Advertisement
Guest User

Untitled

a guest
Sep 27th, 2017
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.78 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_WINDOW+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 DefWindowProc(hwnd, uMsg, wParam, lParam);
  29. }
  30.  
  31.  
  32. int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE, PWSTR pCmdLine, int nCmdShow)
  33. {
  34.     // Register the window class.
  35.     const wchar_t CLASS_NAME[]  = L"Sample Window Class";
  36.  
  37.     WNDCLASS wc = { };
  38.  
  39.     wc.lpfnWndProc   = WindowProc;
  40.     wc.hInstance     = hInstance;
  41.     wc.lpszClassName = CLASS_NAME;
  42.  
  43.     RegisterClass(&wc);
  44.  
  45.     // Create the window.
  46.  
  47.     HWND hwnd = CreateWindowEx(
  48.         0,                              // Optional window styles.
  49.         CLASS_NAME,                     // Window class
  50.         L"Learn to Program Windows",    // Window text
  51.         WS_OVERLAPPEDWINDOW,            // Window style
  52.  
  53.         // Size and position
  54.         CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
  55.  
  56.         NULL,       // Parent window
  57.         NULL,       // Menu
  58.         hInstance,  // Instance handle
  59.         NULL        // Additional application data
  60.         );
  61.  
  62.     if (hwnd == NULL)
  63.     {
  64.         return 0;
  65.     }
  66.  
  67.     ShowWindow(hwnd, nCmdShow);
  68.  
  69.     // Run the message loop.
  70.  
  71.     MSG msg = { };
  72.     while (GetMessage(&msg, NULL, 0, 0))
  73.     {
  74.         TranslateMessage(&msg);
  75.         DispatchMessage(&msg);
  76.     }
  77.  
  78.     return 0;
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement