Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Switching primary monitor

299 views
Skip to first unread message

Ian

unread,
Apr 17, 2008, 8:04:39 AM4/17/08
to
I have been trying to use ChangeDisplaySettingsEx() to switch the
primary display device as per the post:

http://groups.google.com/group/microsoft.public.win32.programmer.gdi/msg/f298871db17f2c97

However, it doesn't not work. I'm running it on a Dell Inspiron
laptop with an ATI graphics chip, and running XP, and hoping it will
switch between the LCD screen and the external monitor. The first
call to ChangeDisplaySettingEx fails with DISP_CHANGE_BADMODE, 'The
graphics mode is not supported'.

Any ideas what might be causing it to fail? The essential part of the
code is:

EnumDisplaySettings(devName2, ENUM_REGISTRY_SETTINGS, &dm2);
dm2.dmFields = DM_POSITION;
dm2.dmPosition.x = 0;
dm2.dmPosition.y = 0;
retCode = ChangeDisplaySettingsEx(devName2, &dm2, NULL,
CDS_SET_PRIMARY |
CDS_UPDATEREGISTRY | CDS_NORESET, NULL);
ShowDisplayError("Error in dev2 change", retCode);

EnumDisplaySettings(devName1, ENUM_REGISTRY_SETTINGS, &dm1);
dm1.dmFields = DM_POSITION;
dm1.dmPosition.x = dm2.dmPelsWidth;
dm1.dmPosition.y = 0;
retCode = ChangeDisplaySettingsEx(devName1, &dm1, NULL,
CDS_UPDATEREGISTRY |
CDS_NORESET, NULL);
ShowDisplayError("Error in dev1 change", retCode);

retCode = ChangeDisplaySettings(NULL, 0);
ShowDisplayError("Error in settings change", retCode);

Thanks.

Ian.

David Lowndes

unread,
Apr 17, 2008, 5:23:32 PM4/17/08
to
>I have been trying to use ChangeDisplaySettingsEx() to switch the
>primary display device as per the post:
>
>http://groups.google.com/group/microsoft.public.win32.programmer.gdi/msg/f298871db17f2c97
>
>However, it doesn't not work. I'm running it on a Dell Inspiron
>laptop with an ATI graphics chip, and running XP, and hoping it will
>switch between the LCD screen and the external monitor.

Ian,

Does the standard Windows Control Panel display applet show this as
having 2 displays?

Have a look at VidRes (www.jddesign.co.uk) and see if it encounters
the same problem as your code does. It uses the same APIs and I can't
spot anything immediately wrong with the code you showed.

Dave

Message has been deleted

Ian

unread,
Apr 18, 2008, 6:18:30 AM4/18/08
to
> Does the standard Windows Control Panel display applet show this as
> having 2 displays?
>
> Have a look at VidRes (www.jddesign.co.uk) and see if it encounters
> the same problem as your code does. It uses the same APIs and I can't
> spot anything immediately wrong with the code you showed.

Dave,

Yes, there are two displays in the Control Panel applet.

Thanks for the tip on VidRes. The GUI gives the two displays as
options, but does not allow you to 'Make Primary' or 'Make Sole' the
second display (the buttons grey out). The VidRes readme says this
was added intentionally a few versions ago so that you can't make
'removable' monitors the primary display. I suppose this is to
prevent accidental switching, but it seems very restrictive. The
command line interface has the same restriction. I will see if I can
find out from them whether there's a workaround, and post back.

Thanks again Dave for the feedback.

Ian.

David Lowndes

unread,
Apr 18, 2008, 9:34:07 AM4/18/08
to
>Yes, there are two displays in the Control Panel applet.
>
>Thanks for the tip on VidRes. The GUI gives the two displays as
>options, but does not allow you to 'Make Primary' or 'Make Sole' the
>second display (the buttons grey out). The VidRes readme says this
>was added intentionally a few versions ago so that you can't make
>'removable' monitors the primary display.

Hi Ian,

I'll answer here for the benefit of anyone else reading (VidRes is one
of my projects).

I presume you're referring to this comment:

"Prevent removable displays (often the external connection on notebook
computers) from being the primary or sole monitor.", ... and does the
command line usage give you the error "The device is removable. It
can't be made the primary"?

I'm afraid the details of the particular circumstances leading to
those changes have long since left me, but I think someone contacted
me with a problem, and I vaguely recall checking it on my daughter's
laptop and getting the same results - it didn't work.

Subsequently I found this documentation of DISPLAY_DEVICE_REMOVABLE
for the DISPLAY_DEVICE structure, which says:

"The device is removable; it cannot be the primary display"

Dave

Ian

unread,
Apr 22, 2008, 4:48:57 AM4/22/08
to
> I'm afraid the details of the particular circumstances leading to
> those changes have long since left me, but I think someone contacted
> me with a problem, and I vaguely recall checking it on my daughter's
> laptop and getting the same results - it didn't work.
>
> Subsequently I found this documentation of DISPLAY_DEVICE_REMOVABLE
> for the DISPLAY_DEVICE structure, which says:
>
> "The device is removable; it cannot be the primary display"

Dave,

My laptop has the same flag set for the second device, so that would
explain the problem.

Thanks for your help.

Ian.

0 new messages