It is currently Mon Oct 21, 2019 4:56 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Code explanation
PostPosted: Thu Apr 18, 2019 3:07 pm 
Offline
Enthusiast
Enthusiast

Joined: Wed Sep 10, 2014 7:17 am
Posts: 126
Location: Ontario Canada
I was looking through some posts for some information on changing screen resolution and found this code.

Code:

#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.

_________________
Code In Basic - http://www.codeinbasic.com


Top
 Profile  
Reply with quote  
 Post subject: Re: Code explanation
PostPosted: Thu Apr 18, 2019 4:08 pm 
Offline
Addict
Addict
User avatar

Joined: Sat Feb 19, 2011 3:47 am
Posts: 2213
Location: Singapore
Columbo wrote:
...a line-by-line explanation as to what each line is doing?

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


Top
 Profile  
Reply with quote  
 Post subject: Re: Code explanation
PostPosted: Thu Apr 18, 2019 6:30 pm 
Offline
Enthusiast
Enthusiast

Joined: Wed Sep 10, 2014 7:17 am
Posts: 126
Location: Ontario Canada
Thanks Syed,... much appreciated.Good to hear from you.

Cheers!

_________________
Code In Basic - http://www.codeinbasic.com


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 14 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye