Advertisement
Guest User

Untitled

a guest
Sep 27th, 2017
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.94 KB | None | 0 0
  1. #include <windows.h>
  2. #include <iostream>
  3.  
  4. LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  5. {
  6.     switch (uMsg)
  7.     {
  8.     case WM_DESTROY:
  9.         PostQuitMessage(0);
  10.         return 0;
  11.  
  12.     case WM_PAINT:
  13.         {
  14.             PAINTSTRUCT ps;
  15.             HDC hdc = BeginPaint(hwnd, &ps);
  16.  
  17.             FillRect(hdc, &ps.rcPaint, (HBRUSH) (COLOR_BTNFACE + 1));
  18.  
  19.             EndPaint(hwnd, &ps);
  20.         }
  21.         return 0;
  22.  
  23.     case WM_CHAR:
  24.         std::cout << wParam << std::endl;
  25.         break;
  26.  
  27.     }
  28.     return DefWindowProcA(hwnd, uMsg, wParam, lParam);
  29. }
  30.  
  31.  
  32. int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, PSTR pCmdLine, int nCmdShow)
  33. {
  34.     // Register the window class.
  35.     const char* CLASS_NAME  = "Sample Window Class";
  36.  
  37.     WNDCLASSA wc;
  38.     ZeroMemory(&wc, sizeof(wc));
  39.  
  40.     wc.lpfnWndProc   = WindowProc;
  41.     wc.hInstance     = hInstance;
  42.     wc.lpszClassName = CLASS_NAME;
  43.     wc.hCursor = LoadCursor(0, IDC_ARROW);
  44.     wc.hIcon = LoadIcon(0, IDI_WINLOGO);
  45.  
  46.     RegisterClassA(&wc);
  47.  
  48.     // Create the window.
  49.  
  50.     HWND hwnd = CreateWindowExA(
  51.         0,                              // Optional window styles.
  52.         CLASS_NAME,                     // Window class
  53.         "Learn to Program Windows",    // Window text
  54.         WS_OVERLAPPEDWINDOW,            // Window style
  55.  
  56.         // Size and position
  57.         CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
  58.  
  59.         NULL,       // Parent window
  60.         NULL,       // Menu
  61.         hInstance,  // Instance handle
  62.         NULL        // Additional application data
  63.         );
  64.  
  65.     if (hwnd == NULL)
  66.     {
  67.         std::cout << "No window" << std::endl;
  68.         return 0;
  69.     }
  70.  
  71.     ShowWindow(hwnd, nCmdShow);
  72.  
  73.     // Run the message loop.
  74.  
  75.     MSG msg = { };
  76.     while (GetMessage(&msg, NULL, 0, 0))
  77.     {
  78.         TranslateMessage(&msg);
  79.         DispatchMessage(&msg);
  80.     }
  81.  
  82.     return 0;
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement