1、获取屏幕分辨率
1.1 GetSystemMetrics
整个屏幕区域。
# include <windows.h>
int cx = GetSystemMetrics( SM_CXSCREEN );
int cy = GetSystemMetrics( SM_CYSCREEN );
不包括任务栏等区域.
# include <windows.h>
int cx = GetSystemMetrics( SM_CXFULLSCREEN );
int cy = GetSystemMetrics( SM_CYFULLSCREEN );
1.2 GetDeviceCaps
HDC hDC = ::GetDC(NULL);
int cx = ::GetDeviceCaps(hDC,HORZRES);
int cy = ::GetDeviceCaps(hDC,VERTRES);
::ReleaseDC(NULL,hDC);
HDC hDC = ::GetDC(NULL);
int cx = ::GetDeviceCaps(hDC,DESKTOPHORZRES);
int cy = ::GetDeviceCaps(hDC,DESKTOPVERTRES);
::ReleaseDC(NULL,hDC);
1.3 SystemParametersInfo
RECT rect;
SystemParametersInfo(SPI_GETWORKAREA, 0, &rect, SPIF_SENDCHANGE);
int cx = (rect.right - rect.left);
int cy = (rect.bottom - rect.top);
1.4 GetDesktopWindow
HWND hd = GetDesktopWindow();
RECT rect;
GetWindowRect(hd, &rect);
int cx = (rect.right - rect.left);
int cy = (rect.bottom - rect.top);
2、获取屏幕显示比例
DPI 的基值定义为 USER _ DEFAULT SCREEN _ _ DPI, 设置为 96。 若要确定监视器的缩放因子,请取 DPI 值并除以 USER _ DEFAULT SCREEN _ _ DPI。 下表提供了一些示例 DPI 值和相关缩放因子。
DPI 值 | 缩放百分比 |
---|
96 | 100% | 120 | 125% | 144 | 150% | 192 | 200% |
#include <Windows.h>
#include <iostream>
HWND hd = GetDesktopWindow();
int zoom = GetDpiForWindow(hd);
double dpi = 0;
switch (zoom) {
case 96:
dpi = 1;
std::cout << "100%" << std::endl;
break;
case 120:
dpi = 1.25;
std::cout << "125%" << std::endl;
break;
case 144:
dpi = 1.5;
std::cout << "150%" << std::endl;
break;
case 192:
dpi = 2;
std::cout << "200%" << std::endl;
break;
default:
std::cout << "error" << std::endl;
break;
}
后续
如果你觉得该方法或代码有一点点用处,可以给作者点个赞;╮( ̄▽ ̄)╭ 如果你感觉方法或代码不咋地//(ㄒoㄒ)//,就在评论处留言,作者继续改进。o_O??? 谢谢各位童鞋们啦( ′ ▽′ )ノ ( ′ ▽′ )っ!!!
|