函数参考


_WinAPI_CreateDesktop

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

注意/说明

The number of desktops that can be created is limited by the size of the system desktop heap. You can increase the
number of desktops that can be created by increasing the size of the desktop heap or by reducing the default heap
reserved for each desktop in the interactive window station. The default size of the desktop heap depends on factors
such as hardware architecture. To retrieve the size of the heap, call the _WinAPI_GetUserObjectInformation()
function with $UOI_HEAPSIZE.

When you are finished using the desktop, call the _WinAPI_CloseDesktop() function to close it.

相关

详情参考

在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)