Dual screen display - expands the main display to the auxiliary display

- Apr 16, 2019-

Dual screen display - expands the main display to the auxiliary display


BOOL AddUnattachedDisplayDeviceToDesktop()
{
  DWORD DispNum = 0;
  DISPLAY_DEVICE DisplayDevice;
  DEVMODE defaultMode;
  HDC hdc;
  int nWidth;
  BOOL bFoundSecondary = FALSE;

  hdc = ::GetDC(0);
  nWidth = ::GetDeviceCaps(hdc,HORZRES);
  ::ReleaseDC(0,hdc);

  // Initialize DisplayDevice.
  ::ZeroMemory(&DisplayDevice, sizeof(DisplayDevice));
  DisplayDevice.cb = sizeof(DisplayDevice);

  // Get display devices.
  while ((::EnumDisplayDevices(NULL, DispNum, &DisplayDevice, 0)) &&
  (bFoundSecondary == FALSE))
  {  
  ::ZeroMemory(&defaultMode, sizeof(DEVMODE));
  defaultMode.dmSize = sizeof(DEVMODE);
  if (!::EnumDisplaySettings((LPSTR)DisplayDevice.DeviceName,
  ENUM_REGISTRY_SETTINGS, &defaultMode))
  return FALSE; // Store default failed

  if (!(DisplayDevice.StateFlags & DISPLAY_DEVICE_PRIMARY_DEVICE))
  {
  //Found the first secondary device.
  bFoundSecondary = TRUE;
  defaultMode.dmPosition.x += nWidth;
  defaultMode.dmFields = DM_POSITION;  
  ::ChangeDisplaySettingsEx((LPSTR)DisplayDevice.DeviceName,  
  &defaultMode, NULL, CDS_NORESET|CDS_UPDATEREGISTRY, NULL); 

  // A second call to ChangeDisplaySettings updates the monitor.
  ::ChangeDisplaySettings(NULL, 0);  
  } 

  // Reinitialize DisplayDevice.  
  ::ZeroMemory(&DisplayDevice, sizeof(DisplayDevice));
  DisplayDevice.cb = sizeof(DisplayDevice);
  DispNum++;
  } // End while the display devices.  
  return TRUE;
}
void CMonitorTestDlg::OnBnClickedButton5()
{
 DetachDisplay();
  //TODO: Add control notification handler code here}


Previous:To use multiple monitors for one virtual machine Next:The embodiment of Android one machine in the bank self-service terminal