Advertisement
jcyangzh

added minmax info

Apr 3rd, 2013
192
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. const char g_szClassName[] = "myWindowClass";
  4.  
  5. LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
  6. {
  7.     switch(msg)
  8.     {
  9.     case WM_GETMINMAXINFO:
  10.     {
  11.         MINMAXINFO* mmi = (MINMAXINFO*)lParam;
  12.         int iMinWidth = 500;
  13.         int iMinHeight = 500;
  14.         mmi->ptMinTrackSize.x = iMinWidth;
  15.         mmi->ptMinTrackSize.y = iMinHeight;
  16.         return 0;
  17.     }
  18.     break;
  19.     case WM_CREATE:
  20.     {
  21.  
  22.     }
  23.     break;
  24.         case WM_CLOSE:
  25.             DestroyWindow(hwnd);
  26.         break;
  27.         case WM_DESTROY:
  28.             PostQuitMessage(0);
  29.         break;
  30.         default:
  31.             return DefWindowProc(hwnd, msg, wParam, lParam);
  32.     }
  33.     return 0;
  34. }
  35.  
  36. int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
  37.     LPSTR lpCmdLine, int nCmdShow)
  38. {
  39.     WNDCLASSEX wc;
  40.     HWND hwnd;
  41.     MSG Msg;
  42.  
  43.     //Step 1: Registering the Window Class
  44.     wc.cbSize        = sizeof(WNDCLASSEX);
  45.     wc.style         = 0;
  46.     wc.lpfnWndProc   = WndProc;
  47.     wc.cbClsExtra    = 0;
  48.     wc.cbWndExtra    = 0;
  49.     wc.hInstance     = hInstance;
  50.     wc.hIcon         = LoadIcon(NULL, IDI_APPLICATION);
  51.     wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
  52.     wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
  53.     wc.lpszMenuName  = NULL;
  54.     wc.lpszClassName = g_szClassName;
  55.     wc.hIconSm       = LoadIcon(NULL, IDI_APPLICATION);
  56.  
  57.     if(!RegisterClassEx(&wc))
  58.     {
  59.         MessageBox(NULL, "Window Registration Failed!", "Error!",
  60.             MB_ICONEXCLAMATION | MB_OK);
  61.         return 0;
  62.     }
  63.  
  64.     hwnd = CreateWindowEx(
  65.         WS_EX_CLIENTEDGE,
  66.         g_szClassName,
  67.         "The title of my window",
  68.         WS_OVERLAPPEDWINDOW,
  69.         CW_USEDEFAULT, CW_USEDEFAULT, 240, 120,
  70.         NULL, NULL, hInstance, NULL);
  71.  
  72.     if(hwnd == NULL)
  73.     {
  74.         MessageBox(NULL, "Window Creation Failed!", "Error!",
  75.             MB_ICONEXCLAMATION | MB_OK);
  76.         return 0;
  77.     }
  78.  
  79.     ShowWindow(hwnd, nCmdShow);
  80.     UpdateWindow(hwnd);
  81.  
  82.     while(GetMessage(&Msg, NULL, 0, 0) > 0)
  83.     {
  84.         TranslateMessage(&Msg);
  85.         DispatchMessage(&Msg);
  86.     }
  87.     return Msg.wParam;
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement