private void RegFormClass() { IntPtr hInstance = Marshal.GetHINSTANCE(this.GetType().Module); //(IntPtr)Kernel.GetModuleHandle(null); WNDCLASSEX vWndCls = WNDCLASSEX.Build(); if (!User.GetClassInfoEx(hInstance, "HCPopupForm", ref vWndCls)) { vWndCls = WNDCLASSEX.Build(); //vWndCls.cbSize = 48; vWndCls.lpszClassName = "HCPopupForm"; vWndCls.style = User.CS_VREDRAW | User.CS_HREDRAW | User.CS_DBLCLKS | User.CS_DROPSHADOW; vWndCls.hInstance = hInstance; vWndCls.lpfnWndProc = Marshal.GetFunctionPointerForDelegate(WndProc); vWndCls.cbClsExtra = 0; vWndCls.cbWndExtra = 8; vWndCls.hIcon = IntPtr.Zero; vWndCls.hIconSm = IntPtr.Zero; vWndCls.hCursor = IntPtr.Zero; vWndCls.hbrBackground = (IntPtr)GDI.GetStockObject(0); vWndCls.lpszMenuName = null; if (User.RegisterClassEx(ref vWndCls) == 0) { throw new Exception("异常:注册HCPopupForm错误"); } } }
public void CreateMainWindowNative(int width, int height) { const int CS_VREDRAW = 0x0001; const int CS_HREDRAW = 0x0002; // Register class _proc_native = InternalProcessNativeWindowMessage; WNDCLASSEX wcx = WNDCLASSEX.Build(); wcx.style = CS_VREDRAW | CS_HREDRAW; wcx.lpfnWndProc = Marshal.GetFunctionPointerForDelegate(_proc_native); wcx.hInstance = GetModuleHandle(null); wcx.lpszClassName = "OMG MEOW"; short a = RegisterClassExW(ref wcx); uint styleEx = 0; uint style = (uint)WindowStyles.WS_OVERLAPPEDWINDOW; _hwnd = CreateWindowExW(styleEx, "OMG MEOW", null, style, -1, 0, width, height, IntPtr.Zero, IntPtr.Zero, wcx.hInstance, IntPtr.Zero); Debug.Assert(_hwnd != IntPtr.Zero); }