Changeset 72013 in vbox
- Timestamp:
- Apr 25, 2018 1:19:33 PM (7 years ago)
- svn:sync-xref-src-repo-rev:
- 122274
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/globals/UIDesktopWidgetWatchdog.cpp
r72012 r72013 38 38 39 39 /* Other VBox includes: */ 40 # include <iprt/asm.h> 40 41 # include <iprt/assert.h> 42 # include <iprt/ldr.h> 41 43 # include <VBox/log.h> 42 44 … … 51 53 #ifdef VBOX_WS_WIN 52 54 55 # ifndef DPI_ENUMS_DECLARED 53 56 typedef enum _MONITOR_DPI_TYPE // gently stolen from MSDN 54 57 { … … 58 61 MDT_DEFAULT = MDT_EFFECTIVE_DPI 59 62 } MONITOR_DPI_TYPE; 63 # endif 64 typedef void (WINAPI *PFN_GetDpiForMonitor)(HMONITOR, MONITOR_DPI_TYPE, uint *, uint *); 65 66 /** Set when dynamic API import is reoslved. */ 67 static bool volatile g_fResolved; 68 /** Pointer to Shcore.dll!GetDpiForMonitor, introduced in windows 8.1. */ 69 static PFN_GetDpiForMonitor g_pfnGetDpiForMonitor = NULL; 70 71 /** @returns true if all APIs found, false if missing APIs */ 72 static bool ResolveDynamicImports(void) 73 { 74 if (!g_fResolved) 75 { 76 PFN_GetDpiForMonitor pfn = (decltype(pfn))RTLdrGetSystemSymbol("Shcore.dll", "GetDpiForMonitor"); 77 g_pfnGetDpiForMonitor = pfn; 78 ASMCompilerBarrier(); 79 80 g_fResolved = true; 81 } 82 return g_pfnGetDpiForMonitor != NULL; 83 } 60 84 61 85 static BOOL CALLBACK MonitorEnumProcF(HMONITOR hMonitor, HDC hdcMonitor, LPRECT lpClipRect, LPARAM dwData) … … 64 88 RT_NOREF(hdcMonitor, lpClipRect); 65 89 66 /* Dynamically access Shcore.dll: */67 QLibrary shcore("Shcore.dll", NULL);68 69 90 /* Acquire effective DPI (available since Windows 8.1): */ 70 typedef void (WINAPI *GetDpiForMonitorFP)(HMONITOR hMonitor, MONITOR_DPI_TYPE enmDpiType, uint *puOutX, uint *puOutY); 71 GetDpiForMonitorFP GetDpiForMonitorF = (GetDpiForMonitorFP)shcore.resolve("GetDpiForMonitor"); 72 if (GetDpiForMonitorF) 73 { 74 uint uOutX = 0; 75 uint uOutY = 0; 76 GetDpiForMonitorF(hMonitor, MDT_EFFECTIVE_DPI, &uOutX, &uOutY); 77 reinterpret_cast<QList<QPair<int, int> >*>(dwData)->append(qMakePair(uOutX, uOutY)); 78 return true; 79 } 80 81 /* False by default: */ 82 return false; 91 AssertReturn(g_pfnGetDpiForMonitor, false); 92 uint uOutX = 0; 93 uint uOutY = 0; 94 g_pfnGetDpiForMonitor(hMonitor, MDT_EFFECTIVE_DPI, &uOutX, &uOutY); 95 reinterpret_cast<QList<QPair<int, int> >*>(dwData)->append(qMakePair(uOutX, uOutY)); 96 97 return TRUE; 83 98 } 84 99 … … 432 447 433 448 #ifdef VBOX_WS_WIN 434 /* Dynamically resolve EnumDisplayMonitors (available since Windows 2k) first time through: */ 435 static bool volatile s_fResolved = false; 436 static decltype(EnumDisplayMonitors) *s_pfnEnumDisplayMonitors = NULL; 437 decltype(EnumDisplayMonitors) *pfnEnumDisplayMonitors; 438 if (s_fResolved) 439 pfnEnumDisplayMonitors = s_pfnEnumDisplayMonitors; 440 else 441 { 442 pfnEnumDisplayMonitors = (decltype(EnumDisplayMonitors) *)GetProcAddress(GetModuleHandleW(L"USER32.DLL"), 443 "EnumDisplayMonitors"); 444 s_pfnEnumDisplayMonitors = pfnEnumDisplayMonitors; 445 s_fResolved = true; 446 } 447 448 /* Enumerate available monitors through EnumDisplayMonitors if available: */ 449 if (pfnEnumDisplayMonitors) 449 /* Enumerate available monitors through EnumDisplayMonitors if GetDpiForMonitor is available: */ 450 if (ResolveDynamicImports()) 450 451 { 451 452 QList<QPair<int, int> > listOfScreenDPI; 452 pfnEnumDisplayMonitors(0, 0, MonitorEnumProcF, (LPARAM)&listOfScreenDPI);453 EnumDisplayMonitors(0, 0, MonitorEnumProcF, (LPARAM)&listOfScreenDPI); 453 454 if (iHostScreenIndex >= 0 && iHostScreenIndex < listOfScreenDPI.size()) 454 455 {
Note:
See TracChangeset
for help on using the changeset viewer.