Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Disabling the Extend your desktop to this monitor.

Posted on 2004-08-27
5
Medium Priority
?
1,395 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 400 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 1600 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 1600 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
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.
Suggested Courses

972 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