Link to home
Start Free TrialLog in
Avatar of lichtf
lichtf

asked on

Disabling the Extend your desktop to this monitor.

I am trying to disable the extended desktop from all the monitors except for the primary one.

I tried using EnumDisplayMonitors() with the function at the end of this message as the callback function.

This seems to move the location of the second display, but it doesn't disable the extended desktop.

Any help is greatly appreciated.  I can't believe that there isn't a windows API that can be used to do this.

BOOL CALLBACK MonitorEnumProc(HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcMonitor, LPARAM dwData )
{
  MONITORINFOEX mi;
  DEVMODE dm;
  LONG lStatus;

  mi.cbSize = sizeof(MONITORINFOEX);
  if(GetMonitorInfo(hMonitor, (LPMONITORINFO)&mi))
  {

    if(!(mi.dwFlags & MONITORINFOF_PRIMARY))
    {
      dm.dmSize = sizeof(DEVMODE);
      dm.dmDriverExtra = 0;
      dm.dmFields = DM_POSITION;
      dm.dmPelsHeight = dm.dmPelsWidth = 0;
      lStatus = ChangeDisplaySettingsEx(mi.szDevice, &dm, NULL, CDS_TEST, NULL);
      if(lStatus == DISP_CHANGE_SUCCESSFUL)
      {
        lStatus = ChangeDisplaySettingsEx(mi.szDevice, &dm, NULL, /*CDS_RESET*/CDS_UPDATEREGISTRY, 0);
      }
    }
  }

  return TRUE;
}
SOLUTION
Avatar of jkr
jkr
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of lichtf
lichtf

ASKER

jkr,

Thanks for your response.  Adding those two changes you mentioned sort of fixed my problem.  After running the code the extended desktop is disabled in the settings tab of the display properties(and I can't move my mouse off the primary monitor), but the second monitor shows all sorts of corrupted images (it appears to be a corrupted and oddly scaled version of what my primary monitor is displaying).  When I disable the desktop extension through the UI on the settings tab of the display properties page the second monitor goes black and doesn't display anything, as would be expected.

Does anyone know of any thing else that I might need to do to stop this corrupted data from going to the monitor?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of lichtf

ASKER

Thanks for you help Dan.

I realized that I have the exact same video card as the person in the thread that you linked to.  I tried the code with using two video cards, (instead of the radeon 8500 with dual outputs), and the code worked correctly.  There must be something with this card, or maybe with all cards that have dual outputs.  I'm not sure how windows detaches the monitor though, since when I use the windows UI and disable the extended desktop everything works fine with the radeon 8500.

I think I might just have to live with this card and this problem, at least for now since I've spent all the time I can on this issue.

Thanks again for your help.