Creates a new desktop, associates it with the current window station of the calling process.
#Include <WinAPIEx.au3>
_WinAPI_CreateDesktop ( $sName [, $iAccess [, $iFlags [, $iHeap [, $tSecurity]]]] )
$sName | The name of the desktop to be created. Desktop names are case-insensitive and may not contain backslash characters (\). |
$iAccess | [可选参数] The requested access to the desktop. This parameter can be one or more of the following values. $DESKTOP_ALL_ACCESS $DESKTOP_CREATEMENU $DESKTOP_CREATEWINDOW $DESKTOP_ENUMERATE $DESKTOP_HOOKCONTROL $DESKTOP_JOURNALPLAYBACK $DESKTOP_JOURNALRECORD $DESKTOP_READOBJECTS $DESKTOP_SWITCHDESKTOP $DESKTOP_WRITEOBJECTS |
$iFlags | [可选参数] The optional flags. It can be zero or the following value. $DF_ALLOWOTHERACCOUNTHOOK |
$iHeap | [可选参数] The size of the desktop heap, in kilobytes. |
$tSecurity | [可选参数] $tagSECURITY_ATTRIBUTES structure that determines whether the returned handle can be inherited by child processes. If this parameter is 0, the handle cannot be inherited. |
Success | Handle to the newly created desktop. If the specified desktop already exists, the function succeeds and |
失败: | 返回 0 并设置 @error 标志为非 0 值. |
在MSDN中搜索
#Include <APIConstants.au3>
#Include <WinAPIEx.au3>
Opt('MustDeclareVars', 1)
Global $hDesktop, $hPrev, $pText, $tProcess, $tStartup
; Retrieve a handle to the current desktop and create a new desktop named "MyDesktop"
$hPrev = _WinAPI_GetThreadDesktop(_WinAPI_GetCurrentThreadID())
$hDesktop = _WinAPI_CreateDesktop('MyDesktop', BitOR($DESKTOP_CREATEWINDOW, $DESKTOP_SWITCHDESKTOP))
If Not $hDesktop Then
MsgBox(16, 'Error', 'Unable to create desktop.')
Exit
EndIf
; Switch to the newly created desktop
_WinAPI_SwitchDesktop($hDesktop)
; Run "calc.exe" on "MyDesktop" and wait until a process will not be closed by user
$pText = _WinAPI_CreateString('MyDesktop')
$tProcess = DllStructCreate($tagPROCESS_INFORMATION)
$tStartup = DllStructCreate($tagSTARTUPINFO)
DllStructSetData($tStartup, 'Size', DllStructGetSize($tStartup))
DllStructSetData($tStartup, 'Desktop', $pText)
If _WinAPI_CreateProcess('', @SystemDir & '\calc.exe', 0, 0, 0, $CREATE_NEW_PROCESS_GROUP, 0, 0, DllStructGetPtr($tStartup), DllStructGetPtr($tProcess)) Then
ProcessWaitClose(DllStructGetData($tProcess, 'ProcessID'))
EndIf
; Switch to previous desktop and close "MyDesktop"
_WinAPI_SwitchDesktop($hPrev)
_WinAPI_CloseDesktop($hDesktop)
; Free memory allocated for a string
_WinAPI_FreeMemory($pText)