Advertisement
bobmarley12345

Win32 blank window c/c++

Nov 29th, 2022
671
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.19 KB | None | 0 0
  1. #include <iostream>
  2. #include <Windows.h>
  3.  
  4. LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  5.  
  6. int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine, int nCmdShow) {
  7.     LPCWSTR className = L"REghZy Frame Control";
  8.     LPCWSTR winTitle = L"Frame Control";
  9.  
  10.     WNDCLASSW wc = {};
  11.     wc.lpfnWndProc = WindowProc;
  12.     wc.hInstance = hInstance;
  13.     wc.lpszClassName = className;
  14.  
  15.     if (!RegisterClassW(&wc)) {
  16.         printf("Failed to register class");
  17.         MessageBoxW(NULL, L"Failed to register application class", L"App init failure - instance", NULL);
  18.         return 0;
  19.     }
  20.  
  21.     HWND hwnd = CreateWindowExW(
  22.         0,                    // Optional window styles.
  23.         className,            // Window class
  24.         winTitle,             // Window titlebar
  25.         WS_OVERLAPPEDWINDOW,  // Window style
  26.  
  27.         // Size and position
  28.         CW_USEDEFAULT, // x
  29.         CW_USEDEFAULT, // y
  30.         500,           // w
  31.         500,           // h
  32.  
  33.         NULL,       // Parent window    
  34.         NULL,       // Menu
  35.         hInstance,  // Instance handle
  36.         NULL        // Additional application data
  37.     );
  38.  
  39.     if (!hwnd) {
  40.         printf("Failed to register class");
  41.         MessageBoxW(NULL, L"Failed to create application main window", L"App init failure - window", NULL);
  42.         return 0;
  43.     }
  44.  
  45.     ShowWindow(hwnd, nCmdShow);
  46.  
  47.     // Run the message loop.
  48.  
  49.     MSG msg = { };
  50.     while (GetMessage(&msg, NULL, 0, 0) > 0) {
  51.         TranslateMessage(&msg);
  52.         DispatchMessage(&msg);
  53.     }
  54.  
  55.     return 0;
  56. }
  57.  
  58. LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
  59.     switch (uMsg) {
  60.         case WM_DESTROY: {
  61.             PostQuitMessage(0);
  62.             return 0;
  63.         }
  64.  
  65.         case WM_PAINT: {
  66.             PAINTSTRUCT ps;
  67.             HDC hdc = BeginPaint(hwnd, &ps);
  68.  
  69.             // All painting occurs here, between BeginPaint and EndPaint.
  70.  
  71.             FillRect(hdc, &ps.rcPaint, (HBRUSH)(COLOR_WINDOW + 1));
  72.  
  73.             EndPaint(hwnd, &ps);
  74.         }
  75.        
  76.         return 0;
  77.     }
  78.  
  79.     return DefWindowProc(hwnd, uMsg, wParam, lParam);
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement