有ac/c++吗?用于在 XP 的双视图或克隆桌面设置之间进行更改的多显示器库?

发布于 2024-08-04 16:01:08 字数 155 浏览 6 评论 0 原文

我正在编写一个应用程序,在双视图或克隆 Windows XP 桌面之间自动切换会很有帮助。该应用程序使用一个小的 wxWidgets 窗口作为 GUI。如果 GUI 中有一个可以轻松在双视图和克隆视图之间切换的按钮,那就太好了。

是否有 ac/c++ 库可以访问控制双视图或克隆?

I am writing an application where it would be helpful to automatically switch between having Windows XP's desktop in dualview or cloned. The application uses a small wxWidgets window for the GUI. It would be nice to have a button within the GUI that could easily switch between dualview and cloned.

Is there a c/c++ library that gives access to controlling dualview or cloned?

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

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

发布评论

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

评论(2

温折酒 2024-08-11 16:01:08

查看这个脚本,据我所知,它应该启用或禁用多视图。虽然它是用脚本语言编写的,但它确实利用了普通的 WinAPI 函数,因此您应该能够通过查看它们来了解发生了什么。

据我所知,禁用第二个显示器似乎是通过调用 ChangeDisplaySettingsEx 在第二个显示器上,并提供宽度、高度、颜色深度和刷新率 0。要重新启用它,人们可能会使用有效参数第二次调用 ChangeDisplaySettingsEx。

无论如何,最好尝试一下该脚本(解释器在主页上免费提供),看看它是否实现了您正在寻找的功能(请注意,该脚本是针对两个特定监视器进行硬编码的,您将不得不替换它们与您的显示器的名称以使其正常工作)。

Check out this script which, as far as I can tell, is supposed to enable or disable multiview. While it is written in a scripting language, it does leverage normal WinAPI functions, so you should be able to find out what is happening by looking at them.

As far as I can tell, it appears that disabling a second monitor is done by calling ChangeDisplaySettingsEx on the second monitor and providing a width, height, colour depth and refresh rate of 0. To reenable it, one would call ChangeDisplaySettingsEx a second time with valid parameters presumably.

Anyway it would probably be best to try the script (the interpreter is available for free on the homepage) and see if it achieves the functionality you're looking for (note that the script is hardcoded for two particular monitors, you will have to replace them with the names of your monitors to get it to work).

千纸鹤 2024-08-11 16:01:08

下面的代码可以工作。它不保留显示器分辨率。

void AppFrame::OnButtonModify(wxCommandEvent& event)
{
  static bool bSwitch = false;

  if (bSwitch)
  {
    ExtendExternalDisplay();
  }
  else
  {
    CloneExternalDisplay();
  }
  bSwitch = !bSwitch;
}

void AppFrame::ExtendExternalDisplay() 
{

  int   nModeSwitch = NULL;
  DEVMODE dmPrimary, dmSecondary, dmThird, savedmSecondary;

#define szPrimaryDisplay TEXT( "\\\\.\\DISPLAY1" )
#define szSecondaryDisplay TEXT( "\\\\.\\DISPLAY2" )
#define szThirdDisplay TEXT( "\\\\.\\DISPLAY3" )

  ZeroMemory( &dmPrimary, sizeof(dmPrimary) );
  dmPrimary.dmSize = sizeof(dmPrimary);
  ZeroMemory( &dmSecondary, sizeof(dmSecondary) );
  dmSecondary.dmSize = sizeof(dmSecondary);
  ZeroMemory( &dmThird, sizeof(dmThird) );
  dmThird.dmSize = sizeof(dmThird);
  ZeroMemory( &dmThird, sizeof(dmThird) );
  dmThird.dmSize = sizeof(dmThird);

  BOOL result;
  HDC handle;
  DWORD iDevNum = 0;
  DWORD dwFlags = 0;
  DISPLAY_DEVICE lpDisplayDevice, lpDisplayDeviceOne, lpDisplayDeviceTwo;    
  ZeroMemory(&lpDisplayDevice, sizeof(lpDisplayDevice));       
  ZeroMemory(&lpDisplayDeviceOne, sizeof(lpDisplayDeviceOne));
  ZeroMemory(&lpDisplayDeviceTwo, sizeof(lpDisplayDeviceTwo));
  lpDisplayDevice.cb = sizeof(lpDisplayDevice);
  lpDisplayDeviceOne.cb = sizeof(lpDisplayDeviceOne);
  lpDisplayDeviceTwo.cb = sizeof(lpDisplayDeviceTwo);

  // All this does is confirm the number of display devices the graphics board is capable of handling
  while(EnumDisplayDevices(NULL, iDevNum, &lpDisplayDevice, dwFlags))
  {
    if (iDevNum == 0)
    {
      lpDisplayDeviceOne = lpDisplayDevice;
      TRACE("DeviceName:   '%s'\n", lpDisplayDeviceOne.DeviceName);
      TRACE("DeviceString: '%s'\n", lpDisplayDeviceOne.DeviceString);
      TRACE("Flags:        %08X %s%s\n", lpDisplayDeviceOne.StateFlags,((lpDisplayDeviceOne.StateFlags & DISPLAY_DEVICE_ATTACHED_TO_DESKTOP) ? "Desktop " : ""), ((lpDisplayDeviceOne.StateFlags & DISPLAY_DEVICE_PRIMARY_DEVICE) ? "Primary" : "")); 
    }

    if (iDevNum == 1)
    {
      lpDisplayDeviceTwo = lpDisplayDevice;
      TRACE("DeviceName:   '%s'\n", lpDisplayDeviceTwo.DeviceName);
      TRACE("DeviceString: '%s'\n", lpDisplayDeviceTwo.DeviceString);
      TRACE("Flags:        %08X %s%s\n", lpDisplayDeviceTwo.StateFlags,((lpDisplayDeviceTwo.StateFlags & DISPLAY_DEVICE_ATTACHED_TO_DESKTOP) ? "Desktop " : ""), ((lpDisplayDeviceTwo.StateFlags & DISPLAY_DEVICE_PRIMARY_DEVICE) ? "Primary" : "")); 
    }

    iDevNum ++;
  }  

  // load DISPLAY1 monitor information // ENUM_CURRENT_SETTINGS     
  if (!EnumDisplaySettings(szPrimaryDisplay, ENUM_REGISTRY_SETTINGS, (DEVMODE*)&dmPrimary))
  {
    TRACE("EnumDisplaySettings unable to enumerate primary display\n");
    return;
  }

  if (!EnumDisplaySettings(szSecondaryDisplay, ENUM_REGISTRY_SETTINGS, (DEVMODE*)&dmSecondary))
    TRACE("EnumDisplaySettings unable to enumerate secondary display display\n");

  // these don't enumerate in clone mode
  if (!EnumDisplaySettings(szSecondaryDisplay, ENUM_CURRENT_SETTINGS, (DEVMODE*)&savedmSecondary))  
    TRACE("EnumDisplaySettings unable to enumerate secondary display using ENUM_CURRENT_SETTINGS settings\n");

  // disable a display, doesn't work
  //    nModeSwitch = ChangeDisplaySettingsEx (szSecondaryDisplay, NULL, NULL, NULL, NULL);
  //    CDdx::ErrorDisplayDevice(nModeSwitch);                      // test and TRACE result

  dmPrimary.dmFields = DM_POSITION;
  dmPrimary.dmPosition.x = 0;           // set DISPLAY1 as the primary display
  dmPrimary.dmPosition.y = 0;           // set DISPLAY1 as the primary display

  // set DISPLAY1 as primary display (dmPosition.x = 0)
  nModeSwitch = ChangeDisplaySettingsEx (szPrimaryDisplay, (DEVMODE*)&dmPrimary, NULL, (CDS_UPDATEREGISTRY | CDS_NORESET), NULL);
//  CDdx::ErrorDisplayDevice(nModeSwitch);                      // test and TRACE result

  // despite the other lines of code this next line is neccesary to wake the video projector
  dmSecondary = dmPrimary;

  dmSecondary.dmFields = DM_POSITION | DM_PELSWIDTH | DM_PELSHEIGHT;
  dmSecondary.dmPosition.x = dmPrimary.dmPelsWidth + 1;
  dmSecondary.dmPosition.y = 0;
  dmSecondary.dmPelsWidth = dmPrimary.dmPelsWidth;          // resize the primary display to match the secondary display
  dmSecondary.dmPelsHeight = dmPrimary.dmPelsHeight;            // resize the primary display to match the secondary display    

  nModeSwitch = ChangeDisplaySettingsEx (szSecondaryDisplay, (DEVMODE*)&dmSecondary, NULL, (CDS_UPDATEREGISTRY | CDS_NORESET), NULL);
//  CDdx::ErrorDisplayDevice(nModeSwitch);                      // test and TRACE result

  // load DISPLAY3 monitor information
  if (!EnumDisplaySettings(szThirdDisplay, ENUM_CURRENT_SETTINGS, (DEVMODE*)&dmThird))
  {
    TRACE("EnumDisplaySettings unable to enumerate third display display\n");
  }
  else
  {
    dmThird.dmPelsWidth = dmSecondary.dmPelsWidth;              // resize the primary display to match the secondary display
    dmThird.dmPelsHeight = dmSecondary.dmPelsHeight;            // resize the primary display to match the secondary display    
    dmThird.dmPosition.x = -dmThird.dmPelsWidth;                // set DISPLAY3 as the third display
    dmPrimary.dmPosition.y = 0;                                 // set DISPLAY1 as the third display

    // set DISPLAY3 as third display (-dmThird.dmPelsWidth)
    nModeSwitch = ChangeDisplaySettingsEx (szThirdDisplay, (DEVMODE*)&dmThird, NULL, (CDS_UPDATEREGISTRY | CDS_NORESET), NULL);
//    CDdx::ErrorDisplayDevice(nModeSwitch);                        // test and TRACE result
  }

  // really important line makes the whole thing happen
  nModeSwitch = ChangeDisplaySettingsEx (NULL, NULL, NULL, 0, NULL);
//  CDdx::ErrorDisplayDevice(nModeSwitch);                          // test and TRACE result

}

void AppFrame::CloneExternalDisplay()
{
  int   nModeSwitch = NULL;
  DEVMODE dmPrimary, dmSecondary, dmThird;
#define szPrimaryDisplay TEXT( "\\\\.\\DISPLAY1" )
#define szSecondaryDisplay TEXT( "\\\\.\\DISPLAY2" )
#define szThirdDisplay TEXT( "\\\\.\\DISPLAY3" )

  ZeroMemory( &dmPrimary, sizeof(dmPrimary) );
  dmPrimary.dmSize = sizeof(dmPrimary);
  ZeroMemory( &dmSecondary, sizeof(dmSecondary) );
  dmSecondary.dmSize = sizeof(dmSecondary);
  ZeroMemory( &dmThird, sizeof(dmThird) );

  // load DISPLAY1 monitor information
  if (!EnumDisplaySettings(szPrimaryDisplay, ENUM_CURRENT_SETTINGS, (DEVMODE*)&dmPrimary))
  {
    TRACE("EnumDisplaySettings unable to enumerate primary display\n");
    return;
  }

  if (!EnumDisplaySettingsEx(szSecondaryDisplay, ENUM_REGISTRY_SETTINGS, (DEVMODE*)&dmSecondary, 0))
    TRACE("EnumDisplaySettings unable to enumerate secondary display display\n");

  dmPrimary.dmFields = DM_POSITION;
  dmPrimary.dmPosition.x = 0;                                   // set DISPLAY1 as the primary display
  dmPrimary.dmPosition.y = 0;                                   // set DISPLAY1 as the primary display

  // set DISPLAY1 as primary display (dmPosition.x = 0)
  nModeSwitch = ChangeDisplaySettingsEx (szPrimaryDisplay, (DEVMODE*)&dmPrimary, NULL, (CDS_UPDATEREGISTRY | CDS_NORESET), NULL);
//  CDdx::ErrorDisplayDevice(nModeSwitch);                      // test and TRACE result

  // this should disable display
  dmSecondary.dmFields = DM_PELSWIDTH|DM_PELSHEIGHT;
  dmSecondary.dmPelsWidth = 0; //dmPrimary.dmPelsWidth;         // resize the primary display to match the secondary display
  dmSecondary.dmPelsHeight = 0;//dmPrimary.dmPelsHeight;            // resize the primary display to match the secondary display    

  // this should clone the display
  dmSecondary.dmFields |= DM_POSITION;
  dmSecondary.dmPosition.x = 0;         // set DISPLAY1 as the primary display
  dmSecondary.dmPosition.y = 0;         // set DISPLAY1 as the primary display

  nModeSwitch = ChangeDisplaySettingsEx (szSecondaryDisplay, (DEVMODE*)&dmSecondary, NULL, (CDS_UPDATEREGISTRY | CDS_NORESET), NULL);
//  CDdx::ErrorDisplayDevice(nModeSwitch);                      // test and TRACE result

  nModeSwitch = ChangeDisplaySettingsEx (NULL, NULL, NULL, 0, NULL);                                    // set DISPLAY1 as the primary display
//  CDdx::ErrorDisplayDevice(nModeSwitch);                  // test and TRACE result    

}

The following code sort of works. It doesn't keep the monitor resolution.

void AppFrame::OnButtonModify(wxCommandEvent& event)
{
  static bool bSwitch = false;

  if (bSwitch)
  {
    ExtendExternalDisplay();
  }
  else
  {
    CloneExternalDisplay();
  }
  bSwitch = !bSwitch;
}

void AppFrame::ExtendExternalDisplay() 
{

  int   nModeSwitch = NULL;
  DEVMODE dmPrimary, dmSecondary, dmThird, savedmSecondary;

#define szPrimaryDisplay TEXT( "\\\\.\\DISPLAY1" )
#define szSecondaryDisplay TEXT( "\\\\.\\DISPLAY2" )
#define szThirdDisplay TEXT( "\\\\.\\DISPLAY3" )

  ZeroMemory( &dmPrimary, sizeof(dmPrimary) );
  dmPrimary.dmSize = sizeof(dmPrimary);
  ZeroMemory( &dmSecondary, sizeof(dmSecondary) );
  dmSecondary.dmSize = sizeof(dmSecondary);
  ZeroMemory( &dmThird, sizeof(dmThird) );
  dmThird.dmSize = sizeof(dmThird);
  ZeroMemory( &dmThird, sizeof(dmThird) );
  dmThird.dmSize = sizeof(dmThird);

  BOOL result;
  HDC handle;
  DWORD iDevNum = 0;
  DWORD dwFlags = 0;
  DISPLAY_DEVICE lpDisplayDevice, lpDisplayDeviceOne, lpDisplayDeviceTwo;    
  ZeroMemory(&lpDisplayDevice, sizeof(lpDisplayDevice));       
  ZeroMemory(&lpDisplayDeviceOne, sizeof(lpDisplayDeviceOne));
  ZeroMemory(&lpDisplayDeviceTwo, sizeof(lpDisplayDeviceTwo));
  lpDisplayDevice.cb = sizeof(lpDisplayDevice);
  lpDisplayDeviceOne.cb = sizeof(lpDisplayDeviceOne);
  lpDisplayDeviceTwo.cb = sizeof(lpDisplayDeviceTwo);

  // All this does is confirm the number of display devices the graphics board is capable of handling
  while(EnumDisplayDevices(NULL, iDevNum, &lpDisplayDevice, dwFlags))
  {
    if (iDevNum == 0)
    {
      lpDisplayDeviceOne = lpDisplayDevice;
      TRACE("DeviceName:   '%s'\n", lpDisplayDeviceOne.DeviceName);
      TRACE("DeviceString: '%s'\n", lpDisplayDeviceOne.DeviceString);
      TRACE("Flags:        %08X %s%s\n", lpDisplayDeviceOne.StateFlags,((lpDisplayDeviceOne.StateFlags & DISPLAY_DEVICE_ATTACHED_TO_DESKTOP) ? "Desktop " : ""), ((lpDisplayDeviceOne.StateFlags & DISPLAY_DEVICE_PRIMARY_DEVICE) ? "Primary" : "")); 
    }

    if (iDevNum == 1)
    {
      lpDisplayDeviceTwo = lpDisplayDevice;
      TRACE("DeviceName:   '%s'\n", lpDisplayDeviceTwo.DeviceName);
      TRACE("DeviceString: '%s'\n", lpDisplayDeviceTwo.DeviceString);
      TRACE("Flags:        %08X %s%s\n", lpDisplayDeviceTwo.StateFlags,((lpDisplayDeviceTwo.StateFlags & DISPLAY_DEVICE_ATTACHED_TO_DESKTOP) ? "Desktop " : ""), ((lpDisplayDeviceTwo.StateFlags & DISPLAY_DEVICE_PRIMARY_DEVICE) ? "Primary" : "")); 
    }

    iDevNum ++;
  }  

  // load DISPLAY1 monitor information // ENUM_CURRENT_SETTINGS     
  if (!EnumDisplaySettings(szPrimaryDisplay, ENUM_REGISTRY_SETTINGS, (DEVMODE*)&dmPrimary))
  {
    TRACE("EnumDisplaySettings unable to enumerate primary display\n");
    return;
  }

  if (!EnumDisplaySettings(szSecondaryDisplay, ENUM_REGISTRY_SETTINGS, (DEVMODE*)&dmSecondary))
    TRACE("EnumDisplaySettings unable to enumerate secondary display display\n");

  // these don't enumerate in clone mode
  if (!EnumDisplaySettings(szSecondaryDisplay, ENUM_CURRENT_SETTINGS, (DEVMODE*)&savedmSecondary))  
    TRACE("EnumDisplaySettings unable to enumerate secondary display using ENUM_CURRENT_SETTINGS settings\n");

  // disable a display, doesn't work
  //    nModeSwitch = ChangeDisplaySettingsEx (szSecondaryDisplay, NULL, NULL, NULL, NULL);
  //    CDdx::ErrorDisplayDevice(nModeSwitch);                      // test and TRACE result

  dmPrimary.dmFields = DM_POSITION;
  dmPrimary.dmPosition.x = 0;           // set DISPLAY1 as the primary display
  dmPrimary.dmPosition.y = 0;           // set DISPLAY1 as the primary display

  // set DISPLAY1 as primary display (dmPosition.x = 0)
  nModeSwitch = ChangeDisplaySettingsEx (szPrimaryDisplay, (DEVMODE*)&dmPrimary, NULL, (CDS_UPDATEREGISTRY | CDS_NORESET), NULL);
//  CDdx::ErrorDisplayDevice(nModeSwitch);                      // test and TRACE result

  // despite the other lines of code this next line is neccesary to wake the video projector
  dmSecondary = dmPrimary;

  dmSecondary.dmFields = DM_POSITION | DM_PELSWIDTH | DM_PELSHEIGHT;
  dmSecondary.dmPosition.x = dmPrimary.dmPelsWidth + 1;
  dmSecondary.dmPosition.y = 0;
  dmSecondary.dmPelsWidth = dmPrimary.dmPelsWidth;          // resize the primary display to match the secondary display
  dmSecondary.dmPelsHeight = dmPrimary.dmPelsHeight;            // resize the primary display to match the secondary display    

  nModeSwitch = ChangeDisplaySettingsEx (szSecondaryDisplay, (DEVMODE*)&dmSecondary, NULL, (CDS_UPDATEREGISTRY | CDS_NORESET), NULL);
//  CDdx::ErrorDisplayDevice(nModeSwitch);                      // test and TRACE result

  // load DISPLAY3 monitor information
  if (!EnumDisplaySettings(szThirdDisplay, ENUM_CURRENT_SETTINGS, (DEVMODE*)&dmThird))
  {
    TRACE("EnumDisplaySettings unable to enumerate third display display\n");
  }
  else
  {
    dmThird.dmPelsWidth = dmSecondary.dmPelsWidth;              // resize the primary display to match the secondary display
    dmThird.dmPelsHeight = dmSecondary.dmPelsHeight;            // resize the primary display to match the secondary display    
    dmThird.dmPosition.x = -dmThird.dmPelsWidth;                // set DISPLAY3 as the third display
    dmPrimary.dmPosition.y = 0;                                 // set DISPLAY1 as the third display

    // set DISPLAY3 as third display (-dmThird.dmPelsWidth)
    nModeSwitch = ChangeDisplaySettingsEx (szThirdDisplay, (DEVMODE*)&dmThird, NULL, (CDS_UPDATEREGISTRY | CDS_NORESET), NULL);
//    CDdx::ErrorDisplayDevice(nModeSwitch);                        // test and TRACE result
  }

  // really important line makes the whole thing happen
  nModeSwitch = ChangeDisplaySettingsEx (NULL, NULL, NULL, 0, NULL);
//  CDdx::ErrorDisplayDevice(nModeSwitch);                          // test and TRACE result

}

void AppFrame::CloneExternalDisplay()
{
  int   nModeSwitch = NULL;
  DEVMODE dmPrimary, dmSecondary, dmThird;
#define szPrimaryDisplay TEXT( "\\\\.\\DISPLAY1" )
#define szSecondaryDisplay TEXT( "\\\\.\\DISPLAY2" )
#define szThirdDisplay TEXT( "\\\\.\\DISPLAY3" )

  ZeroMemory( &dmPrimary, sizeof(dmPrimary) );
  dmPrimary.dmSize = sizeof(dmPrimary);
  ZeroMemory( &dmSecondary, sizeof(dmSecondary) );
  dmSecondary.dmSize = sizeof(dmSecondary);
  ZeroMemory( &dmThird, sizeof(dmThird) );

  // load DISPLAY1 monitor information
  if (!EnumDisplaySettings(szPrimaryDisplay, ENUM_CURRENT_SETTINGS, (DEVMODE*)&dmPrimary))
  {
    TRACE("EnumDisplaySettings unable to enumerate primary display\n");
    return;
  }

  if (!EnumDisplaySettingsEx(szSecondaryDisplay, ENUM_REGISTRY_SETTINGS, (DEVMODE*)&dmSecondary, 0))
    TRACE("EnumDisplaySettings unable to enumerate secondary display display\n");

  dmPrimary.dmFields = DM_POSITION;
  dmPrimary.dmPosition.x = 0;                                   // set DISPLAY1 as the primary display
  dmPrimary.dmPosition.y = 0;                                   // set DISPLAY1 as the primary display

  // set DISPLAY1 as primary display (dmPosition.x = 0)
  nModeSwitch = ChangeDisplaySettingsEx (szPrimaryDisplay, (DEVMODE*)&dmPrimary, NULL, (CDS_UPDATEREGISTRY | CDS_NORESET), NULL);
//  CDdx::ErrorDisplayDevice(nModeSwitch);                      // test and TRACE result

  // this should disable display
  dmSecondary.dmFields = DM_PELSWIDTH|DM_PELSHEIGHT;
  dmSecondary.dmPelsWidth = 0; //dmPrimary.dmPelsWidth;         // resize the primary display to match the secondary display
  dmSecondary.dmPelsHeight = 0;//dmPrimary.dmPelsHeight;            // resize the primary display to match the secondary display    

  // this should clone the display
  dmSecondary.dmFields |= DM_POSITION;
  dmSecondary.dmPosition.x = 0;         // set DISPLAY1 as the primary display
  dmSecondary.dmPosition.y = 0;         // set DISPLAY1 as the primary display

  nModeSwitch = ChangeDisplaySettingsEx (szSecondaryDisplay, (DEVMODE*)&dmSecondary, NULL, (CDS_UPDATEREGISTRY | CDS_NORESET), NULL);
//  CDdx::ErrorDisplayDevice(nModeSwitch);                      // test and TRACE result

  nModeSwitch = ChangeDisplaySettingsEx (NULL, NULL, NULL, 0, NULL);                                    // set DISPLAY1 as the primary display
//  CDdx::ErrorDisplayDevice(nModeSwitch);                  // test and TRACE result    

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