Brejlounek

Untitled

Oct 25th, 2014
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.95 KB | None | 0 0
  1. #include <windows.h>
  2.  
  3. const char g_szClassName[] = "myWindowClass";
  4.  
  5. // Step 4: the Window Procedure
  6. LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
  7. {
  8.     switch(msg)
  9.     {
  10.         case WM_CLOSE:
  11.             DestroyWindow(hwnd);
  12.         break;
  13.         case WM_DESTROY:
  14.             PostQuitMessage(0);
  15.         break;
  16.         default:
  17.             return DefWindowProc(hwnd, msg, wParam, lParam);
  18.     }
  19.     return 0;
  20. }
  21.  
  22. int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
  23.     LPSTR lpCmdLine, int nCmdShow)
  24. {
  25.     WNDCLASSEX wc;
  26.     HWND hwnd;
  27.     MSG Msg;
  28.  
  29.     //Step 1: Registering the Window Class
  30.     wc.cbSize        = sizeof(WNDCLASSEX);
  31.     wc.style         = 0;
  32.     wc.lpfnWndProc   = WndProc;
  33.     wc.cbClsExtra    = 0;
  34.     wc.cbWndExtra    = 0;
  35.     wc.hInstance     = hInstance;
  36.     wc.hIcon         = LoadIcon(NULL, IDI_APPLICATION);
  37.     wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
  38.     wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
  39.     wc.lpszMenuName  = NULL;
  40.     wc.lpszClassName = g_szClassName;
  41.     wc.hIconSm       = LoadIcon(NULL, IDI_APPLICATION);
  42.  
  43.     if(!RegisterClassEx(&wc))
  44.     {
  45.         MessageBox(NULL, "Window Registration Failed!", "Error!",
  46.             MB_ICONEXCLAMATION | MB_OK);
  47.         return 0;
  48.     }
  49.  
  50.     // Step 2: Creating the Window
  51.     hwnd = CreateWindowEx(
  52.         WS_EX_CLIENTEDGE,
  53.         g_szClassName,
  54.         "The title of my window",
  55.         WS_OVERLAPPEDWINDOW,
  56.         CW_USEDEFAULT, CW_USEDEFAULT, 240, 120,
  57.         NULL, NULL, hInstance, NULL);
  58.  
  59.     if(hwnd == NULL)
  60.     {
  61.         MessageBox(NULL, "Window Creation Failed!", "Error!",
  62.             MB_ICONEXCLAMATION | MB_OK);
  63.         return 0;
  64.     }
  65.  
  66.     ShowWindow(hwnd, nCmdShow);
  67.     UpdateWindow(hwnd);
  68.  
  69.     // Step 3: The Message Loop
  70.     while(GetMessage(&Msg, NULL, 0, 0) > 0)
  71.     {
  72.         TranslateMessage(&Msg);
  73.         DispatchMessage(&Msg);
  74.     }
  75.     return Msg.wParam;
  76. }
Add Comment
Please, Sign In to add comment