win10c语言编程运行不了,c – SetProcessDPIAware似乎无法在Windows 10下运行

本文探讨了如何在Windows应用程序中获取真实的屏幕分辨率而非调整后的分辨率,尤其是在Windows 10环境中遇到的问题及解决方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

我试图在

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

有任何想法吗?

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值