UINT SetupDPI() { // Just do system DPI awareness for now for simplicity... scale the 3D content SetProcessDpiAwareness(PROCESS_SYSTEM_DPI_AWARE); UINT dpiX = 0, dpiY; POINT pt = { 1, 1 }; auto hMonitor = MonitorFromPoint(pt, MONITOR_DEFAULTTONEAREST); if (SUCCEEDED(GetDpiForMonitor(hMonitor, MDT_EFFECTIVE_DPI, &dpiX, &dpiY))) { return dpiX; } else { return 96; // default } }
void _glfwGetMonitorContentScaleWin32(HMONITOR handle, float* xscale, float* yscale) { UINT xdpi, ydpi; if (IsWindows8Point1OrGreater()) GetDpiForMonitor(handle, MDT_EFFECTIVE_DPI, &xdpi, &ydpi); else { const HDC dc = GetDC(NULL); xdpi = GetDeviceCaps(dc, LOGPIXELSX); ydpi = GetDeviceCaps(dc, LOGPIXELSY); ReleaseDC(NULL, dc); } if (xscale) *xscale = xdpi / (float) USER_DEFAULT_SCREEN_DPI; if (yscale) *yscale = ydpi / (float) USER_DEFAULT_SCREEN_DPI; }
LRESULT MetroWindow::InitializeWindow() { HMONITOR hMonitor; POINT pt; UINT dpix = 0, dpiy = 0; HRESULT hr = E_FAIL; // Get the DPI for the main monitor, and set the scaling factor pt.x = 1; pt.y = 1; hMonitor = MonitorFromPoint(pt, MONITOR_DEFAULTTONEAREST); hr = GetDpiForMonitor(hMonitor, MDT_EFFECTIVE_DPI, &dpix, &dpiy); if (hr != S_OK) { ::MessageBox(NULL, (LPCWSTR)L"GetDpiForMonitor failed", (LPCWSTR)L"Notification", MB_OK); return FALSE; } g_Dpi->SetScale(dpix); RECT layout = { g_Dpi->Scale(100), g_Dpi->Scale(100), g_Dpi->Scale(720), g_Dpi->Scale(540) }; Create(nullptr, layout, L"PE File Analyzer", WS_NORESIZEWINDOW, WS_EX_APPWINDOW | WS_EX_WINDOWEDGE); return S_OK; }