浏览代码

Examples: DPI: Hacked in a quick compile-and-run-everywhere call to SetProcessDpiAwareness(), will need to revisit.

omar 7 年之前
父节点
当前提交
aa3fe81c87
共有 1 个文件被更改,包括 20 次插入0 次删除
  1. 20 0
      examples/directx11_example/main.cpp

+ 20 - 0
examples/directx11_example/main.cpp

@@ -96,8 +96,28 @@ LRESULT WINAPI WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
     return DefWindowProc(hWnd, msg, wParam, lParam);
     return DefWindowProc(hWnd, msg, wParam, lParam);
 }
 }
 
 
+// FIXME-DPI: For now we just want to call SetProcessDpiAwareness(PROCESS_PER_MONITOR_AWARE) without requiring SDK 8.1 or 10
+void SetupDpiAwareness()
+{
+    typedef enum PROCESS_DPI_AWARENESS
+    {
+        PROCESS_DPI_UNAWARE = 0,
+        PROCESS_SYSTEM_DPI_AWARE = 1,
+        PROCESS_PER_MONITOR_DPI_AWARE = 2
+    } PROCESS_DPI_AWARENESS;
+    if (HINSTANCE shcore_dll = ::LoadLibraryA("shcore.dll"))
+    {
+        typedef HRESULT(WINAPI * PFN_SetProcessDpiAwareness)(PROCESS_DPI_AWARENESS);
+        if (PFN_SetProcessDpiAwareness SetProcessDpiAwarenessFn = (PFN_SetProcessDpiAwareness)::GetProcAddress(shcore_dll, "SetProcessDpiAwareness"))
+            SetProcessDpiAwarenessFn(PROCESS_PER_MONITOR_DPI_AWARE);
+        ::FreeLibrary(shcore_dll);
+    }
+}
+
 int main(int, char**)
 int main(int, char**)
 {
 {
+    SetupDpiAwareness();
+
     // Create application window
     // Create application window
     WNDCLASSEX wc = { sizeof(WNDCLASSEX), CS_CLASSDC, WndProc, 0L, 0L, GetModuleHandle(NULL), NULL, NULL, NULL, NULL, _T("ImGui Example"), NULL };
     WNDCLASSEX wc = { sizeof(WNDCLASSEX), CS_CLASSDC, WndProc, 0L, 0L, GetModuleHandle(NULL), NULL, NULL, NULL, NULL, _T("ImGui Example"), NULL };
     RegisterClassEx(&wc);
     RegisterClassEx(&wc);