Advertisement
skindervik

Simple WIN32 Window

Nov 24th, 2018
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.51 KB | None | 0 0
  1. #include<Windows.h>
  2.  
  3. #define WIN32_LEAN_AND_MEAN //speeds up compiler
  4.  
  5. LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { //Window message processing
  6.     switch (msg)
  7.     {
  8.     case WM_CLOSE:
  9.         DestroyWindow(hwnd);
  10.         break;
  11.     case WM_DESTROY:
  12.         PostQuitMessage(0);
  13.         break;
  14.     default:
  15.         return DefWindowProc(hwnd, msg, wParam, lParam);
  16.     }
  17.     return 0;
  18. }
  19.  
  20. int WinMain(_In_ HINSTANCE hInstance, _In_opt_  HINSTANCE hPrevInstance, _In_ LPSTR lpCmdLine, _In_ int nCmdShow){ //Entry Point
  21.    
  22.     //(Optional stuff, does nothing)
  23.     UNREFERENCED_PARAMETER(hPrevInstance);
  24.     UNREFERENCED_PARAMETER(lpCmdLine);
  25.     UNREFERENCED_PARAMETER(nCmdShow);
  26.  
  27.     WNDCLASS window; //Create window class
  28.  
  29.     //Define window class
  30.     window.cbClsExtra = NULL;
  31.     window.cbWndExtra = NULL;
  32.     window.hbrBackground = (HBRUSH)COLOR_WINDOW;
  33.     window.hCursor = LoadCursor(NULL, IDC_ARROW);
  34.     window.hIcon = LoadIcon(NULL, IDI_APPLICATION);
  35.     window.hInstance = hInstance;
  36.     window.lpfnWndProc = WndProc;
  37.     window.lpszClassName = "just_window";
  38.     window.lpszMenuName = nullptr;
  39.     window.style = NULL;
  40.  
  41.     RegisterClass(&window); //Register the defined window class
  42.  
  43.     CreateWindow("just_window","Test", WS_VISIBLE | WS_SYSMENU,0,0,500,500,nullptr,nullptr,hInstance,nullptr); //Create the defined window
  44.  
  45.     MSG msg; //Create message class
  46.  
  47.     while (GetMessage(&msg, NULL, 0, 0)) { //Message loop, get message
  48.         TranslateMessage(&msg); //Translate Message
  49.         DispatchMessage(&msg); //Send message to WndProc
  50.     }
  51.  
  52.     return (int) msg.wParam;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement