MCPcopy Create free account
hub / github.com/MicrosoftEdge/WebView2Samples / GetDpiForWindow

Method GetDpiForWindow

SampleApps/WebView2APISample/DpiUtil.cpp:42–59  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

40}
41
42int DpiUtil::GetDpiForWindow(HWND window)
43{
44 static auto GetDpiForMonitorFunc = []() {
45 return reinterpret_cast<decltype(&::GetDpiForMonitor)>(
46 ::GetProcAddress(GetShcoreModule(), "GetDpiForMonitor"));
47 }();
48 if (GetDpiForMonitorFunc)
49 {
50 UINT dpi_x, dpi_y;
51 HMONITOR monitor = ::MonitorFromWindow(window, MONITOR_DEFAULTTONEAREST);
52 CHECK_FAILURE(GetDpiForMonitorFunc(monitor, MDT_EFFECTIVE_DPI, &dpi_x, &dpi_y));
53 return dpi_x;
54 }
55 else
56 {
57 return GetDeviceCaps(GetDC(nullptr), LOGPIXELSX);
58 }
59}
60
61HMODULE DpiUtil::GetUser32Module()
62{

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected