Page 1 of 1

setting the screen resolution

Posted: Sun Apr 20, 2008 3:24 pm
by jcoggins
How do I change the user's screen resolution in PB?

Jason

Posted: Sun Apr 20, 2008 3:47 pm
by Derek
If you are talking about a full screen app like a game then you can use openscreen() to choose a size but if you want to change the actual desktop size used by windows then it can probably be done with the api but changing someones desktop size without asking won't win you any friends, people tend to set their systems up how they like them and don't like it when they get changed.

Posted: Sun Apr 20, 2008 3:50 pm
by srod
Have a look at EnumDisplaySettings_() and ChangeDisplaySettings_().

As Derek says, however, doing this without a user's strict permission could seriously annoy the said user! :)

Posted: Sun Apr 20, 2008 4:00 pm
by nco2k

Code: Select all

Procedure SetResolution(Width, Height, Depth, Flag=#CDS_FULLSCREEN)
  Protected Result, dmScreenSettings.DEVMODE
  dmScreenSettings\dmSize = SizeOf(DEVMODE)
  dmScreenSettings\dmPelsWidth = Width
  dmScreenSettings\dmPelsHeight = Height
  dmScreenSettings\dmBitsPerPel = Depth
  dmScreenSettings\dmFields = #DM_PELSWIDTH | #DM_PELSHEIGHT | #DM_BITSPERPEL
  If ChangeDisplaySettings_(@dmScreenSettings, Flag) = #DISP_CHANGE_SUCCESSFUL
    Result = #True
  EndIf
  ProcedureReturn Result
EndProcedure

SetResolution(800, 600, 16)
Delay(3000)
c ya,
nco2k

Posted: Sat Apr 26, 2008 5:16 pm
by Booger
Here is the routines I use.

Code: Select all

#DM_DISPLAYFREQUENCY = $400000
#DM_PELSWIDTH = $80000
#DM_PELSHEIGHT = $100000
#ENUM_CURRENT_SETTINGS=-1
#CDS_TEST=2
#CDS_FULLSCREEN=4
#CDS_RESET=$40000000
#DISP_CHANGE_SUCCESSFUL=0
#SC_MONITORPOWER=$F170
#CDS_NORESET=$10000000
#CDS_UPDATEREGISTRY=$00000001

Global DMsaved.DEVMODE ;Saves The Previous Screen Settings
Global dmScreenSettings.DEVMODE ;Device Mode


Procedure MonitorSetup(Width,Height,BitDepth,Frequency)
  Delay(10)
  
  EnumDisplaySettings_(#Null,#ENUM_CURRENT_SETTINGS,DMsaved) ;Save The Current Display State
  
  dmScreenSettings\dmSize=SizeOf(DEVMODE) ;Size Of The Devmode Structure
  dmScreenSettings\dmFields=#DM_DISPLAYFREQUENCY | #DM_BITSPERPEL | #DM_PELSWIDTH | #DM_PELSHEIGHT ;bit flags to specify the members of DEVMODE that were initialized
  dmScreenSettings\dmdisplayfrequency=Frequency
  dmScreenSettings\dmBitsPerPel=BitDepth ;Selected Bits Per Pixel
  dmScreenSettings\dmPelsWidth=Width ;Selected Screen Width in pixels
  dmScreenSettings\dmPelsHeight=Height ;Selected Screen Height in pixels
  
  
  ;***************************************************************************************
  ;*Try To Set Selected Mode And Get Results. Note: CDS_FULLSCREEN Gets Rid Of Start Bar
  ;It is written to the registry for API or other calls that work from the registry.
  ;It will be set back To original during shutdown.
  If ChangeDisplaySettings_(dmScreenSettings,#CDS_RESET | #CDS_UPDATEREGISTRY )<>#DISP_CHANGE_SUCCESSFUL
    If MessageBox_(#Null,"The Requested Fullscreen Mode Is Not Supported By"+Chr(10)+"Your Video Card. ","Your App name here.",#MB_OK | #MB_ICONEXCLAMATION)=#IDOK
      ;Pop Up A Message Box Letting User Know The Program Is Closing
      MessageBox_(#Null,"Please check to be sure you monitor settings are set back to normal.","ERROR",#MB_OK | #MB_ICONSTOP)
      ProcedureReturn #False
      
    EndIf
  EndIf
  
  ;***************************************************************************************
  ;YOU SHOULD CALL ANY SCREEN INIT ROUTINES THAT MAY USE REGISTRY VALUES HERE BEFORE NEXT SECTION
  
  
  
  ;*Rewrite the users Original Montior Frequency back into the registry.  It will be forced back
  ;*When ever the program reaches the MonitorRestore routine.  At least its back in the registry in case of a crash.
  ;NEXT SECTION WRITES THE ORIGINAL VALUES BACK INTO THE REGISTRY IN CASE YOU APP CRASHES
  ;***************************************************************************************
  

If ChangeDisplaySettings_(dmSaved,#CDS_NORESET | #CDS_UPDATEREGISTRY)<>#DISP_CHANGE_SUCCESSFUL
  If MessageBox_(#Null,"Cannot write Original settings back to registry!"+Chr(10)+"Your Video Card. ","Your App Name Here",#MB_OK | #MB_ICONEXCLAMATION)=#IDOK
    ;Pop Up A Message Box Letting User Know The Program Is Closing
    MessageBox_(#Null,"Please check to be sure you monitor settings are set back to normal.","ERROR",#MB_OK | #MB_ICONSTOP)
    ProcedureReturn #False
  EndIf
EndIf
ProcedureReturn #True
EndProcedure

;**************************************************************************************************
Procedure RestoreMonitorSettings()
  ;EnumDisplaySettings_(#Null,#ENUM_CURRENT_SETTINGS,DMsaved) ;Save The Current Display State
  ;No error checking, because its restoring the Original settings that were read before changing.
  ChangeDisplaySettings_(dmsaved,#CDS_RESET); Set the users frequency back to their preference.
EndProcedure
;**************************************************************************************************




;Note:  Vesa 2.0 only requires up To 800x600 @ 60hz.  This is the highest resolution And
;frequency that should be set without Querying the device capabilities.
result=MonitorSetup(800,600,32,60)

Delay(5000)

RestoreMonitorSettings()

End

Hope this helps, and be diligent and be sure to restore the users original settings on exit.

And be sure to to force resolutions and frequency that is not a vesa standard. You can damage monitors.