internal Win32Window(string title, int width, int height) { Width = width; Height = height; _wndProc = WndProc; var wndClass = new User32.WndClass { lpfnWndProc = _wndProc, style = 0x20, hbrBackground = new IntPtr(1), lpszClassName = "coreloader" }; User32.RegisterClassA(ref wndClass); const int offset = 50; var rect = new User32.Rect { top = offset, left = offset, bottom = offset + height, right = offset + width }; var style = WindowStyles.WS_OVERLAPPEDWINDOW; User32.AdjustWindowRect(ref rect, style, false); NativeHandle = User32.CreateWindowExA(0, wndClass.lpszClassName, title, style, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero); const int sizeofMsg = 48; _msg = Marshal.AllocHGlobal(sizeofMsg); }
public IWindow CreateWindow(CreateWindowArguments arguments) { var nativeWindow = new NativeWindow(arguments.Width, arguments.Height, _eventManager); var wndClassExA = new WNDCLASSEXA { CbClsExtra = 0, CbSize = Marshal.SizeOf <WNDCLASSEXA>(), HCursor = IntPtr.Zero, HIcon = IntPtr.Zero, LpFnWndProc = nativeWindow.WindowProcedureFunctionPointer, CbWndExtra = 0, HIconSm = IntPtr.Zero, HInstance = Marshal.GetHINSTANCE(GetType().Module), HbrBackground = IntPtr.Zero, LpszClassName = arguments.Title + "class", Style = 0 }; if (User32.RegisterClassExA(ref wndClassExA) == 0) { throw new Win32Exception(Marshal.GetLastWin32Error(), "RegisterClassExA failed"); } const WindowStyles wsStyle = WindowStyles.WS_OVERLAPPEDWINDOW | WindowStyles.WS_VISIBLE; RECT windowRect = default; windowRect.Left = 100; windowRect.Right = arguments.Width + windowRect.Left; windowRect.Top = 100; windowRect.Bottom = arguments.Height + windowRect.Top; User32.AdjustWindowRect(ref windowRect, wsStyle, false); nativeWindow.Handle = User32.CreateWindowExA( 0, wndClassExA.LpszClassName, arguments.Title, wsStyle, arguments.X, arguments.Y, windowRect.Right - windowRect.Left, windowRect.Bottom - windowRect.Top, IntPtr.Zero, IntPtr.Zero, wndClassExA.HInstance, IntPtr.Zero ); if (nativeWindow.Handle == IntPtr.Zero) { throw new Win32Exception(Marshal.GetLastWin32Error(), "CreateWindowExA failed"); } nativeWindow.ShowWindow(); return(nativeWindow); }