windows 获取显示器像素分辨率
时间: 2023-08-12 11:20:02 浏览: 58
可以使用 `GetSystemMetrics` 函数获取当前系统的显示器像素分辨率。下面是示例代码:
```cpp
int screenWidth = GetSystemMetrics(SM_CXSCREEN);
int screenHeight = GetSystemMetrics(SM_CYSCREEN);
```
其中 `SM_CXSCREEN` 和 `SM_CYSCREEN` 分别代表屏幕的宽度和高度,返回值为像素单位。这段代码返回的是当前系统所有显示器的分辨率,如果要获取指定显示器的分辨率,可以使用 `EnumDisplayMonitors` 函数遍历所有显示器,并使用 `GetMonitorInfo` 函数获取指定显示器的信息,包括分辨率。
相关问题
windows 获取显示器真实分辨率 EnumDisplaySettings
`EnumDisplaySettings` 函数可以用于获取指定显示器的真实分辨率。下面是示例代码:
```cpp
void GetRealResolution(HWND hWnd)
{
// 获取显示器设备上下文
HDC hdc = ::GetDC(hWnd);
// 获取显示器的物理宽度和高度
int widthMM = GetDeviceCaps(hdc, HORZSIZE);
int heightMM = GetDeviceCaps(hdc, VERTSIZE);
// 获取显示器的水平和垂直分辨率
int widthPixels = GetDeviceCaps(hdc, HORZRES);
int heightPixels = GetDeviceCaps(hdc, VERTRES);
// 计算真实分辨率
int realWidth = MulDiv(widthPixels, 254, widthMM);
int realHeight = MulDiv(heightPixels, 254, heightMM);
// 输出结果
CString str;
str.Format(_T("Real resolution: %dx%d"), realWidth, realHeight);
AfxMessageBox(str);
// 释放设备上下文
::ReleaseDC(hWnd, hdc);
}
```
其中,`GetDeviceCaps` 函数用于获取显示器的物理尺寸和像素分辨率。根据物理尺寸和像素分辨率的比例,可以计算出真实分辨率。注意,这里获取的是指定窗口所在的显示器的真实分辨率。如果要获取所有显示器的真实分辨率,需要遍历所有显示器并分别调用上述代码。
windows 获取显示器真实分辨率 MFC
可以使用以下代码获取显示器的真实分辨率:
```cpp
// 获取主显示器的真实分辨率
CRect rect;
SystemParametersInfo(SPI_GETWORKAREA, NULL, &rect, NULL);
int width = rect.Width();
int height = rect.Height();
// 获取所有显示器的真实分辨率
CRect desktopRect;
::GetDesktopWindow();
HMONITOR hMonitor = MonitorFromWindow(NULL, MONITOR_DEFAULTTOPRIMARY);
MONITORINFOEX monitorInfo = { sizeof(MONITORINFOEX) };
if (GetMonitorInfo(hMonitor, &monitorInfo)) {
desktopRect = monitorInfo.rcMonitor;
}
int width = desktopRect.Width();
int height = desktopRect.Height();
```
其中,`SystemParametersInfo` 函数用于获取主显示器的工作区大小,即不包括任务栏、窗口标题栏等占用屏幕空间的区域。`GetMonitorInfo` 函数用于获取指定显示器的信息,包括真实分辨率等。
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)