Page 1 of 1

Code explanation

Posted: Thu Apr 18, 2019 3:07 pm
by Columbo
I was looking through some posts for some information on changing screen resolution and found this code.

Code: Select all


#DM_BITSPERPEL=$40000
#DM_PELSWIDTH=$80000
#DM_PELSHEIGHT=$100000

res.DEVMODE

res\dmSize=SizeOf(DEVMODE)
res\dmBitsPerPel=32
res\dmPelsWidth=800
res\dmPelsHeight=600
res\dmDisplayFrequency=60
res\dmFields=#DM_BITSPERPEL|#DM_PELSWIDTH|#DM_PELSHEIGHT 

ChangeDisplaySettings_(@res.DEVMODE,0)

The code however, does not include any comments. I would like to understand what is happening here. Is there anyone who can give me a line-by-line explanation as to what each line is doing?
I am assuming that the lines res\dmPelsWidth=800 and res\dmPelsHeight=600 is a screen resolution of 800 x 600 but what are the rest of the lines doing?

I don’t know what the line res\dmBitsPerPel=32 is but, does the value of 32 change if the screen resolution is different from 800 x 600?

Any help is appreciated.

Re: Code explanation

Posted: Thu Apr 18, 2019 4:08 pm
by TI-994A
Columbo wrote:...a line-by-line explanation as to what each line is doing?
Hi John! Here's a shot in the dark:

Code: Select all

; Microsoft Windows Win32 API Docs (DEVMODE)
; https://docs.microsoft.com/en-us/windows/desktop/api/wingdi/ns-wingdi-_devicemodea
; https://docs.microsoft.com/en-us/windows/desktop/api/wingdi/ns-wingdi-_devicemodew

; These constants correspond to the Win32 API's DEVMODE structure.
; They are now pre-declared in the latest versions of PureBasic and do not need to 
; be manually assigned. So, the #DM_XXXXXX constants can be used without declaration.
; #DM_BITSPERPEL = $40000
; #DM_PELSWIDTH = $80000
; #DM_PELSHEIGHT = $100000

; define a new Win32 API DEVMODE structure (refer to linked docs to view all the members)
res.DEVMODE

; assign the desired values to these six DEVMODE members
res\dmSize = SizeOf(DEVMODE)  ;structure size (required)
res\dmBitsPerPel = 32         ;desired colour depth (output element)
res\dmPelsWidth = 800         ;desired width (output element)
res\dmPelsHeight = 600        ;desired height (output element)
res\dmDisplayFrequency = 60   ;desired refresh rate

; #DM_BITSPERPEL  -> colour depth
; #DM_PELSWIDTH   -> display width
; #DM_PELSHEIGHT  -> display height
; set the OUTPUT element flags that are being modifed
res\dmFields = #DM_BITSPERPEL | #DM_PELSWIDTH | #DM_PELSHEIGHT

; pass the assigned DEVMODE structure (defined here as res) to the Win32 API function
ChangeDisplaySettings_(@res.DEVMODE, 0)

Re: Code explanation

Posted: Thu Apr 18, 2019 6:30 pm
by Columbo
Thanks Syed,... much appreciated.Good to hear from you.

Cheers!