Solved

Disabling the Extend your desktop to this monitor.

Posted on 2004-08-27
5
1,383 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

717 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