Пример #1
0
int CDpiAware::QueryDpi(HWND hWnd /*= NULL*/, DpiValue* pDpi /*= NULL*/)
{
	#if defined(_DEBUG) && defined(DPI_144)
	if (pDpi) pDpi->SetDpi(144,144);
	return 144;
	#endif

	if (hWnd && IsPerMonitorDpi())
	{
		HMONITOR hMon = MonitorFromWindow(hWnd, MONITOR_DEFAULTTONEAREST);
		if (hMon)
		{
			return QueryDpiForMonitor(hMon, pDpi);
		}
	}

	return QueryDpiForWindow(hWnd, pDpi);
}
Пример #2
0
void CDpiAware::UpdateStartupInfo(CEStartupEnv* pStartEnv)
{
	if (!pStartEnv)
		return;

	pStartEnv->bIsPerMonitorDpi = IsPerMonitorDpi();
	for (INT_PTR i = ((int)pStartEnv->nMonitorsCount)-1; i >= 0; i--)
	{
		HMONITOR hMon = MonitorFromRect(&pStartEnv->Monitors[i].rcMonitor, MONITOR_DEFAULTTONEAREST);
		if (!hMon)
			continue;

		for (int j = MDT_Effective_DPI; j <= MDT_Raw_DPI; j++)
		{
			DpiValue dpi;
			QueryDpiForMonitor(hMon, &dpi, (MonitorDpiType)j);
			pStartEnv->Monitors[i].dpis[j+1].x = dpi.Xdpi;
			pStartEnv->Monitors[i].dpis[j+1].y = dpi.Xdpi;
		}
	}
}
Пример #3
0
void CDpiAware::CenterDialog(HWND hDialog)
{
	RECT rect = {}, rectAfter = {};
	if (!hDialog || !GetWindowRect(hDialog, &rect))
		return;

	// If possible, open our startup dialogs on the monitor,
	// where user have clicked our icon (shortcut on the desktop or TaskBar)
	HMONITOR hDefault = ghWnd ? NULL : gpStartEnv->hStartMon;

	// Position dialog in the workarea center
	CDpiAware::GetCenteredRect(NULL, rect, hDefault);
	MoveWindowRect(hDialog, rect);

	if (IsPerMonitorDpi() && GetWindowRect(hDialog, &rectAfter))
	{
		if ((RectWidth(rect) != RectWidth(rectAfter)) || (RectHeight(rect) != RectHeight(rectAfter)))
		{
			CDpiAware::GetCenteredRect(NULL, rectAfter, NULL);
			MoveWindowRect(hDialog, rectAfter);
		}
	}
}