WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

DllCall Information

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Change Screen Resolution to standard size


UPDATE: UDF's to handle Screen Resolution: http://techsupt.winbatch.com/webcgi/webbatch.exe?techsupt/nftechsupt.web+WinBatch/Display+Change~Screen~Resolution.txt


;This program simply checks to see if the screen size is 1024x768.
;If not it checks to see if the display can use that setting. If so
;changes the display to 1024x768. This code was boiled down from
;Marty's suggested code. 


;Change Screen Res Small version.wil



UserDll=StrCat(DirWindows(1),"USER32.DLL")
TDEVICEMODEA=BinaryAlloc(156) ;DEVMODE structure. Size of TDEVICEMODEA record: 156 Bytes
offdmFields = 40 ;Location = 40, Size is 4 by windows default
offdmPelsWidth = 108 ;Location = 108, Size is 4 by windows default
offdmPelsHeight = 112 ;Location = 112, Size is 4 by windows default
ModeIndex = -1 ;Value of -1 returns current settings
AllSize = '' ;List of all screen sizes supported

While 1
ReturnValue=DllCall(UserDll,long:"EnumDisplaySettingsA",lpnull,long:ModeIndex,lpbinary:TDEVICEMODEA)
If ReturnValue == 0 Then Break
dmPelsWidth = BinaryPeek4(TDEVICEMODEA,offdmPelsWidth) ;Horizontal resolution
dmPelsHeight = BinaryPeek4(TDEVICEMODEA,offdmPelsHeight) ;Vertical resolution
If ModeIndex <0 Then OldSetting=StrCat(dmPelsWidth,"x",dmPelsHeight) ;-1 = current settings found
Line=StrCat(dmPelsWidth,"x",dmPelsHeight);Format for list possible display settings
If (ModeIndex >= 0 && !StrIndex(AllSize , Line, '1', @FWDSCAN)) Then AllSize =StrCat(AllSize ,Line,"|")
ModeIndex=ModeIndex + 1 ;Index of 0 or greater returns supported modes
EndWhile

NewSetting = "1024x768"
If StrIndex(AllSize , NewSetting, '1', @FWDSCAN) Then ;Check if NewSetting size is supported
dmPelsWidth = ItemExtract(1,NewSetting,"x")
dmPelsHeight = ItemExtract(2,NewSetting,"x")
BinaryPoke4 (TDEVICEMODEA,offdmPelsWidth ,dmPelsWidth) 
BinaryPoke4 (TDEVICEMODEA,offdmPelsHeight ,dmPelsHeight) 
DM_PELSWIDTH = 524288 ; 0x80000
DM_PELSHEIGHT = 1048576 ; 0x100000
dmFields = (DM_PELSWIDTH | DM_PELSHEIGHT)
BinaryPoke4 (TDEVICEMODEA,offdmFields,dmFields)
ChangeMode = 1 ;Dll setting: Change and update registry
ReturnValue = DllCall(UserDll,long:"ChangeDisplaySettingsA",lpbinary:TDEVICEMODEA,long:ChangeMode)
Else
Message('Change Screen Size', 'Screen size %NewSetting% is not available on this machine.')
Endif
Exit 

Article ID:   W15927
File Created: 2014:07:18:09:50:36
Last Updated: 2014:07:18:09:50:36