Destrovi4

Window2

Feb 12th, 2015
871
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <Windows.h>
  2. #include <iostream>
  3. using namespace std;
  4.  
  5. void TellError(const char* error){
  6.     cout << error << endl;
  7. }
  8.  
  9. int AppRunning = 1;
  10.  
  11. LRESULT CALLBACK WindowProcedure(HWND hWnd,UINT msg,WPARAM wparam,LPARAM lparam) {
  12.  
  13.     switch(msg){
  14.         case WM_KEYDOWN:
  15.             AppRunning=0;
  16.             break;
  17.         case WM_CLOSE:
  18.             DestroyWindow(hWnd);
  19.             break;
  20.         case WM_DESTROY:
  21.             PostQuitMessage(0);
  22.             break;
  23.     }
  24.  
  25.     return DefWindowProc(hWnd,msg,wparam,lparam);
  26. }
  27.  
  28. HWND createWindow(WNDPROC wndProc, int nCmdShow) {
  29.  
  30.     HINSTANCE hInstance = GetModuleHandle(0);
  31.     WNDCLASS WindowClass;
  32.  
  33.     WindowClass.style           = 0;
  34.     WindowClass.lpfnWndProc     = wndProc;
  35.     WindowClass.cbClsExtra      = 0;
  36.     WindowClass.cbWndExtra      = 0;
  37.     WindowClass.hInstance       = hInstance;
  38.     WindowClass.hIcon           = LoadIcon(hInstance, (LPCTSTR)IDI_APPLICATION);
  39.     WindowClass.hCursor         = LoadCursor(NULL, IDC_ARROW);
  40.     WindowClass.hbrBackground   = (HBRUSH)(COLOR_WINDOW+1);
  41.     WindowClass.lpszMenuName    = 0;
  42.     WindowClass.lpszClassName   = TEXT("Class");
  43.     RegisterClass(&WindowClass);
  44.  
  45.     HWND hWnd = CreateWindow(
  46.         "Class",
  47.         NULL,
  48.         WS_BORDER|WS_VISIBLE,
  49.         CW_USEDEFAULT,
  50.         CW_USEDEFAULT,
  51.         CW_USEDEFAULT,
  52.         CW_USEDEFAULT,
  53.         0,0,
  54.         hInstance,
  55.         NULL
  56.     );
  57.  
  58.     ShowWindow(hWnd, nCmdShow);
  59.     UpdateWindow(hWnd);
  60.  
  61.     return hWnd;
  62. }
  63.  
  64.  
  65. int main() {
  66.     cout << "Start" << endl;
  67.     MSG msg;
  68.     HWND hWnd = createWindow(WindowProcedure, 0);//NewWindow("Hello window", 0, 0, 100, 100);
  69.     if(!hWnd){
  70.         TellError("Cannot create window!");
  71.         return 0;
  72.     }
  73.     while(AppRunning){
  74.         if(PeekMessage(&msg,hWnd,0,0,PM_REMOVE)){
  75.             //if(!IsDialogMessage(hWnd,&msg)){
  76.                 TranslateMessage(&msg);
  77.                 DispatchMessage(&msg);
  78.             //}
  79.         }
  80.     }
  81.     DestroyWindow(hWnd);
  82.     cout << "End" << endl;
  83.  
  84.     return 0;
  85. }
Advertisement