-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwinmain.cpp
119 lines (94 loc) · 2.68 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
114
115
116
117
118
119
#include <windows.h>
#include <iostream>
#include <fcntl.h>
#include <cstdio>
#include "defined.h"
#include "dxentry.h"
using namespace std;
void RedirectIOToConsole(int maxLineOfConsole = 500)
{
AllocConsole();
FILE* stream;
freopen_s(&stream, "CONIN$", "r", stdin);
freopen_s(&stream, "CONOUT$", "w", stdout);
freopen_s(&stream, "CONOUT$", "w", stderr);
}
LRESULT CALLBACK MsgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
PAINTSTRUCT ps;
HDC hdc;
switch (uMsg)
{
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
EndPaint(hWnd, &ps);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
case WM_SIZE:
{
UINT width = LOWORD(lParam);
UINT height = HIWORD(lParam);
FAILED_MESSAGE_RETURN_CODE(DXEntryResize(width, height), L"fail to resize d3d objects..", 0);
break;
}
default:
return DefWindowProc(hWnd, uMsg, wParam, lParam);
}
return 0;
}
inline WNDCLASSW GetWindowClass(HINSTANCE hInstance, WNDPROC msgProc, LPCWSTR className)
{
WNDCLASSW wndClass;
memset(&wndClass, 0, sizeof(WNDCLASS));
wndClass.style = CS_DBLCLKS;
wndClass.lpfnWndProc = msgProc;
wndClass.hInstance = hInstance;
wndClass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
wndClass.lpszClassName = className;
return wndClass;
}
inline HWND GetCreatedWindow(HINSTANCE hInstance, LPWNDCLASSW wndClass, LPCWSTR windowTitle, UINT width, UINT height)
{
RECT rc;
SetRect(&rc, 0, 0, width, height);
AdjustWindowRect(&rc, WS_OVERLAPPEDWINDOW, false);
return CreateWindowW(wndClass->lpszClassName, windowTitle, WS_POPUP | WS_BORDER | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME, 100, 100, width, height, 0, (HMENU)nullptr, hInstance, 0);
}
void WindowLoop(HWND hWnd)
{
MSG msg = { 0, };
while (msg.message != WM_QUIT)
{
if (PeekMessage(&msg, nullptr, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
else
{
DXEntryFrameUpdate();
}
}
}
int WINAPI wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPWSTR lpCmdLine, _In_ int nCmdShow)
{
RedirectIOToConsole();
// Register the windows class
WNDCLASSW wndClass = GetWindowClass(hInstance, MsgProc, L"Direct3DWindowClass");
FALSE_MESSAGE_RETURN(RegisterClassW(&wndClass), L"fail to register window class..");
UINT nDefaultWidth = 1280, nDefaultHeight = 800, maxFrameRate = 144;
WCHAR strWindowTitle[] = L"DirectX11 Tutorial 7(Clone)";
HWND hWnd = GetCreatedWindow(hInstance, &wndClass, strWindowTitle, nDefaultWidth, nDefaultHeight);
ShowWindow(hWnd, SW_SHOW);
UpdateWindow(hWnd);
FAILED_MESSAGE_RETURN(
DXEntryInit(hInstance, hWnd, nDefaultWidth, nDefaultHeight, maxFrameRate, true),
L"Fail to initialize."
);
WindowLoop(hWnd);
DXEntryClean();
FreeConsole();
return 0;
}