PureBasic Forum

Code explanation
Page 1 of 1

Author:  Columbo [ Thu Apr 18, 2019 3:07 pm ]
Post subject:  Code explanation

I was looking through some posts for some information on changing screen resolution and found this code.






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.

Author:  TI-994A [ Thu Apr 18, 2019 4:08 pm ]
Post subject:  Re: Code explanation

Columbo wrote:
...a line-by-line explanation as to what each line is doing?

Hi John! Here's a shot in the dark:
; 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)

; 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

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

Author:  Columbo [ Thu Apr 18, 2019 6:30 pm ]
Post subject:  Re: Code explanation

Thanks Syed,... much appreciated.Good to hear from you.


Page 1 of 1 All times are UTC + 1 hour
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group