Advertisement
Guest User

Untitled

a guest
Apr 21st, 2017
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "MainWindow.h"
  2.  
  3. MainWindow::MainWindow(HINSTANCE& g_hInstance, int g_nCmdShow)
  4.     :hInstance(g_hInstance), nCmdShow(g_nCmdShow) {}
  5.  
  6. MainWindow::~MainWindow()
  7. {
  8. }
  9.  
  10. BOOL MainWindow::init()
  11. {
  12.     return !initAppClass() || !initWindow();
  13. }
  14.  
  15. BOOL MainWindow::initAppClass()
  16. {
  17.     ATOM class_id;
  18.     WNDCLASS wc;
  19.     memset(&wc, 0, sizeof(wc));
  20.     wc.lpszMenuName = NULL;
  21.     wc.style = CS_HREDRAW | CS_VREDRAW;
  22.     wc.lpfnWndProc = static_cast<WNDPROC> (wndProc);
  23.     wc.cbClsExtra = 0;
  24.     wc.cbWndExtra = 0;
  25.     wc.hInstance = hInstance;
  26.     wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
  27.     wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  28.     wc.hbrBackground = static_cast<HBRUSH> (GetStockObject(WHITE_BRUSH));
  29.     wc.lpszClassName = L"LabWork1";
  30.     class_id = RegisterClass(&wc);
  31.  
  32.     if (class_id != 0)
  33.         return TRUE;
  34.  
  35.     return FALSE;
  36. }
  37.  
  38. BOOL MainWindow::initWindow()
  39. {
  40.     mainWind = CreateWindow(L"LabWork1", L"Лабораторная работа №1",
  41.         WS_OVERLAPPEDWINDOW,
  42.         CW_USEDEFAULT, NULL,
  43.         400, 400,
  44.         NULL,
  45.         NULL,
  46.         hInstance,
  47.         nullptr);
  48.  
  49.     if (!hInstance)
  50.         return FALSE;
  51.  
  52.     ShowWindow(mainWind, nCmdShow);
  53.     UpdateWindow(mainWind);
  54.     startMessageLoop();
  55.  
  56.     return TRUE;
  57. }
  58.  
  59. WPARAM MainWindow::startMessageLoop()
  60. {
  61.     MSG msg = MSG();
  62.  
  63.     while (GetMessage(&msg, 0, 0, 0))
  64.         DispatchMessage(&msg);
  65.  
  66.     return msg.wParam;
  67. }
  68.  
  69. LRESULT CALLBACK MainWindow::wndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
  70. {
  71.     switch (msg)
  72.     {
  73.     case WM_DESTROY:
  74.         PostQuitMessage(0);
  75.         return 0;
  76.     case WM_PAINT:
  77.         PAINTSTRUCT ps;
  78.         HDC hDC = BeginPaint(hWnd, &ps);
  79.         ball.draw(hDC);
  80.         EndPaint(hWnd, &ps);
  81.         return 0;
  82.     }
  83.  
  84.     return DefWindowProc(hWnd, msg, wParam, lParam);
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement