Code: Alles auswählen
SetDisplayAutoRotationPreferences(

Code: Alles auswählen
SetDisplayAutoRotationPreferences(
Code: Alles auswählen
; PureBasic Code zum Drehen des Monitors in den Portrait-Modus
; Importiere die benötigten Windows-API-Funktionen
Import "user32.lib"
ChangeDisplaySettingsEx(*lpszDeviceName, *lpDevMode, hWnd, dwFlags)
EnumDisplaySettings(*lpszDeviceName, iModeNum, *lpDevMode)
ChangeDisplaySettings(*lpDevMode, dwFlags)
EndImport
; Struktur für die DEVMODE
Structure DEVMODE
dmPelsWidth.l
dmPelsHeight.l
dmDisplayFlags.l
dmDisplayFrequency.l
dmFields.l
; Weitere Felder können hier hinzugefügt werden
EndStructure
; Hauptprogramm
Procedure RotateToPortrait()
Define.devmode.DEVMODE
Define result.l
; Hole die aktuellen Einstellungen
If EnumDisplaySettings(0, 0, @devmode)
; Setze die neuen Werte für Portrait-Modus
devmode\dmPelsWidth = devmode\dmPelsHeight
devmode\dmPelsHeight = devmode\dmPelsWidth
devmode\dmFields = 1 ; DM_PELSWIDTH und DM_PELSHEIGHT
; Wende die neuen Einstellungen an
result = ChangeDisplaySettings(@devmode, 0)
If result = 0
MessageRequester("Erfolg", "Der Monitor wurde in den Portrait-Modus gedreht.", 0)
Else
MessageRequester("Fehler", "Konnte den Monitor nicht drehen. Fehlercode: " + Str(result), 0)
EndIf
Else
MessageRequester("Fehler", "Konnte die aktuellen Anzeigeeinstellungen nicht abrufen.", 0)
EndIf
EndProcedure
; Rufe die Funktion auf
RotateToPortrait()
Code: Alles auswählen
; DEVMODE is still included
;
Enumeration
#DMDO_DEFAULT ; The display orientation is the natural orientation of the display device; it should be used as the default.
#DMDO_90 ; The display orientation is rotated 90 degrees (measured clockwise) from DMDO_DEFAULT.
#DMDO_180 ; The display orientation is rotated 180 degrees (measured clockwise) from DMDO_DEFAULT.
#DMDO_270 ; The display orientation is rotated 270 degrees (measured clockwise) from DMDO_DEFAULT.
EndEnumeration
; helper
Procedure.s GetDisplayDeviceStateFlags(Flags)
Protected result$
If Flags & #DISPLAY_DEVICE_ACTIVE : result$ + "ACTIVE + " : EndIf
If Flags & #DISPLAY_DEVICE_ATTACHED_TO_DESKTOP : result$ + "ATTACHED_TO_DESKTOP + " : EndIf
If Flags & #DISPLAY_DEVICE_PRIMARY_DEVICE : result$ + "PRIMARY_DEVICE + " : EndIf
ProcedureReturn RTrim(RTrim(result$), "+")
EndProcedure
Procedure main()
Protected devmode.DEVMODE
Protected device.DISPLAY_DEVICE ; to store results from EnumDisplayDevices_()
Protected result, n
If OpenWindow(1,0,0,400,400, "INFO", #PB_Window_WindowCentered|#PB_Window_SystemMenu)
ListViewGadget(1,10,10,380,380)
device\cb = SizeOf(DISPLAY_DEVICE) ; <--- very important !!!
devmode\dmSize = SizeOf(DEVMODE) ; <-- not a bad idea anyway
While EnumDisplayDevices_(0, n, @device, 0) > 0 ; check all devices
n + 1 ; increment
If device\StateFlags & #DISPLAY_DEVICE_ATTACHED_TO_DESKTOP ; check if it's part of the desktop
If EnumDisplaySettings_(@device\DeviceName, #ENUM_CURRENT_SETTINGS, @devmode) > 0
AddGadgetItem(1, -1, "Display = " + #DQUOTE$ + PeekS(@device\DeviceName, 32) + #DQUOTE$)
AddGadgetItem(1, -1, " Flags = " + GetDisplayDeviceStateFlags(device\StateFlags))
AddGadgetItem(1, -1, " Frequency = " + Str(devmode\dmDisplayFrequency))
AddGadgetItem(1, -1, " BitsPerPel = " + Str(devmode\dmBitsPerPel))
AddGadgetItem(1, -1, " PelsWidth = " + Str(devmode\dmPelsWidth))
AddGadgetItem(1, -1, " PelsHeight = " + Str(devmode\dmPelsHeight))
AddGadgetItem(1, -1, " DO = " + StringField("DEFAULT 90 180 270", 1+devmode\Display\dmDisplayOrientation, " ") + " (" + Str(devmode\Display\dmDisplayOrientation)+")")
AddGadgetItem(1, -1, "")
EndIf
EndIf
Wend
While WaitWindowEvent() <> #PB_Event_CloseWindow : Wend
EndIf
ProcedureReturn 0
EndProcedure
main()
Code: Alles auswählen
; DEVMODE is still included
;
Enumeration
#DMDO_DEFAULT ; The display orientation is the natural orientation of the display device; it should be used as the default.
#DMDO_90 ; The display orientation is rotated 90 degrees (measured clockwise) from DMDO_DEFAULT.
#DMDO_180 ; The display orientation is rotated 180 degrees (measured clockwise) from DMDO_DEFAULT.
#DMDO_270 ; The display orientation is rotated 270 degrees (measured clockwise) from DMDO_DEFAULT.
EndEnumeration
#DISP_CHANGE_SUCCESSFUL = 0
#DISP_CHANGE_RESTART = 1
#DISP_CHANGE_FAILED = -1
#DISP_CHANGE_BADMODE = -2
#DISP_CHANGE_NOTUPDATED = -3
#DISP_CHANGE_BADFLAGS = -4
#DISP_CHANGE_BADPARAM = -5
#DISP_CHANGE_BADDUALVIEW = -6
Procedure main()
Protected devmode.DEVMODE, devmodeC.DEVMODE
Protected result.l, n, Dev$, Orig_Orientation, DesktopName$
If OpenWindow(1, 0, 0, 400, 400, "INFO", #PB_Window_WindowCentered | #PB_Window_SystemMenu)
ListViewGadget(1, 10, 10, 380, 380)
Count = ExamineDesktops()
For n = 0 To Count - 1
Dev$ = DesktopName(n)
If EnumDisplaySettings_(@Dev$, #ENUM_CURRENT_SETTINGS, @devmode) > 0
AddGadgetItem(1, - 1, "Display = " + #DQUOTE$ + Dev$ + #DQUOTE$)
If n = 0
;copy main desktop settings for some fun
CopyStructure(@devmode, @devmodeC, DEVMODE)
AddGadgetItem(1, - 1, " Primary Monitor")
Orig_Orientation = devmode\Display\dmDisplayOrientation
DesktopName$ = Dev$
EndIf
AddGadgetItem(1, - 1, " Frequency = " + Str(devmode\dmDisplayFrequency))
AddGadgetItem(1, - 1, " BitsPerPel = " + Str(devmode\dmBitsPerPel))
AddGadgetItem(1, - 1, " PelsWidth = " + Str(devmode\dmPelsWidth))
AddGadgetItem(1, - 1, " PelsHeight = " + Str(devmode\dmPelsHeight))
AddGadgetItem(1, - 1, " DO = " + StringField("DEFAULT 90 180 270", 1 + devmode\Display\dmDisplayOrientation, " ") + " (" + Str(devmode\Display\dmDisplayOrientation) + ")")
AddGadgetItem(1, - 1, "")
EndIf
Next n
;just for fun, swap main monitor 90°
devmodeC\Display\dmDisplayOrientation = #DMDO_90
Swap devmodeC\dmPelsHeight, devmodeC\dmPelsWidth
result = ChangeDisplaySettingsEx_(@DesktopName$, @devmodeC, 0, 0, 0)
Select result
Case #DISP_CHANGE_SUCCESSFUL
Debug "The settings change was successful."
Case #DISP_CHANGE_BADDUALVIEW
Debug "The settings change was unsuccessful because the system is DualView capable."
Case #DISP_CHANGE_BADFLAGS
Debug "An invalid set of flags was passed in."
Case #DISP_CHANGE_BADMODE
Debug "The graphics mode is Not supported."
Case #DISP_CHANGE_BADPARAM
Debug "An invalid parameter was passed in. This can include an invalid flag Or combination of flags."
Case #DISP_CHANGE_FAILED
Debug "The display driver failed the specified graphics mode."
Case #DISP_CHANGE_NOTUPDATED
Debug "Unable To write settings To the registry."
Case #DISP_CHANGE_RESTART
Debug "The computer must be restarted For the graphics mode To work."
EndSelect
While WaitWindowEvent() <> #PB_Event_CloseWindow : Wend
devmodeC\Display\dmDisplayOrientation = Orig_Orientation
Swap devmodeC\dmPelsHeight, devmodeC\dmPelsWidth
ChangeDisplaySettingsEx_(@DesktopName$, @devmodeC, 0, 0, 0)
EndIf
ProcedureReturn 0
EndProcedure
main()