hi gurus,
Iam using EnumDisplaySettings and ChangeDisplay Settings. The Trouble is that on some machines it actually restarts the machines( determined by the return value) but on some it just makes the screen blink and changes the settings. Can anybody help me in determining whether calling ExitWindows will actually restart computer , or just change settings without doing it!!!
Thanks
Cimperiali
September 11th, 2001, 01:46 AM
'from Api - guide (a free tool you can download from internet) here is an
'example of usage of ChangeDisplaySetting.
'KPD-Team 1999
'URL: http://www.allapi.net/
'E-Mail: KPDTeam@Allapi.net
'Hope this can help
option Explicit
Const WM_DISPLAYCHANGE = &H7E
Const HWND_BROADCAST = &HFFFF&
Const EWX_LOGOFF = 0
Const EWX_SHUTDOWN = 1
Const EWX_REBOOT = 2
Const EWX_FORCE = 4
Const CCDEVICENAME = 32
Const CCFORMNAME = 32
Const DM_BITSPERPEL = &H40000
Const DM_PELSWIDTH = &H80000
Const DM_PELSHEIGHT = &H100000
Const CDS_UPDATEREGISTRY = &H1
Const CDS_TEST = &H4
Const DISP_CHANGE_SUCCESSFUL = 0
Const DISP_CHANGE_RESTART = 1
Const BITSPIXEL = 12
private Type DEVMODE
dmDeviceName as string * CCDEVICENAME
dmSpecVersion as Integer
dmDriverVersion as Integer
dmSize as Integer
dmDriverExtra as Integer
dmFields as Long
dmOrientation as Integer
dmPaperSize as Integer
dmPaperLength as Integer
dmPaperWidth as Integer
dmScale as Integer
dmCopies as Integer
dmDefaultSource as Integer
dmPrintQuality as Integer
dmColor as Integer
dmDuplex as Integer
dmYResolution as Integer
dmTTOption as Integer
dmCollate as Integer
dmFormName as string * CCFORMNAME
dmUnusedPadding as Integer
dmBitsPerPel as Integer
dmPelsWidth as Long
dmPelsHeight as Long
dmDisplayFlags as Long
dmDisplayFrequency as Long
End Type
private Declare Function EnumDisplaySettings Lib "user32" Alias "EnumDisplaySettingsA" (byval lpszDeviceName as Long, byval iModeNum as Long, lpDevMode as Any) as Boolean
private Declare Function ChangeDisplaySettings Lib "user32" Alias "ChangeDisplaySettingsA" (lpDevMode as Any, byval dwFlags as Long) as Long
private Declare Function ExitWindowsEx Lib "user32" (byval uFlags as Long, byval dwReserved as Long) as Long
private Declare Function GetDeviceCaps Lib "gdi32" (byval hdc as Long, byval nIndex as Long) as Long
private Declare Function CreateDC Lib "gdi32" Alias "CreateDCA" (byval lpDriverName as string, byval lpDeviceName as string, byval lpOutput as string, byval lpInitData as Any) as Long
private Declare Function DeleteDC Lib "gdi32" (byval hdc as Long) as Long
private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (byval hwnd as Long, byval wMsg as Long, byval wParam as Long, lParam as Any) as Long
Dim OldX as Long, OldY as Long, nDC as Long
Sub ChangeRes(X as Long, Y as Long, Bits as Long)
Dim DevM as DEVMODE, ScInfo as Long, erg as Long, an as VbMsgBoxResult
'get the info into DevM
erg = EnumDisplaySettings(0&, 0&, DevM)
'This is what we're going to change
DevM.dmFields = DM_PELSWIDTH Or DM_PELSHEIGHT Or DM_BITSPERPEL
DevM.dmPelsWidth = X 'ScreenWidth
DevM.dmPelsHeight = Y 'ScreenHeight
DevM.dmBitsPerPel = Bits '(can be 8, 16, 24, 32 or even 4)
'Now change the display and check if possible
erg = ChangeDisplaySettings(DevM, CDS_TEST)
'Check if succesfull
Select Case erg&
Case DISP_CHANGE_RESTART
an = MsgBox("You've to reboot", vbYesNo + vbSystemModal, "Info")
If an = vbYes then
erg& = ExitWindowsEx(EWX_REBOOT, 0&)
End If
Case DISP_CHANGE_SUCCESSFUL
erg = ChangeDisplaySettings(DevM, CDS_UPDATEREGISTRY)
ScInfo = Y * 2 ^ 16 + X
'Notify all the windows of the screen resolution change
SendMessage HWND_BROADCAST, WM_DISPLAYCHANGE, byval Bits, byval ScInfo
MsgBox "Everything's ok", vbOKOnly + vbSystemModal, "It worked!"
Case else
MsgBox "Mode not supported", vbOKOnly + vbSystemModal, "error"
End Select
End Sub
private Sub Form_Load()
Dim nDC as Long
'retrieve the screen's resolution
OldX = Screen.Width / Screen.TwipsPerPixelX
OldY = Screen.Height / Screen.TwipsPerPixelY
'Create a device context, compatible with the screen
nDC = CreateDC("DISPLAY", vbNullString, vbNullString, byval 0&)
'Change the screen's resolution
ChangeRes 640, 480, GetDeviceCaps(nDC, BITSPIXEL)
End Sub
private Sub Form_Unload(Cancel as Integer)
'restore the screen resolution
ChangeRes OldX, OldY, GetDeviceCaps(nDC, BITSPIXEL)
'delete our device context
DeleteDC nDC
End Sub
Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood, TCartwright, Bruno Paris, Dr_Micahel
and all the other wonderful people who made and make Codeguru a great place.
Come back soon, you Gurus.
The Rater
Cimperiali
September 11th, 2001, 01:48 AM
'While ChangeDisplaySettingsEx requires win98 or later, Win2000 or later:
Const CCDEVICENAME = 32
Const CCFORMNAME = 32
Const DM_PELSWIDTH = &H80000
Const DM_PELSHEIGHT = &H100000
Const CDS_TEST = &H4
private Type DISPLAY_DEVICE
cb as Long
DeviceName as string * 32
DeviceString as string * 128
StateFlags as Long
DeviceID as string * 128
DeviceKey as string * 128
End Type
private Type DEVMODE
dmDeviceName as string * CCDEVICENAME
dmSpecVersion as Integer
dmDriverVersion as Integer
dmSize as Integer
dmDriverExtra as Integer
dmFields as Long
dmOrientation as Integer
dmPaperSize as Integer
dmPaperLength as Integer
dmPaperWidth as Integer
dmScale as Integer
dmCopies as Integer
dmDefaultSource as Integer
dmPrintQuality as Integer
dmColor as Integer
dmDuplex as Integer
dmYResolution as Integer
dmTTOption as Integer
dmCollate as Integer
dmFormName as string * CCFORMNAME
dmUnusedPadding as Integer
dmBitsPerPel as Integer
dmPelsWidth as Long
dmPelsHeight as Long
dmDisplayFlags as Long
dmDisplayFrequency as Long
dmICMMethod as Long 'NT 4.0
dmICMIntent as Long 'NT 4.0
dmMediaType as Long 'NT 4.0
dmDitherType as Long 'NT 4.0
dmReserved1 as Long 'NT 4.0
dmReserved2 as Long 'NT 4.0
dmPanningWidth as Long 'Win2000
dmPanningHeight as Long 'Win2000
End Type
private Declare Function ChangeDisplaySettingsEx Lib "user32" Alias "ChangeDisplaySettingsExA" (lpszDeviceName as Any, lpDevMode as Any, byval hWnd as Long, byval dwFlags as Long, lParam as Any) as Long
private Declare Function EnumDisplayDevices Lib "user32" Alias "EnumDisplayDevicesA" (Unused as Any, byval iDevNum as Long, lpDisplayDevice as DISPLAY_DEVICE, byval dwFlags as Long) as Boolean
Dim OldX as Long, OldY as Long, T as Long
private Sub Form_Load()
'KPD-Team 2000
'URL: http://www.allapi.net/
'E-Mail: KPDTeam@Allapi.net
Dim DD as DISPLAY_DEVICE, DevM as DEVMODE
DD.cb = len(DD)
OldX = Screen.Width / Screen.TwipsPerPixelX
OldY = Screen.Height / Screen.TwipsPerPixelY
'First retieve some display info
If EnumDisplayDevices(byval 0&, 0, DD, byval 0&) then
'and show it
me.AutoRedraw = true
me.print "Device string:" + Left$(DD.DeviceString, InStr(1, DD.DeviceString, Chr$(0)) - 1)
me.print "Device Name:" + Left$(DD.DeviceName, InStr(1, DD.DeviceName, Chr$(0)) - 1)
me.print "Device Key:" + Left$(DD.DeviceKey, InStr(1, DD.DeviceKey, Chr$(0)) - 1)
me.print "Device ID:" + Left$(DD.DeviceID, InStr(1, DD.DeviceID, Chr$(0)) - 1)
else
me.print "error while retrieving Display Information"
End If
DevM.dmSize = len(DevM)
'we want to change the horizontal and the vertical resolution
DevM.dmFields = DM_PELSWIDTH Or DM_PELSHEIGHT
DevM.dmPelsWidth = 640
DevM.dmPelsHeight = 480
'change the display settings
Call ChangeDisplaySettingsEx(byval 0&, DevM, byval 0&, CDS_TEST, byval 0&)
T = Timer
Do: DoEvents: Loop Until Timer > T + 5
DevM.dmPelsWidth = OldX
DevM.dmPelsHeight = OldY
'change the display settings back to the old settings
Call ChangeDisplaySettingsEx(byval 0&, DevM, byval 0&, CDS_TEST, byval 0&)
End Sub
Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood, TCartwright, Bruno Paris, Dr_Micahel
and all the other wonderful people who made and make Codeguru a great place.
Come back soon, you Gurus.
The Rater
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.