获取显示器的缩放大小,使用C++实现完整demo
时间: 2024-02-23 16:01:04 浏览: 33
以下是使用C++实现获取显示器缩放大小的完整demo:
```cpp
#include <Windows.h>
#include <iostream>
int main()
{
// 获取主显示器的句柄
HMONITOR hMonitor = MonitorFromPoint(POINT{ 0, 0 }, MONITOR_DEFAULTTOPRIMARY);
// 获取主显示器的缩放大小
DEVICE_SCALE_FACTOR scale = SCALE_100_PERCENT;
HRESULT hr = GetScaleFactorForMonitor(hMonitor, &scale);
if (hr == S_OK)
{
std::cout << "Main monitor scale factor: " << scale << std::endl;
}
else
{
std::cerr << "Failed to get main monitor scale factor!" << std::endl;
}
return 0;
}
```
该程序使用了 Windows API 中的 `GetScaleFactorForMonitor` 函数来获取主显示器的缩放大小。`GetScaleFactorForMonitor` 函数需要传入显示器的句柄,并返回缩放大小,如果获取失败则返回错误码。在上面的示例中,使用 `MonitorFromPoint` 函数获取主显示器的句柄,并在获取缩放大小后输出结果。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.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)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)