add window message queue
This commit is contained in:
+29
-1
@@ -10,6 +10,8 @@ INT Window::init(HINSTANCE hInstance, UINT width, UINT height)
|
|||||||
wc.lpszClassName = TEXT("D3D9"); // class name
|
wc.lpszClassName = TEXT("D3D9"); // class name
|
||||||
wc.lpfnWndProc = WindowProc; // callback function for windows to communicate with our application
|
wc.lpfnWndProc = WindowProc; // callback function for windows to communicate with our application
|
||||||
wc.hbrBackground = CreateSolidBrush(RGB(0, 255, 0));
|
wc.hbrBackground = CreateSolidBrush(RGB(0, 255, 0));
|
||||||
|
wc.hCursor = LoadCursor(nullptr, IDC_ARROW);
|
||||||
|
wc.hIcon = LoadIcon(nullptr, IDI_APPLICATION);
|
||||||
|
|
||||||
// 2. register window class
|
// 2. register window class
|
||||||
if (!RegisterClass(&wc)) return 100;
|
if (!RegisterClass(&wc)) return 100;
|
||||||
@@ -40,8 +42,19 @@ INT Window::init(HINSTANCE hInstance, UINT width, UINT height)
|
|||||||
BOOL Window::run()
|
BOOL Window::run()
|
||||||
{
|
{
|
||||||
// 6. run window
|
// 6. run window
|
||||||
|
// GetMessage - syncronous call which holds until a new message arrived
|
||||||
|
// PeekMessage - get last message from message queue or nothing if there is no message
|
||||||
|
// TranslateMessage - translates keyboard input
|
||||||
|
// DispatchMessage - send message to WindowProcedure
|
||||||
|
|
||||||
return true;
|
MSG msg = {};
|
||||||
|
if (PeekMessage(&msg, nullptr, 0, UINT_MAX, PM_REMOVE))
|
||||||
|
{
|
||||||
|
TranslateMessage(&msg);
|
||||||
|
DispatchMessage(&msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
return msg.message != WM_QUIT;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Window::deInit()
|
void Window::deInit()
|
||||||
@@ -50,5 +63,20 @@ void Window::deInit()
|
|||||||
|
|
||||||
LRESULT WindowProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
LRESULT WindowProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
||||||
{
|
{
|
||||||
|
switch (msg)
|
||||||
|
{
|
||||||
|
case WM_CLOSE:
|
||||||
|
DestroyWindow(hWnd);
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
case WM_DESTROY:
|
||||||
|
PostQuitMessage(0);
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
case WM_KEYDOWN:
|
||||||
|
if (wParam == VK_ESCAPE) DestroyWindow(hWnd);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
return DefWindowProc(hWnd, msg, wParam, lParam);
|
return DefWindowProc(hWnd, msg, wParam, lParam);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user