private Subclass(IntPtr hwnd) { FHwnd = hwnd; FSubclassProcDelegate = SubclassProc; if (!ComCtl32.SetWindowSubclass(FHwnd, FSubclassProcDelegate, UIntPtr.Zero, IntPtr.Zero)) { throw new Exception("SetWindowSubclass failed!"); } }
private IntPtr SubclassProc(IntPtr hWnd, WM msg, IntPtr wParam, IntPtr lParam, UIntPtr uIdSubclass, IntPtr dwRefData) { if (WindowMessage != null) { WindowMessage(this, new WMEventArgs(hWnd, msg, wParam, lParam)); } if (msg == WM.NCDESTROY) { Dispose(); } return(ComCtl32.DefSubclassProc(hWnd, msg, wParam, lParam)); }
public void Dispose() { if (FHwnd != IntPtr.Zero) { ComCtl32.RemoveWindowSubclass(FHwnd, FSubclassProcDelegate, UIntPtr.Zero); FHwnd = IntPtr.Zero; if (Disposed != null) { Disposed(this, EventArgs.Empty); } WindowMessage = null; Disposed = null; GC.SuppressFinalize(this); } }
private IntPtr SubclassProc(IntPtr hWnd, WM msg, UIntPtr wParam, IntPtr lParam, UIntPtr uIdSubclass, IntPtr dwRefData) { var handled = false; if (WindowMessage != null) { var args = new WMEventArgs(hWnd, msg, wParam, lParam); WindowMessage(this, args); handled = args.Handled; } if (msg == WM.NCDESTROY) { Dispose(); } if (!handled) { return(ComCtl32.DefSubclassProc(hWnd, msg, wParam, lParam)); } else { return(IntPtr.Zero); } }