- 1、获取屏幕分辨率
- 1.1 GetSystemMetrics
- 1.2 GetDeviceCaps
- 1.3 SystemParametersInfo
- 1.4 GetDesktopWindow
- 2、获取屏幕显示比例
- 后续
整个屏幕区域。
# includeint cx = GetSystemMetrics( SM_CXSCREEN ); int cy = GetSystemMetrics( SM_CYSCREEN );
不包括任务栏等区域.
# include1.2 GetDeviceCapsint cx = GetSystemMetrics( SM_CXFULLSCREEN ); int cy = GetSystemMetrics( SM_CYFULLSCREEN );
HDC hDC = ::GetDC(NULL); // 得到屏幕DC int cx = ::GetDeviceCaps(hDC,HORZRES); // 宽 int cy = ::GetDeviceCaps(hDC,VERTRES); // 高 ::ReleaseDC(NULL,hDC); // 释放DC
HDC hDC = ::GetDC(NULL); // 得到屏幕DC int cx = ::GetDeviceCaps(hDC,DESKTOPHORZRES); // 宽 int cy = ::GetDeviceCaps(hDC,DESKTOPVERTRES); // 高 ::ReleaseDC(NULL,hDC); // 释放DC1.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、获取屏幕显示比例
- GetDpiForWindow function (winuser.h)
- Minimum supported client Windows 10, version 1607 [desktop apps only]
DPI 的基值定义为 USER _ DEFAULT SCREEN _ _ DPI, 设置为 96。 若要确定监视器的缩放因子,请取 DPI 值并除以 USER _ DEFAULT SCREEN _ _ DPI。 下表提供了一些示例 DPI 值和相关缩放因子。
| DPI 值 | 缩放百分比 |
|---|---|
| 96 | 100% |
| 120 | 125% |
| 144 | 150% |
| 192 | 200% |
#include后续#include 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???
谢谢各位童鞋们啦( ´ ▽´ )ノ ( ´ ▽´ )っ!!!



