title: Enable display programmatically
body: <p>I am trying to enable a secondary monitor in C++. What I have seems to try and change the display settings but nothing really happens, can anyone tell me where I am going wrong? </p>
  
  <pre><code>    std::wstring devName( L"Intel(R) HD Graphics Family" );
      std::wstring dispName( L"\\\\.\\DISPLAY3" );
  
      DISPLAY_DEVICE theDisplay;
      theDisplay.cb = sizeof(theDisplay);
      DWORD dev = 0;
  
      while(EnumDisplayDevices(0, dev, &amp;theDisplay, 0))
      {
          if (devName.compare(theDisplay.DeviceString) == 0 &amp;&amp; dispName.compare(theDisplay.DeviceName) == 0)
          {
              // found display adapter we're looking for
              if (theDisplay.StateFlags &amp; DISPLAY_DEVICE_ATTACHED_TO_DESKTOP)
              {
                  // Display is part of desktop, turn al other monitors off
                  cout &lt;&lt; "Display is part of desktop\n";
              }
              else
              {
                  // Display is off, turn it on
                  DEVMODE dm;
  
                  memset(&amp;dm,0,sizeof(DEVMODE));
                  dm.dmSize = sizeof (DEVMODE);
                  dm.dmFields = DM_POSITION;
                  dm.dmPosition.x = 3361;
                  dm.dmPosition.y = 0;
                  dm.dmPelsWidth = 1920;
                  dm.dmPelsHeight = 1080;
  
                  LONG ret = ChangeDisplaySettingsEx (theDisplay.DeviceName, &amp;dm, NULL, CDS_UPDATEREGISTRY, NULL);
                  if (ret != DISP_CHANGE_SUCCESSFUL)
                  {
                      cout &lt;&lt; "failed";
                  }
              }
          }
          dev++;
      }
  
      system ("pause");
      return 0;
  </code></pre>