-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwindow_setup.cpp
More file actions
72 lines (63 loc) · 2.56 KB
/
window_setup.cpp
File metadata and controls
72 lines (63 loc) · 2.56 KB
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
#include "window_setup.h"
#include "dx_setup.h"
#include "imgui.h"
#include "imgui_impl_win32.h"
#include <comdef.h>
#include <memory>
#include <tchar.h>
extern IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND windowHandle, UINT windowMessage, WPARAM wordParameter, LPARAM longParameter);
HWND InitializeHostWindow(HINSTANCE applicationInstance, const TCHAR* windowClassName)
{
WNDCLASSEX windowClass = { sizeof(WNDCLASSEX), CS_CLASSDC, HandleWindowMessages, 0L, 0L, applicationInstance, NULL, NULL, NULL, NULL, windowClassName, NULL };
if (!::RegisterClassEx(&windowClass)) {
MessageBox(NULL, _T("Failed to register window class!"), _T("Error"), MB_OK | MB_ICONERROR);
return NULL;
}
HWND createdWindowHandle = ::CreateWindowEx(
0, windowClass.lpszClassName, _T("V-Launch Host"), WS_POPUP,
0, 0, 1, 1,
NULL, NULL, windowClass.hInstance, NULL);
if (!createdWindowHandle) {
MessageBox(NULL, _T("Failed to create hidden host window!"), _T("Error"), MB_OK | MB_ICONERROR);
::UnregisterClass(windowClass.lpszClassName, windowClass.hInstance);
return NULL;
}
return createdWindowHandle;
}
void DestroyHostWindow(HINSTANCE applicationInstance, const TCHAR* windowClassName)
{
::UnregisterClass(windowClassName, applicationInstance);
}
LRESULT WINAPI HandleWindowMessages(HWND windowHandle, UINT windowMessage, WPARAM wordParameter, LPARAM longParameter)
{
if (ImGui::GetCurrentContext() && ImGui_ImplWin32_WndProcHandler(windowHandle, windowMessage, wordParameter, longParameter))
return true;
switch (windowMessage)
{
case WM_SIZE:
{
IDXGISwapChain* activeSwapChain = GetDirectXSwapChain();
if (activeSwapChain != NULL && wordParameter != SIZE_MINIMIZED)
{
DestroyRenderTarget();
HRESULT resultCode = activeSwapChain->ResizeBuffers(0, (UINT)LOWORD(longParameter), (UINT)HIWORD(longParameter), DXGI_FORMAT_UNKNOWN, 0);
if (SUCCEEDED(resultCode)) {
BuildRenderTarget();
}
else {
_com_error errorInformation(resultCode);
MessageBox(windowHandle, errorInformation.ErrorMessage(), _T("ResizeBuffers Failed"), MB_OK | MB_ICONERROR);
}
}
return 0;
}
case WM_SYSCOMMAND:
if ((wordParameter & 0xfff0) == SC_KEYMENU)
return 0;
break;
case WM_DESTROY:
::PostQuitMessage(0);
return 0;
}
return ::DefWindowProc(windowHandle, windowMessage, wordParameter, longParameter);
}