怎样获取屏幕分辨率

来源:互联网 发布:ubuntu安装飞秋 编辑:程序博客网 时间:2024/06/01 14:36
1. Difference between resolution and DPI:
Resolution: 显示器width*height有多大
DPI: 每 Inch 显示多少个点(dot)
2. How to get resolution:
a)
unsigned int w = ::GetSystemMetrics(SM_CXSCREEN);
unsigned int h = ::GetSystemMetrics(SM_CYSCREEN);
b)
RECT rect;
::GetWindowRect(::GetDesktopWindow(), &rect);
unsigned int w = ::abs(rect.right - rect.left);
unsigned int h = ::abs(rect.bottom - rect.top);

3. How to get DPI:
HDC hDC = ::GetDC(0);
int dpiX = ::GetDeviceCaps(hDC, LOGPIXELSX);
int dpiY = ::GetDeviceCaps(hDC, LOGPIXELSY);
原创粉丝点击