/// <summary> /// If file exists in the current folder then this method simply returns the file name. /// if not, it will search the file with provided name in every folder, specified in the system /// search path. /// </summary> /// <param name="fileName">Name of the file.</param> /// <returns></returns> public static string FullPath(string fileName) { if (string.IsNullOrEmpty(fileName)) { return(string.Empty); } // search machine try { StringBuilder sb = new StringBuilder(260); if (NativeMethods.FullPath(fileName, sb)) { return(sb.ToString()); } else { return(fileName); } } catch (Exception ex) { //oops! TraceDebug.Trace("FileSearch.FullPath: " + ex.Message); return(fileName); } }
int IOleDropTarget.OleDragEnter(object pDataObj, int grfKeyState, long pt, ref int pdwEffect) { TraceDebug.Trace("OleDragEnter"); POINT pointl = new POINT(); pointl.x = DropTarget.GetX(pt); pointl.y = DropTarget.GetY(pt); // this shouldn't happen, but seems to occasionally, so rather than an Assertion that // will cause a GPF, we'll try and handle it nicely.... if (lastDataObject != null) { // Drag leave wasn't called, so call it now... this.owner.OnDragLeave(EventArgs.Empty); lastDataObject = null; this.lastEffect = DragDropEffects.None; } DragEventArgs e = this.CreateDragEventArgs(pDataObj, grfKeyState, pointl, pdwEffect); if (e != null) { this.owner.OnDragEnter(e); pdwEffect = (int)e.Effect; this.lastEffect = e.Effect; } else { pdwEffect = 0; } return(0); }
internal void DrawSurface() { StopTimer(pulseTimer); try { Clear(); if (surfaceCache != null) { surfaceCache.Draw(); } Canvas.DrawEllipse(pulsarPen, (Width - rad) / 2 - 1 + HorizontalShift, (Width - rad) / 2 + 1 + VerticalShift, rad, rad); rad += 2; if (rad >= 25) { rad = 0; } StartTimer(pulseTimer, frequency); } catch (Exception ex) { TraceDebug.Trace("Pulsar.DrawSurface: " + ex.Message); } }
private DragEventArgs CreateDragEventArgs(object pDataObj, int grfKeyState, POINT pt, int pdwEffect) { System.Windows.Forms.IDataObject data = null; if (pDataObj == null) { data = this.lastDataObject; } else if (pDataObj is System.Windows.Forms.IDataObject) { data = (System.Windows.Forms.IDataObject)pDataObj; } else if (pDataObj is System.Runtime.InteropServices.ComTypes.IDataObject) { data = new DataObject(pDataObj); } else { TraceDebug.Trace("CreateDragEventArgs returns null"); return(null); } DragEventArgs args = new DragEventArgs(data, grfKeyState, pt.x, pt.y, (DragDropEffects)pdwEffect, this.lastEffect); this.lastDataObject = data; return(args); }
public static void Extend(Form form, GlassMargins margins) { if (form == null) { return; } if (!GlassAvailable) { return; } try { NativeMethods.MARGINS LMargins = new NativeMethods.MARGINS(); LMargins.cxLeftWidth = margins.LeftWidth; LMargins.cxRightWidth = margins.RightWidth; LMargins.cyBottomHeight = margins.BottomHeight; LMargins.cyTopHeight = margins.TopHeight; NativeMethods.DwmExtendFrameIntoClientArea(form.Handle, ref LMargins); } catch (DllNotFoundException) { TraceDebug.Trace("DWMAPI DLL not found"); } }
int IOleDropTarget.OleDragLeave() { TraceDebug.Trace("OleDragLeave"); this.owner.OnDragLeave(EventArgs.Empty); lastDataObject = null; this.lastEffect = DragDropEffects.None; return(0); }
public static Bitmap FromNativeResource(IntPtr handle, string resource) { if (string.IsNullOrEmpty(resource) || handle == IntPtr.Zero) { return(null); } Bitmap result; int w = 0; int h = 0; IntPtr ppvBits; IntPtr hBitmap = NativeMethods.LoadPNGResource(handle, resource, ref w, ref h, out ppvBits); if (hBitmap != IntPtr.Zero) { try { #if PRESSURE long pressure = InteropHelper.AlignToPage(w * h * 4); if (pressure != 0L) { GC.AddMemoryPressure(pressure); } #endif result = new Bitmap(w, h, PixelFormat.Format32bppArgb); try { BitmapData data = result.LockBits(new Rectangle(0, 0, w, h), ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb); NativeMethods.RtlMoveMemory(data.Scan0, ppvBits, h * data.Stride); // copies the bitmap result.UnlockBits(data); } catch (Exception ex) { TraceDebug.Trace("FromNativeResource: " + ex.Message + " Resource name " + resource); result = null; } } finally { NativeMethods.DeleteObject(hBitmap); #if PRESSURE long pressure = InteropHelper.AlignToPage(w * h * 4); if (pressure != 0L) { GC.RemoveMemoryPressure(pressure); } #endif } return(result); } else { return(null); } }
public void StopTimer(int timerId) { try { NativeMethods.KillTimer(handle, (IntPtr)timerId); } catch (Exception ex) { TraceDebug.Trace("StopTimer: " + ex.Message); } }
public void StartTimer(int timerId, int interval) { try { NativeMethods.SetTimer(handle, (IntPtr)timerId, interval, IntPtr.Zero); } catch (Exception ex) { TraceDebug.Trace("StartTimer: " + ex.Message); } }
public void Save() { if (ReadOnly) { return; } if (string.IsNullOrEmpty(fileName)) { return; } FileOperations.ClearFileAttributes(fileName); IntPtr file = IntPtr.Zero; try { try { file = NativeMethods.FileCreateRewrite(fileName); for (int i = 0; i < sections.Count; i++) { NativeMethods.FileWriteChar(file, openSection); NativeMethods.FileWrite(file, sections.Key(i)); NativeMethods.FileWriteChar(file, closeSection); NativeMethods.FileWriteNewLine(file); for (int j = 0; j < sections[i].Count; j++) { if (!string.IsNullOrEmpty(sections[i].Value(j))) { NativeMethods.FileWrite(file, sections[i].Key(j)); NativeMethods.FileWriteChar(file, divider); NativeMethods.FileWrite(file, sections[i].Value(j)); NativeMethods.FileWriteNewLine(file); } } } } catch (Exception ex) { TraceDebug.Trace("MemIniFile.Save: " + ex.Message); } } finally { if (file != IntPtr.Zero) { NativeMethods.FileClose(file); } } }
internal static void SetCompositionEnabled(bool value) { if (!GlassAvailable) { return; } try { NativeMethods.DwmEnableComposition(value); } catch (DllNotFoundException) { TraceDebug.Trace("DWMAPI DLL not found"); } }
/// <summary> /// Get the image for specified file name. If the file has no embedded icon, /// this method will return default image for the file extension /// </summary> /// <param name="fileName">Name of the file.</param> /// <returns>Image or null. The size of the image = size of the icon</returns> public static Image FileNameImage(string fileName) { Image result; try { result = FileNameImageInternal(fileName); } catch (Exception ex) { TraceDebug.Trace(ex); result = NativeThemeManager.LoadBitmap("UnknownFile.png"); } return(result); }
int IOleDropTarget.OleDragOver(int grfKeyState, long pt, ref int pdwEffect) { TraceDebug.Trace("OleDragOver"); POINT pointl = new POINT(); pointl.x = DropTarget.GetX(pt); pointl.y = DropTarget.GetY(pt); DragEventArgs e = this.CreateDragEventArgs(lastDataObject, grfKeyState, pointl, pdwEffect); if (e != null) { this.owner.OnDragOver(e); pdwEffect = (int)e.Effect; this.lastEffect = e.Effect; } else { pdwEffect = 0; } return(0); }
public UIElement this[string name] { get { try { if (nameList.ContainsKey(name)) { return(this[nameList[name]]); } else { return(null); } } catch (Exception ex) { TraceDebug.Trace("The visual element [UIElement] with name " + name + " was not found " + ex.Message); return(null); } } }
internal static bool IsCompositionEnabled() { bool enabled = false; if (!GlassAvailable) { return(false); } try { int res = NativeMethods.DwmIsCompositionEnabled(ref enabled); if (res != 0) { enabled = false; } } catch (DllNotFoundException) { TraceDebug.Trace("DWMAPI DLL not found"); return(false); } return(enabled); }
public unsafe void Load() { string s; string currentSection = null; string[] content; sections.Clear(); if (string.IsNullOrEmpty(fileName)) { return; } if (!FileOperations.FileExists(fileName)) { return; } TextFileReader reader = null; try { try { reader = new TextFileReader(fileName, encoding); while ((s = reader.ReadLine()) != null) { if (string.IsNullOrEmpty(s)) { continue; } if (s[0] == ';') { continue; } if ((s[0] == openSection) && (s[s.Length - 1] == closeSection)) { currentSection = s.Substring(1, s.Length - 2); sections.Add(currentSection); } else { if (currentSection == null) { continue; } int j = s.IndexOf(divider); if (j > 0) { content = s.Split(new char[1] { divider }, 2); if (content.Length == 2) { sections[currentSection].Add(content[0].Trim(), content[1].Trim()); } } } } } catch (Exception ex) { TraceDebug.Trace("MemIniFile.Load: " + ex.Message); } } finally { if (reader != null) { reader.Close(); } } }