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

Programmatically changing multiple monitor settings

1,081 views
Skip to first unread message

Steve Chin

unread,
Jun 16, 2003, 3:22:09 PM6/16/03
to
Does anyone know of any Windows SDK calls to
programmatically change monitor settings?

The settings I'm interested in are enabling and disabling
monitors and setting the primary monitor. You can change
these settings manually through the Display Properties
dialog box, but I'm looking to write a program that can
do this for me automatically.

Thanks,
Steve

Chris Hill

unread,
Jun 17, 2003, 12:10:13 AM6/17/03
to
On Mon, 16 Jun 2003 12:22:09 -0700, "Steve Chin" <sch...@hotmail.com>
wrote:

ChangeDisplaySettingsEx

Chris

Mike D Sutton

unread,
Jun 17, 2003, 10:26:46 AM6/17/03
to

Have a look at the ChangeDisplaySettingsEx() API call:
http://msdn.microsoft.com/library/en-us/gdi/devcons_3tfc.asp
Hope this helps,

Mike


- Microsoft Visual Basic MVP -
E-Mail: ED...@mvps.org
WWW: Http://www.mvps.org/EDais/


Steve Chin

unread,
Jun 20, 2003, 4:53:59 AM6/20/03
to
OK, figured out how to get it to work. Not only do you have to set the
CDS_SET_PRIMARY flag, but you also have to set the respective positions for
your new monitor setup so that the new primary monitor is at position 0,0.

Attached is source code that switches the primary monitor between two
monitor devices:
=======================================================================

int iDevNum = 0;
char devName1[32];
char devName2[32];
DISPLAY_DEVICE mDisplayDevice;

devName1[0] = devName2[0] = 0;
mDisplayDevice.cb = sizeof(DISPLAY_DEVICE);
while (EnumDisplayDevices(NULL, iDevNum, &mDisplayDevice, 0))
{
DWORD df = mDisplayDevice.StateFlags;
if (!(df & DISPLAY_DEVICE_MIRRORING_DRIVER))
{
if (df & DISPLAY_DEVICE_PRIMARY_DEVICE)
strcpy(devName1, mDisplayDevice.DeviceName);
else
strcpy(devName2, mDisplayDevice.DeviceName);
}
++iDevNum;
}

if (devName1[0] && devName2[0])
{
LONG result;
DEVMODE dm1, dm2;

memset(&dm1, 0, sizeof(DEVMODE));
memset(&dm2, 0, sizeof(DEVMODE));

EnumDisplaySettings(devName2, ENUM_REGISTRY_SETTINGS, &dm2);
dm2.dmFields = DM_POSITION;
dm2.dmPosition.x = 0;
dm2.dmPosition.y = 0;
ChangeDisplaySettingsEx(devName2, &dm2, NULL, CDS_SET_PRIMARY |
CDS_UPDATEREGISTRY | CDS_NORESET, NULL);

EnumDisplaySettings(devName1, ENUM_REGISTRY_SETTINGS, &dm1);
dm1.dmFields = DM_POSITION;
dm1.dmPosition.x = dm2.dmPelsWidth;
dm1.dmPosition.y = 0;
ChangeDisplaySettingsEx(devName1, &dm1, NULL, CDS_UPDATEREGISTRY |
CDS_NORESET, NULL);

ChangeDisplaySettings(NULL, 0);

0 new messages