c++ winform 不能调用获取屏幕分辨率函数GetSystemMetrics的问题

本文探讨了使用Windows API函数GetSystemMetrics(SM_CXSIZE)获取按钮尺寸的问题。该函数在不同版本的Windows中返回不同的值,导致界面调整困难。文章提供了一个示例代码并寻求解决方案。

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

#include "windows.h"
#pragma comment(lib, "user32.lib")


int cx = GetSystemMetrics( SM_CXSCREEN ); 
int cy = GetSystemMetrics( SM_CYSCREEN );




参考MSDN资源如下:

I am trying to get the size of the button in Windows in my project using windows API GetSystemMetrics(SM_CXSIZE).

Whereas GetSystemMetrics(SM_CXSIZE) returns '36' in Windows 8 and I am able to adjust the tool bar window correctly. But it returns '22' in Windows Server 2012 and I am not able to adjust my tool bar properly.

A sample code snippet is:

#include <windows.h>
#include <stdio.h>
#pragma comment(lib, "user32.lib")

int main()
{    
   printf("Value SM_CXSIZE: %d", GetSystemMetrics(SM_CXSIZE));   
   return 0;
}

Can you please suggest a way to accomplish this.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值