inline window::window<> create_test_window() { WNDCLASSEXW window_class = WNDCLASSEXW(); window_class.cbSize = sizeof(WNDCLASSEXW); window_class.lpszClassName = L"testclass"; window_class.lpfnWndProc = ::DefWindowProcW; ATOM klass = ::RegisterClassExW(&window_class); if (klass == 0 && ::GetLastError() != ERROR_CLASS_ALREADY_EXISTS) BOOST_THROW_EXCEPTION( boost::enable_error_info(washer::last_error()) << boost::errinfo_api_function("RegisterClassEx")); HWND hwnd = ::CreateWindowExW( 0L, L"testclass", L"", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, NULL, NULL); // BUG: CreateWindowExW doesn't set the error when passed // invalid arguments if (hwnd == NULL) BOOST_THROW_EXCEPTION( boost::enable_error_info(washer::last_error()) << boost::errinfo_api_function("CreateWindowEx")); return window::window<>(window::window_handle::adopt_handle(hwnd)); }
//Registers, creates, and shows the Window!! bool WinCreate() { WindowINST = GetModuleHandle(0); // Get current process handle std::string title = string_format("Cataclysm: Dark Days Ahead - %s", getVersionString()); // Register window class WNDCLASSEXW WindowClassType = WNDCLASSEXW(); WindowClassType.cbSize = sizeof(WNDCLASSEXW); WindowClassType.lpfnWndProc = ProcessMessages;//the procedure that gets msgs WindowClassType.hInstance = WindowINST;// hInstance WindowClassType.hIcon = LoadIcon(WindowINST, MAKEINTRESOURCE(0)); // Get first resource WindowClassType.hIconSm = LoadIcon(WindowINST, MAKEINTRESOURCE(0)); WindowClassType.hCursor = LoadCursor(NULL, IDC_ARROW); WindowClassType.lpszClassName = szWindowClass; if (!RegisterClassExW(&WindowClassType)) return false; // Adjust window size uint32_t WndStyle = WS_CAPTION | WS_MINIMIZEBOX | WS_SYSMENU | WS_VISIBLE; // Basic window, show on creation RECT WndRect; WndRect.left = WndRect.top = 0; WndRect.right = WindowWidth; WndRect.bottom = WindowHeight; AdjustWindowRect(&WndRect, WndStyle, false); // Center window RECT WorkArea; SystemParametersInfo(SPI_GETWORKAREA, 0, &WorkArea, 0); int WindowX = WorkArea.right/2 - (WndRect.right - WndRect.left)/2; int WindowY = WorkArea.bottom/2 - (WndRect.bottom - WndRect.top)/2; // Magic WindowHandle = CreateWindowExW(0, szWindowClass , widen(title).c_str(), WndStyle, WindowX, WindowY, WndRect.right - WndRect.left, WndRect.bottom - WndRect.top, 0, 0, WindowINST, NULL); if (WindowHandle == 0) return false; return true; };