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
|
#include "WindowsObject.h"
WindowsObject::WindowsObject()
:
m_hInstance(GetModuleHandle(NULL)),
m_windowClassName(L"DirectX11Engine")
{
InitializeWindow(800, 600, true);
}
void WindowsObject::InitializeWindow(int displayResWidth, int displayResHeight, bool displayWindowed)
{
WNDCLASSEX wc;
ZeroMemory(&wc, sizeof(wc));
wc.cbClsExtra = NULL;
wc.cbSize = sizeof(WNDCLASSEX);
wc.cbWndExtra = NULL;
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
wc.hInstance = m_hInstance;
wc.lpfnWndProc = WndProc;
wc.lpszClassName = m_windowClassName;
wc.lpszMenuName = NULL;
wc.style = CS_OWNDC | CS_HREDRAW | CS_VREDRAW;
RegisterClassEx(&wc);
if(displayWindowed)
{
m_windowPosX = (GetSystemMetrics(SM_CXSCREEN) - displayResWidth) / 2;
m_windowPosY = (GetSystemMetrics(SM_CYSCREEN) - displayResHeight) / 2;
m_hWnd = CreateWindowEx(NULL, m_windowClassName, L"DirectX 11 App", WS_OVERLAPPEDWINDOW,
m_windowPosX, m_windowPosY, displayResWidth, displayResHeight, NULL, NULL, m_hInstance, NULL);
}
ShowWindow(m_hWnd, SW_SHOW);
UpdateWindow(m_hWnd);
}
void WindowsObject::MessageProcedure()
{
D3D11App D3DApp(m_hWnd);
MSG msg;
ZeroMemory(&msg, sizeof(msg));
while(msg.message != WM_QUIT)
{
if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
else
{
}
}
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg)
{
case WM_DESTROY:
PostQuitMessage(0);
break;
}
return DefWindowProc(hWnd, msg, wParam, lParam);
}
|