我试图在
Windows C应用程序中获得真正的屏幕分辨率(以像素为单位).当Windows dpi设置改变时,我得到虚拟(调整)分辨率而不是真实分辨率.我尝试使用SetProcessDPIAware,SetProcessDpiAwareness(所有三个枚举值作为参数)和清单中的真实设置.在所有三种情况下,代码在我的Windows 7 PC中工作正常(即显示真实分辨率)但在Win 10中没有(这里它忽略了DPI Aware设置并返回调整后的分辨率).
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
// Windows Header Files:
#include
#include
#include
#include
#include
#include
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
char *cBuffer2 ;
cBuffer2 = (char *)malloc(3000) ;
if (IsWindowsVistaOrGreater())
{
// SetProcessDpiAwareness(PROCESS_SYSTEM_DPI_AWARE);
int result = SetProcessDPIAware();
sprintf(cBuffer2,"SetProcessDPIAware() result: [%i]\n",result) ;
int height = GetSystemMetrics(SM_CYSCREEN);
int width = GetSystemMetrics(SM_CXSCREEN);
sprintf(cBuffer2,"%s#1:\nHeight: [%i]\nwidth: [%i]\n",cBuffer2,height,width) ;
HWND hwnd = (HWND)atoi(lpCmdLine) ;
HMONITOR monitor = MonitorFromWindow(hwnd, MONITOR_DEFAULTTONEAREST);
MONITORINFO info;
info.cbSize = sizeof(MONITORINFO);
GetMonitorInfo(monitor, &info);
int monitor_width = info.rcMonitor.right - info.rcMonitor.left;
int monitor_height = info.rcMonitor.bottom - info.rcMonitor.top;
sprintf(cBuffer2,"%s#2:\nHeight: [%i]\nwidth: [%i]\n",cBuffer2,monitor_height,monitor_width) ;
}
MessageBox(0,cBuffer2,"SHOWRES.EXE",MB_OK) ;
return 0 ;
}
我尝试使用的清单如下:
true
有任何想法吗?