Guest User

Untitled

a guest
Feb 23rd, 2014
378
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.10 KB | None | 0 0
  1. #include <Windows.h>
  2.  
  3. LPCWSTR g_szClassName = L"MainWindow_Class";
  4.  
  5.  
  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, LPSTR lpCmdLine, int nCmdShow)
  23. {
  24.         WNDCLASSEX wc;
  25.         MSG msg;
  26.         HWND hwnd;
  27.  
  28.         ZeroMemory(&wc, sizeof(&wc));
  29.  
  30.         wc.style = 0;
  31.         wc.lpszClassName = g_szClassName;
  32.         wc.lpszMenuName = NULL;
  33.         wc.lpfnWndProc = WndProc;
  34.         wc.hInstance = hInstance;
  35.         wc.hIconSm = LoadIcon(NULL, IDC_ICON);
  36.         wc.hIcon = LoadIcon(NULL, IDC_ICON);
  37.         wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  38.         wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
  39.         wc.cbWndExtra = 0;
  40.         wc.cbSize = sizeof(WNDCLASSEX);
  41.         wc.cbClsExtra = 0;
  42.        
  43.         if (!RegisterClassEx(&wc))
  44.         {
  45.                 LPCWSTR Error01 = L"Could not register class!";
  46.                 LPCWSTR Error01_Caption = L"Error";
  47.                 MessageBox(NULL, Error01, Error01_Caption, MB_OK | MB_ICONERROR);
  48.         }
  49.  
  50.         LPCWSTR WindowTitle = L"EXAMPLE WINDOW!";
  51.  
  52.         hwnd = CreateWindowEx(WS_EX_CLIENTEDGE, g_szClassName, WindowTitle, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 500, 300, NULL, NULL, hInstance, NULL);
  53.  
  54.         if (hwnd == NULL)
  55.         {
  56.                 LPCWSTR Error02 = L"Could not create Window!";
  57.                 LPCWSTR Error02_Caption = L"Error";
  58.                 MessageBox(NULL, Error02 , Error02_Caption , MB_OK | MB_ICONERROR);
  59.         }
  60.  
  61.         ShowWindow(hwnd, nCmdShow);
  62.         UpdateWindow(hwnd);
  63.  
  64.         while(GetMessage(&msg, 0, 0, 0))
  65.         {
  66.                 TranslateMessage(&msg);
  67.                 DispatchMessage(&msg);
  68.         }
  69.  
  70.         return msg.wParam;
  71. }
Advertisement
Add Comment
Please, Sign In to add comment