在C++

发布于 2025-01-25 00:58:43 字数 1353 浏览 3 评论 0 原文

我是为我的公司而言,我们的多个用户对计算机的了解很少。我们有多个带码头和外部监视器的车站。因此,用户搬到其他站时会遇到显示问题。监视大小,重复或更改频率。

我使此易于使用一键单击的工具在控制台C ++ EXE中调整其显示器大小。我遇到的问题是确定显示是笔记本电脑显示还是外部监视器。这很重要,因为我们所有的外部监视器都是1920 x 1080,但我们的一些笔记本电脑是1920 x 1200。

main.cpp:

#include <Windows.h>
#include <string>
#include <iostream>
int main()
{

    DEVMODE devmode;
    
    SetDisplayConfig(0, NULL, 0, NULL, SDC_TOPOLOGY_EXTEND | SDC_APPLY);
    

    //long result = ChangeDisplaySettings(&devmode, 0);

    DISPLAY_DEVICE displayDevice;
    displayDevice.cb = sizeof(displayDevice);
    int deviceIndex = 0;
    while (EnumDisplayDevices(0, deviceIndex, &displayDevice, 0))
    {
        std::wstring deviceName = displayDevice.DeviceName;
        int monitorIndex = 0;

        while (EnumDisplayDevices(deviceName.c_str(), monitorIndex, &displayDevice, 0))
        {            
            devmode.dmPelsWidth = 1920;
            devmode.dmPelsHeight = 1080;
            devmode.dmDisplayFrequency = 60;
            devmode.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT | DM_DISPLAYFREQUENCY;
            devmode.dmSize = sizeof(DEVMODE);

            long result = ChangeDisplaySettingsEx(deviceName.c_str(), &devmode, NULL, NULL, 0);
            ++monitorIndex;
        }
        ++deviceIndex;
    }
    return 0;
}

I'm IT for my company and multiple of our user know very little of computers. We have multiple drop-in stations with docks and external monitors. So users experience display issues when moving to a different station. Monitors resize, duplicate or change frequencies.

I made this easy to use one click tool to resize their monitors in a console C++ exe. The issue I run into is identifying whether the display is a laptop display or an external monitor. This is important because all of our external monitors are 1920 x 1080 but some of our laptops are 1920 x 1200.

main.cpp:

#include <Windows.h>
#include <string>
#include <iostream>
int main()
{

    DEVMODE devmode;
    
    SetDisplayConfig(0, NULL, 0, NULL, SDC_TOPOLOGY_EXTEND | SDC_APPLY);
    

    //long result = ChangeDisplaySettings(&devmode, 0);

    DISPLAY_DEVICE displayDevice;
    displayDevice.cb = sizeof(displayDevice);
    int deviceIndex = 0;
    while (EnumDisplayDevices(0, deviceIndex, &displayDevice, 0))
    {
        std::wstring deviceName = displayDevice.DeviceName;
        int monitorIndex = 0;

        while (EnumDisplayDevices(deviceName.c_str(), monitorIndex, &displayDevice, 0))
        {            
            devmode.dmPelsWidth = 1920;
            devmode.dmPelsHeight = 1080;
            devmode.dmDisplayFrequency = 60;
            devmode.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT | DM_DISPLAYFREQUENCY;
            devmode.dmSize = sizeof(DEVMODE);

            long result = ChangeDisplaySettingsEx(deviceName.c_str(), &devmode, NULL, NULL, 0);
            ++monitorIndex;
        }
        ++deviceIndex;
    }
    return 0;
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

小耗子 2025-02-01 00:58:43

也许您正在寻找 display_device_removable flag在 displayDevice.stateflags 字段中?

含义
display_device_remodable 该设备可移动;它不能是主要显示。

Perhaps you are looking for the DISPLAY_DEVICE_REMOVABLE flag in the displayDevice.StateFlags field?

Value Meaning
DISPLAY_DEVICE_REMOVABLE The device is removable; it cannot be the primary display.

https://learn.microsoft.com/en-us/windows/win32/api/wingdi/ns-wingdi-display_devicea

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文