private bool PlatformInit() { WNDCLASS winClass = new WNDCLASS(); winClass.style = WinUser.CS_HREDRAW | WinUser.CS_VREDRAW | WinUser.CS_OWNDC; proc = WndProc; winClass.lpfnWndProc = Marshal.GetFunctionPointerForDelegate(proc); winClass.lpszClassName = "Sparky Win32 Window"; winClass.hCursor = WinUser.LoadCursorW(IntPtr.Zero, WinUser.IDC_ARROW); winClass.hIcon = WinUser.LoadIconW(IntPtr.Zero, WinUser.IDI_WINLOGO); if (WinUser.RegisterClassW(ref winClass) == 0) { Log.Error("Could not register Win32 class!"); return(false); } RECT size = new RECT(0, 0, (int)properties.width, (int)properties.height); WinUser.AdjustWindowRectEx(ref size, WinUser.WS_OVERLAPPEDWINDOW | WinUser.WS_CLIPSIBLINGS | WinUser.WS_CLIPCHILDREN, false, WinUser.WS_EX_APPWINDOW | WinUser.WS_EX_WINDOWEDGE); hWnd = WinUser.CreateWindowExW(WinUser.WS_EX_APPWINDOW | WinUser.WS_EX_WINDOWEDGE, winClass.lpszClassName, title, WinUser.WS_OVERLAPPEDWINDOW | WinUser.WS_CLIPSIBLINGS | WinUser.WS_CLIPCHILDREN, (int)(WinUser.GetSystemMetrics(WinUser.SM_CXSCREEN) / 2 - properties.width / 2), (int)(WinUser.GetSystemMetrics(WinUser.SM_CYSCREEN) / 2 - properties.height / 2), (int)(size.right + (-size.left)), (int)(size.bottom + (-size.top)), IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero ); if (hWnd.ToInt32() == 0) { Log.Error("Could not create window!"); return(false); } RegisterWindowClass(hWnd, this); hDc = WinUser.GetDC(hWnd); PIXELFORMATDESCRIPTOR pfd = GetPixelFormat(); int pixelFormat = WinGDI.ChoosePixelFormat(hDc, ref pfd); if (pixelFormat != 0) { if (!WinGDI.SetPixelFormat(hDc, pixelFormat, ref pfd)) { Log.Error("Failed setting pixel format!"); return(false); } } else { Log.Error("Failed choosing pixel format!"); return(false); } Context.Create(properties, hWnd); WinUser.ShowWindow(hWnd, WinUser.SW_SHOW); WinUser.SetFocus(hWnd); return(true); }