Microsoft KB Archive/306399

= PRB: ChangeDisplaySettingsEx Does Not Detach a Monitor from the Desktop =

Article ID: 306399

Article Last Modified on 4/4/2006

-

APPLIES TO

 Microsoft Platform Software Development Kit-January 2000 Edition, when used with:  Microsoft Windows 95

 Microsoft Windows 98 Standard Edition

 Microsoft Windows 98 Second Edition

 Microsoft Windows Millennium Edition</li></ul> </li></ul>

-

<div class="notice_section">

This article was previously published under Q306399

<div class="symptoms_section">

SYMPTOMS
When you call the ChangeDisplaySettingsEx function on the Microsoft Windows 95, Windows 98, Windows 98 Second Edition, or Windows Millennium Edition (Me) operating system to detach a secondary monitor from the desktop, the monitor will not immediately detach from the desktop. The ChangeDisplaySettingsEx call updates the registry settings so that the update is seen the next time the operating system is started. However, this problem does not occur on Windows NT and Windows 2000.

<div class="resolution_section">

RESOLUTION
DEVMODE must be set up properly and the property fields in the DEVMODE structure must be set to 0 before you call ChangeDisplaySettingsEx. In addition, in order for the display to be detached immediately without the need to restart the operating system, you must call ChangeDisplaySettingsEx twice.

<div class="moreinformation_section">

MORE INFORMATION
In the DEVMODE structure, you need to set the DEVMODE entries of the following flags to zero in the dmFields before calling ChangeDisplaySettingsEx:

DM_PELSWIDTH

DM_PELSHEIGHT

DM_BITSPERPEL

DM_POSITION

DM_DISPLAYFREQUENCY

DM_DISPLAYFLAGS

NOTE: You should save the current DEVMODE by calling EnumDisplaySettings so that you can attach the monitor back to the desktop by using another call to ChangeDisplaySettingsEx.

The following code demonstrates how to detach all secondary display devices from the desktop: void DetachDisplay {   BOOL            FoundSecondaryDisp = FALSE; DWORD          DispNum = 0; DISPLAY_DEVICE DisplayDevice; LONG           Result; TCHAR          szTemp[200]; int            i = 0; DEVMODE  defaultMode;

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

// get all display devices while (EnumDisplayDevices(NULL, DispNum, &DisplayDevice, 0)) {       ZeroMemory(&defaultMode, sizeof(DEVMODE)); defaultMode.dmSize = sizeof(DEVMODE); if ( !EnumDisplaySettings((LPSTR)DisplayDevice.DeviceName, ENUM_REGISTRY_SETTINGS, &defaultMode) ) OutputDebugString(&quot;Store default failed\n&quot;);

if ((DisplayDevice.StateFlags & DISPLAY_DEVICE_ATTACHED_TO_DESKTOP) &&           !(DisplayDevice.StateFlags & DISPLAY_DEVICE_PRIMARY_DEVICE)) {           DEVMODE    DevMode; ZeroMemory(&DevMode, sizeof(DevMode)); DevMode.dmSize = sizeof(DevMode); DevMode.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL | DM_POSITION | DM_DISPLAYFREQUENCY | DM_DISPLAYFLAGS ; Result = ChangeDisplaySettingsEx((LPSTR)DisplayDevice.DeviceName, &DevMode, NULL, CDS_UPDATEREGISTRY, NULL); Result = ChangeDisplaySettingsEx((LPSTR)DisplayDevice.DeviceName, &DevMode, NULL, CDS_UPDATEREGISTRY, NULL);

//The code below shows how to re-attach the secondary displays to the desktop

//ChangeDisplaySettingsEx((LPSTR)DisplayDevice.DeviceName, &defaultMode, NULL, CDS_UPDATEREGISTRY, NULL); //ChangeDisplaySettingsEx((LPSTR)DisplayDevice.DeviceName, &defaultMode, NULL, CDS_UPDATEREGISTRY, NULL); }

// Reinit DisplayDevice just to be extra clean

ZeroMemory(&DisplayDevice, sizeof(DisplayDevice)); DisplayDevice.cb = sizeof(DisplayDevice); DispNum++; } // end while for all display devices }

Keywords: kbmultimon kbgdi kbprb kbdswgdi2003swept KB306399

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.