Code explanation

Just starting out? Need help? Post your questions and find answers here.
User avatar
Columbo
Enthusiast
Enthusiast
Posts: 303
Joined: Wed Sep 10, 2014 7:17 am
Location: Ontario Canada
Contact:

Code explanation

Post 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.
http://www.oldtimeradiotoday.com - Listen to or download classic old time radio broadcasts.
User avatar
TI-994A
Addict
Addict
Posts: 2512
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: Code explanation

Post 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)
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel :D
User avatar
Columbo
Enthusiast
Enthusiast
Posts: 303
Joined: Wed Sep 10, 2014 7:17 am
Location: Ontario Canada
Contact:

Re: Code explanation

Post by Columbo »

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

Cheers!
http://www.oldtimeradiotoday.com - Listen to or download classic old time radio broadcasts.
Post Reply