-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathwinmain.cpp
113 lines (91 loc) · 2.31 KB
/
winmain.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#include "stdafx.h"
#include "app.h"
bool gDestroy = false;
bool gActive = true;
HWND gWndHandle;
LRESULT WINAPI MsgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch (msg)
{
case WM_DESTROY:
gDestroy = true;
break;
case WM_ACTIVATE:
gActive = wParam != WA_INACTIVE;
break;
case WM_KEYDOWN:
gApp.OnKeyDown(wParam);
break;
case WM_LBUTTONDOWN:
gApp.OnLButtonDown(LOWORD(lParam), HIWORD(lParam));
break;
case WM_LBUTTONUP:
gApp.OnLButtonUp(LOWORD(lParam), HIWORD(lParam));
break;
case WM_MOUSEMOVE:
gApp.OnMouseMove(LOWORD(lParam), HIWORD(lParam));
break;
case WM_MOUSEWHEEL:
gApp.OnMouseWheel(GET_WHEEL_DELTA_WPARAM(wParam));
break;
case WM_SIZE:
gApp.OnResize();
break;
}
return DefWindowProc(hWnd, msg, wParam, lParam);
}
void MainLoop(HINSTANCE hInst)
{
MSG Msg;
while (!gDestroy)
{
if (PeekMessage(&Msg, NULL, 0, 0, PM_NOREMOVE))
{
if (!GetMessage(&Msg, NULL, 0, 0))
return;
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
else
{
if (gActive)
{
gApp.Render();
Sleep(1);
}
}
}
}
INT WINAPI WinMain(HINSTANCE hInst, HINSTANCE, LPSTR lpCmdLine, INT)
{
wchar_t const* appName = L"rt_bc6h_encoder_gpu";
WNDCLASSEX wc = { sizeof(WNDCLASSEX), 0, MsgProc, 0L, 0L, GetModuleHandle(NULL), NULL, NULL, NULL, NULL, appName, NULL };
RegisterClassEx(&wc);
DWORD const dwStyle = WS_SYSMENU | WS_MAXIMIZEBOX | WS_MINIMIZEBOX | WS_SIZEBOX;
RECT rcWindowSize;
SetRect(&rcWindowSize, 0, 0, 1280, 720);
AdjustWindowRect(&rcWindowSize, dwStyle, FALSE);
RECT rcDesktop;
GetClientRect(GetDesktopWindow(), &rcDesktop);
if (rcWindowSize.bottom < rcDesktop.bottom)
{
rcWindowSize.bottom -= rcWindowSize.top;
rcWindowSize.top = 0;
}
if (rcWindowSize.right < rcDesktop.right)
{
int iTranslate = (rcDesktop.right - (rcWindowSize.right - rcWindowSize.left)) / 2;
rcWindowSize.left += iTranslate;
rcWindowSize.right += iTranslate;
}
gWndHandle = CreateWindow(appName, appName, dwStyle, rcWindowSize.left, rcWindowSize.top,
rcWindowSize.right - rcWindowSize.left, rcWindowSize.bottom - rcWindowSize.top,
GetDesktopWindow(), nullptr, wc.hInstance, nullptr);
gApp.Init(gWndHandle);
ShowWindow(gWndHandle, SW_SHOWDEFAULT);
UpdateWindow(gWndHandle);
MainLoop(hInst);
UnregisterClass(appName, wc.hInstance);
gApp.Release();
return 0;
}