Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 781315
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T20:12:46+00:00 2026-05-14T20:12:46+00:00

I am writing an application where it would be helpful to automatically switch between

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T20:12:46+00:00Added an answer on May 14, 2026 at 8:12 pm

    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    
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing a C++ application and would like to request several data files
I am writing a Facebook application that would use a Postgres DB along with
I'm writing a Python+Qt4 application that would ideally need to pop up a window
I'm writing my Servlet application and would like to use the following static method
I'm writing a very Simple Chat Application and would like to know how to
In Android I am writing an application in which, I would like to capture
Im writing a server based application and i would like eclipse to be able
I am writing a little application in android which would have a server part
I'm writing a shopping car application and I would like visitors (i.e. people not
I am currently writing my truly first PHP Application and i would like to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.