@@ -2,15 +2,17 @@ extern "C"{
2
2
#define WIN32_LEAN_AND_MEAN
3
3
#include < windows.h>
4
4
#include < windowsx.h>
5
+ #include < shellscalingapi.h>
5
6
#include < dwmapi.h>
6
7
#include < GL/gl.h>
7
8
#include " win32_window.h"
8
9
#include " swcadef.h" // Courtesy of https://gist.github.com/sylveon/9c199bb6684fe7dffcba1e3d383fb609
9
10
}
10
11
12
+ #pragma comment (lib, "shcore")
13
+ #pragma comment (lib, "dwmapi")
11
14
#pragma comment (lib, "opengl32")
12
15
#pragma comment (lib, "glu32")
13
- #pragma comment (lib, "dwmapi")
14
16
15
17
#include " imgui.h"
16
18
#include " imgui_internal.h"
@@ -52,7 +54,9 @@ static void Hook_Renderer_DestroyWindow(ImGuiViewport* viewport);
52
54
static void Hook_Platform_RenderWindow (ImGuiViewport* viewport, void *);
53
55
static void Hook_Renderer_SwapBuffers (ImGuiViewport* viewport, void *);
54
56
55
- int APIENTRY wWinMain (
57
+ int
58
+ APIENTRY
59
+ wWinMain (
56
60
_In_ HINSTANCE hInstance,
57
61
_In_opt_ HINSTANCE hPrevInstance,
58
62
_In_ LPWSTR lpCmdLine,
@@ -63,29 +67,37 @@ int APIENTRY wWinMain(
63
67
UNREFERENCED_PARAMETER (lpCmdLine);
64
68
UNREFERENCED_PARAMETER (nCmdShow);
65
69
66
- ImGui_ImplWin32_EnableDpiAwareness ();
67
- win32_window_t w32Window = {0 };
68
- win32_window_create (&w32Window, 1080 , 720 , 0 , ImGuiBorderlessWin32::windowed);
69
- w32Window.msgHook = (win32_wndproc_hook_t )WndProcHook;
70
+ win32_window_t win32_window = { 0 };
70
71
71
- if (!CreateDeviceWGL (w32Window.hWnd , &g_MainWindow))
72
+ HRESULT hr = SetProcessDpiAwareness (PROCESS_PER_MONITOR_DPI_AWARE); // This can be set by a program's manifest or its corresponding registry settings
73
+ if (E_INVALIDARG == hr)
72
74
{
73
- CleanupDeviceWGL (w32Window.hWnd , &g_MainWindow);
74
- ::DestroyWindow (w32Window.hWnd);
75
- ::UnregisterClass (w32Window.tcClassName, GetModuleHandle(NULL ));
75
+ return 1 ;
76
+ }
77
+
78
+ win32_window_create (&win32_window, 1080 , 720 , 0 , ImGuiBorderlessWin32::windowed);
79
+ win32_window.msgHook = (win32_wndproc_hook_t )WndProcHook;
80
+
81
+ if (!CreateDeviceWGL (win32_window.hWnd , &g_MainWindow))
82
+ {
83
+ CleanupDeviceWGL (win32_window.hWnd , &g_MainWindow);
84
+ ::DestroyWindow (win32_window.hWnd);
85
+ ::UnregisterClass (win32_window.tcClassName, GetModuleHandle(NULL ));
76
86
return 1 ;
77
87
}
78
88
79
89
wglMakeCurrent (g_MainWindow.hDC , g_hRC);
80
90
81
- ::ShowWindow (w32Window .hWnd, SW_SHOWDEFAULT);
82
- ::UpdateWindow (w32Window .hWnd);
91
+ ::ShowWindow (win32_window .hWnd, SW_SHOWDEFAULT);
92
+ ::UpdateWindow (win32_window .hWnd);
83
93
84
94
IMGUI_CHECKVERSION ();
85
95
ImGui::CreateContext ();
86
96
ImGuiIO& io = ImGui::GetIO ();
87
97
io.ConfigFlags |= ImGuiConfigFlags_DockingEnable; // Enable Docking
88
98
io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable; // Enable Multi-Viewport / Platform Windows
99
+ io.ConfigFlags |= ImGuiConfigFlags_DpiEnableScaleFonts;
100
+ io.ConfigFlags |= ImGuiConfigFlags_DpiEnableScaleViewports;
89
101
90
102
// Setup Dear ImGui style
91
103
ImGui::StyleColorsDark ();
@@ -98,8 +110,9 @@ int APIENTRY wWinMain(
98
110
}
99
111
100
112
// Setup Platform/Renderer backends
101
- ImGui_ImplWin32_InitForOpenGL ((void *)w32Window .hWnd );
113
+ ImGui_ImplWin32_InitForOpenGL ((void *)win32_window .hWnd );
102
114
ImGui_ImplOpenGL3_Init ();
115
+ ImGui_ImplWin32_EnableDpiAwareness ();
103
116
104
117
if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable)
105
118
{
@@ -117,13 +130,14 @@ int APIENTRY wWinMain(
117
130
for (;;)
118
131
{
119
132
MSG msg; // - Pump message loop; break on WM_QUIT
120
- if (!win32_window_pump_message_loop (&w32Window , &msg, FALSE )) break ;
133
+ if (!win32_window_pump_message_loop (&win32_window , &msg, FALSE )) break ;
121
134
122
135
// - Set the client render function callback if not done so already (So we can also render in sizemoves)
123
136
if (!g_ClientRenderFunction)
124
137
{
125
- g_ClientRenderFunction = [io ](HWND hWnd) {
138
+ g_ClientRenderFunction = [](HWND hWnd) {
126
139
static ImVec4 clear_color (.0f , .0f , .0f , .0f );
140
+ ImGuiIO& io = ImGui::GetIO ();
127
141
128
142
ImGui_ImplOpenGL3_NewFrame ();
129
143
ImGui_ImplWin32_NewFrame ();
@@ -204,17 +218,17 @@ int APIENTRY wWinMain(
204
218
}
205
219
206
220
// - Then just make that client render call like usual
207
- g_ClientRenderFunction (w32Window .hWnd );
221
+ g_ClientRenderFunction (win32_window .hWnd );
208
222
}
209
223
210
224
ImGui_ImplOpenGL3_Shutdown ();
211
225
ImGui_ImplWin32_Shutdown ();
212
226
ImGui::DestroyContext ();
213
227
214
- CleanupDeviceWGL (w32Window .hWnd , &g_MainWindow);
228
+ CleanupDeviceWGL (win32_window .hWnd , &g_MainWindow);
215
229
wglDeleteContext (g_hRC);
216
- ::DestroyWindow (w32Window .hWnd);
217
- ::UnregisterClass (w32Window .tcClassName, GetModuleHandle(NULL ));
230
+ ::DestroyWindow (win32_window .hWnd);
231
+ ::UnregisterClass (win32_window .tcClassName, GetModuleHandle(NULL ));
218
232
219
233
return 0 ;
220
234
} // main
0 commit comments