Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Windows.h>
- #include <string>
- LRESULT CALLBACK window_proc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
- {
- if (message == WM_CLOSE || (message == WM_KEYDOWN && wparam == VK_ESCAPE)) {
- PostQuitMessage(0);
- return 0;
- }
- return DefWindowProc(hwnd, message, wparam, lparam);
- }
- int main()
- {
- std::string window_title = "AppName";
- std::string window_class = window_title + "Class";
- WNDCLASS wc = {};
- wc.lpfnWndProc = window_proc;
- wc.hCursor = LoadCursor(NULL, IDC_ARROW);
- wc.lpszClassName = window_class.c_str();
- RegisterClass(&wc);
- DWORD dwStyle = WS_SYSMENU | WS_CAPTION | WS_VISIBLE;
- RECT rc = { 0, 0, 512, 512 };
- AdjustWindowRect(&rc, dwStyle, FALSE);
- HWND hwnd = CreateWindow(window_class.c_str(), window_title.c_str(), dwStyle, CW_USEDEFAULT, CW_USEDEFAULT, rc.right - rc.left, rc.bottom - rc.top, NULL, NULL, NULL, NULL);
- if (!hwnd) {
- UnregisterClass(window_class.c_str(), NULL);
- return 1;
- }
- MSG msg = {};
- while (msg.message != WM_QUIT) {
- if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
- TranslateMessage(&msg);
- DispatchMessage(&msg);
- }
- }
- DestroyWindow(hwnd);
- UnregisterClass(window_class.c_str(), NULL);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment