Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

PRB: You Must Restart the Computer After You Use the ChangeDisplaySettingsEx Function to Attach a Secondary Monitor


Symptoms

On a Windows 2000 or Windows XP-based system, when you use the ChangeDisplaySettingsEx function to attach a secondary monitor to the desktop, the change does not take effect until you restart the computer.

↑ Back to the top


Cause

This problem occurs on multiple-monitor portable computers that use a dual-view implementation, with which you can use both an external CRT display and the built-in LCD display.

↑ Back to the top


Resolution

To resolve this problem, call ChangeDisplaySettings(NULL, 0) to update the desktop immediately after you call ChangeDisplaySettingsEx to attach the secondary monitor to the desktop. This causes the system to use the settings in the registry and resets each of the display devices.

↑ Back to the top


More Information

The following code attaches the first secondary device that it finds to the desktop without requiring you to restart the computer:

BOOL AddUnattachedDisplayDeviceToDesktop()
{
DWORD DispNum = 0;
DISPLAY_DEVICE DisplayDevice;
DEVMODE defaultMode;
HDC hdc;
int nWidth;
BOOL bFoundSecondary = FALSE;

hdc = GetDC(0);
nWidth = GetDeviceCaps(hdc,HORZRES);
ReleaseDC(0,hdc);

// Initialize DisplayDevice.
ZeroMemory(&DisplayDevice, sizeof(DisplayDevice));
DisplayDevice.cb = sizeof(DisplayDevice);

// Get display devices.
while ((EnumDisplayDevices(NULL, DispNum, &DisplayDevice, 0)) &&
(bFoundSecondary == FALSE))
{
ZeroMemory(&defaultMode, sizeof(DEVMODE));
defaultMode.dmSize = sizeof(DEVMODE);
if (!EnumDisplaySettings((LPSTR)DisplayDevice.DeviceName,
ENUM_REGISTRY_SETTINGS, &defaultMode))
return FALSE; // Store default failed

if (!(DisplayDevice.StateFlags & DISPLAY_DEVICE_PRIMARY_DEVICE))
{
//Found the first secondary device.
bFoundSecondary = TRUE;
defaultMode.dmPosition.x += nWidth;
defaultMode.dmFields = DM_POSITION;
ChangeDisplaySettingsEx((LPSTR)DisplayDevice.DeviceName,
&defaultMode, NULL, CDS_NORESET|CDS_UPDATEREGISTRY, NULL);

// A second call to ChangeDisplaySettings updates the monitor.
ChangeDisplaySettings(NULL, 0);
}

// Reinitialize DisplayDevice.
ZeroMemory(&DisplayDevice, sizeof(DisplayDevice));
DisplayDevice.cb = sizeof(DisplayDevice);
DispNum++;
} // End while the display devices.
return TRUE;
}

↑ Back to the top


Keywords: kbgdi64swept, kbdswgdi2003swept, kbdsupport, kbgdi, kbmultimon, kbprb, kbbillprodsweep, kb

↑ Back to the top

Article Info
Article ID : 308216
Revision : 1
Created on : 1/7/2017
Published on : 6/19/2014
Exists online : False
Views : 790