It works in Delphi, but not in PB, can anyone help !?
Code: Select all
DesktopName.s="test 1"
Desk=CreateDesktop_(DesktopName, 0, 0, #DF_ALLOWOTHERACCOUNTHOOK, #MAXIMUM_ALLOWED, 0)
Debug Desk
Debug SwitchDesktop_(Desk)
Code: Select all
DesktopName.s="test 1"
Desk=CreateDesktop_(DesktopName, 0, 0, #DF_ALLOWOTHERACCOUNTHOOK, #MAXIMUM_ALLOWED, 0)
Debug Desk
Debug SwitchDesktop_(Desk)
Before calling CreateDesktop_() you need to associate a window station with your process. This is very easy if you've got the handle to one, just do this:The CreateDesktop function creates a new desktop on the window station associated with the calling process.
Code: Select all
SetProcessWindowStation(hWinSta)
Code: Select all
hWinSta = OpenWindowStation_("WinSta0", 0, #WINSTA_ALL)
Code: Select all
Procedure EnumWindowStationProc(Name.s, lParam.l)
Debug Name
ProcedureReturn 1
EndProcedure
EnumWindowStations_(@EnumWindowStationProc(), 0)
Code: Select all
#DESKTOP_ALL = #DESKTOP_WRITEOBJECTS | #DESKTOP_SWITCHDESKTOP | #DESKTOP_READOBJECTS | #DESKTOP_JOURNALRECORD | #DESKTOP_JOURNALPLAYBACK | #DESKTOP_HOOKCONTROL | #DESKTOP_ENUMERATE | #DESKTOP_CREATEWINDOW | #DESKTOP_CREATEMENU
hDesk = CreateDesktop_("Kool Desktop 2", 0, 0, #DF_ALLOWOTHERACCOUNTHOOK, #DESKTOP_ALL, 0)
SwitchDesktop_(hDesk)
Code: Select all
Delay(2000)
Code: Select all
hDefaultDesk = OpenDesktop_("Default", #DF_ALLOWOTHERACCOUNTHOOK, 0, #DESKTOP_SWITCHDESKTOP)
Code: Select all
Procedure EnumDesktopProc(Name.s, lParam.l)
Debug Name
ProcedureReturn 1
EndProcedure
hWinSta = OpenWindowStation_("WinSta0", 0, #WINSTA_ENUMDESKTOPS)
EnumDesktops_(hWinSta, @EnumDesktopProc(), 0)
CloseWindowStation_(hWinSta)
Code: Select all
SwitchDesktop_(hDefaultDesk)
Code: Select all
CloseDesktop_(hDesk) ; This DELETES the desktop we created
CloseDesktop_(hDefaultDesk) ; This closes the handle to the default desktop
CloseWindowStation_(hWinSta) ; This closes the handle to the window station.
Code: Select all
#DESKTOP_ALL = #DESKTOP_WRITEOBJECTS | #DESKTOP_SWITCHDESKTOP | #DESKTOP_READOBJECTS | #DESKTOP_JOURNALRECORD | #DESKTOP_JOURNALPLAYBACK | #DESKTOP_HOOKCONTROL | #DESKTOP_ENUMERATE | #DESKTOP_CREATEWINDOW | #DESKTOP_CREATEMENU
;Show an error
Procedure Abort(s.s)
MessageRequester("", "Error: "+s.s)
End
EndProcedure
;Check a result and ev. abort
Procedure Chk(a.l, s.s)
;If a is false, abort.
;If a is false and s contains an error message, show it before abort.
If Not(a)
If s.s
Abort(s.s)
Else
End
EndIf
EndIf
EndProcedure
hWinSta = OpenWindowStation_("WinSta0", 0, #WINSTA_ALL)
Chk( SetProcessWindowStation_(hWinSta) , "Failed to set window station")
hDefaultDesk = OpenDesktop_("Default", #DF_ALLOWOTHERACCOUNTHOOK, 0, #DESKTOP_SWITCHDESKTOP)
Chk(hDefaultDesk, "Failed to open default desktop")
hDesk = CreateDesktop_("My Desktop 2", 0, 0, #DF_ALLOWOTHERACCOUNTHOOK, #DESKTOP_ALL, 0)
Chk( hDesk, "Failed to create desktop")
Chk( SwitchDesktop_(hDesk), "Failed to switch desktop")
Delay(2000)
Chk( SwitchDesktop_(hDefaultDesk), "Failed to switch desktop")
CloseDesktop_(hDesk)
CloseDesktop_(hDefaultDesk)
CloseWindowStation_(hWinSta)
Code: Select all
#WINSTA_ALL = #WINSTA_ACCESSCLIPBOARD | #WINSTA_ACCESSGLOBALATOMS | #WINSTA_CREATEDESKTOP | #WINSTA_ENUMDESKTOPS | #WINSTA_ENUMERATE | #WINSTA_EXITWINDOWS | #WINSTA_READATTRIBUTES | #WINSTA_READSCREEN | #WINSTA_WRITEATTRIBUTES | #DELETE | #READ_CONTROL | #WRITE_DAC | #WRITE_OWNER