private IntPtr WndProc(IntPtr rawHwnd, uint msg, IntPtr wParam, IntPtr lParam) { //WM_CREATE must always succeed var hwnd = new User32.HWND(rawHwnd); if (msg == (uint)User32.WM.CREATE || msg == (uint)User32.WM.NCCREATE) { return(User32.DefWindowProc(hwnd, msg, wParam, lParam)); } IntPtr?ret = _wndProc(hwnd, msg, wParam, lParam); if (ret.HasValue) { return(ret.Value); } return(User32.DefWindowProc(hwnd, msg, wParam, lParam)); }
public MessageWindow(string name, WndProcNullableRet wndProc) { if (string.IsNullOrEmpty(name)) { throw new Exception("class_name is empty or null"); } if (wndProc == null) { throw new ArgumentNullException("wndProc"); } _name = name; _wndProc = wndProc; //Log.General.Debug("MessageWindow() name: " + name); _hInstance = Marshal.GetHINSTANCE(GetType() .Module); if (_hInstance == new IntPtr(-1)) { throw new Win32Exception("Couldn't get modules instance"); } int UniqueID = 1; _className = _name + " class " + UniqueID; if (_className.Length > 255) { throw new ArgumentException("class name too long"); } //Log.General.Debug("MessageWindow.Create classname: " + _className); _internalWndProc = WndProc; _wndClassEx = new User32.WNDCLASSEX { cbSize = (uint)Marshal.SizeOf(typeof(User32.WNDCLASSEX)), style = User32.CS.OWNDC | User32.CS.HREDRAW | User32.CS.VREDRAW, lpfnWndProc = _internalWndProc, cbClsExtra = 0, cbWndExtra = 0, hInstance = _hInstance, hIcon = IntPtr.Zero, hCursor = IntPtr.Zero, hbrBackground = IntPtr.Zero, lpszMenuName = null, lpszClassName = _className, hIconSm = IntPtr.Zero }; _classAtom = User32.RegisterClassEx(ref _wndClassEx); if (_classAtom.IsInvalid) { throw new Win32Exception("Could not register window class"); } _windowName = _name + " wnd " + UniqueID; //Log.General.Debug("MessageWindow.Create windowname: " + _windowName); // Create window _handle = User32.StrongHWND.CreateWindowEx( User32.WindowStylesEx.WS_EX_CLIENTEDGE | User32.WindowStylesEx.WS_EX_APPWINDOW, _className, _windowName, User32.WindowStyles.WS_OVERLAPPEDWINDOW, // position 0, 0, // size 0, 0, // no parent User32.HWND.NULL, // no menu IntPtr.Zero, _hInstance, IntPtr.Zero); if (Handle.IsInvalid) { throw new Win32Exception("Could not create window"); } }
public static extern IntPtr DefWindowProc(User32.HWND hWnd, uint msg, IntPtr wParam, IntPtr lParam);