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;
}
lichtfAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
DanRollinsConnect With a Mentor Commented:
I used this code and the secondary monitor went blank and was detached (according to the Control Panel).

If that does not work for you, I would suspect some sort of device driver anomalie.  Perhaps it could be solved by manually blanking the screen before (or after?) detaching it.

#define DM_POSITION         0x00000020L

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)) {
            DEVMODE    DevMode;
            ZeroMemory(&DevMode, sizeof(DevMode));
            DevMode.dmSize = sizeof(DevMode);
            DevMode.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL | DM_POSITION
                        | DM_DISPLAYFREQUENCY | DM_DISPLAYFLAGS ;
            lStatus= ChangeDisplaySettingsEx((LPSTR)mi.szDevice, &DevMode, NULL, CDS_UPDATEREGISTRY, NULL);
            lStatus= ChangeDisplaySettingsEx((LPSTR)mi.szDevice, &DevMode, NULL, CDS_UPDATEREGISTRY, NULL);
            }
      }

      return TRUE;
}
0
 
jkrConnect With a Mentor Commented:
First of all, you should set all members of the DEMODE struct to NULL, e.g.

     ZeroMemory(&dm, sizeof(DWVMODE);

Then, you should spcify that you want to alter the dmPels* fields:

     dm.dmSize = sizeof(DEVMODE);
     dm.dmDriverExtra = 0;
     dm.dmFields = DM_POSITION | DM_PELSWIDTH | DM_PELSHEIGHT;
     dm.dmPelsHeight = dm.dmPelsWidth = 0;
0
 
lichtfAuthor Commented:
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?
0
 
DanRollinsConnect With a Mentor Commented:
This google groups thread seems to be on point:

http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&safe=off&frame=right&th=481edeed868f2239&seekm=tZyVdboBCHA.2716%40cpmsftngxa08#link1

(including the "squashed" appearance of the second monitor.  I'll see if I can reproduce the problem...
-- Dan
0
 
lichtfAuthor Commented:
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.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.