Solved

Disabling the Extend your desktop to this monitor.

Posted on 2004-08-27
5
1,378 Views
Last Modified: 2007-12-19
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;
}
0
Comment
Question by:lichtf
  • 2
  • 2
5 Comments
 
LVL 86

Assisted Solution

by:jkr
jkr earned 100 total points
ID: 11917104
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
 

Author Comment

by:lichtf
ID: 11917518
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
 
LVL 49

Assisted Solution

by:DanRollins
DanRollins earned 400 total points
ID: 11926705
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
 
LVL 49

Accepted Solution

by:
DanRollins earned 400 total points
ID: 11926925
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
 

Author Comment

by:lichtf
ID: 11930584
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

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question