Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "MainWindow.h"
- MainWindow::MainWindow(HINSTANCE& g_hInstance, int g_nCmdShow)
- :hInstance(g_hInstance), nCmdShow(g_nCmdShow) {}
- MainWindow::~MainWindow()
- {
- }
- BOOL MainWindow::init()
- {
- return !initAppClass() || !initWindow();
- }
- BOOL MainWindow::initAppClass()
- {
- ATOM class_id;
- WNDCLASS wc;
- memset(&wc, 0, sizeof(wc));
- wc.lpszMenuName = NULL;
- wc.style = CS_HREDRAW | CS_VREDRAW;
- wc.lpfnWndProc = static_cast<WNDPROC> (wndProc);
- wc.cbClsExtra = 0;
- wc.cbWndExtra = 0;
- wc.hInstance = hInstance;
- wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
- wc.hCursor = LoadCursor(NULL, IDC_ARROW);
- wc.hbrBackground = static_cast<HBRUSH> (GetStockObject(WHITE_BRUSH));
- wc.lpszClassName = L"LabWork1";
- class_id = RegisterClass(&wc);
- if (class_id != 0)
- return TRUE;
- return FALSE;
- }
- BOOL MainWindow::initWindow()
- {
- mainWind = CreateWindow(L"LabWork1", L"Лабораторная работа №1",
- WS_OVERLAPPEDWINDOW,
- CW_USEDEFAULT, NULL,
- 400, 400,
- NULL,
- NULL,
- hInstance,
- nullptr);
- if (!hInstance)
- return FALSE;
- ShowWindow(mainWind, nCmdShow);
- UpdateWindow(mainWind);
- startMessageLoop();
- return TRUE;
- }
- WPARAM MainWindow::startMessageLoop()
- {
- MSG msg = MSG();
- while (GetMessage(&msg, 0, 0, 0))
- DispatchMessage(&msg);
- return msg.wParam;
- }
- LRESULT CALLBACK MainWindow::wndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
- {
- switch (msg)
- {
- case WM_DESTROY:
- PostQuitMessage(0);
- return 0;
- case WM_PAINT:
- PAINTSTRUCT ps;
- HDC hDC = BeginPaint(hWnd, &ps);
- ball.draw(hDC);
- EndPaint(hWnd, &ps);
- return 0;
- }
- return DefWindowProc(hWnd, msg, wParam, lParam);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement