Desktop API 笔记
//枚举所有桌面
BOOL EnumDesktops( HWINSTA hwinsta, DESKTOPENUMPROC lpEnumFunc, LPARAM lParam);
//打开获取用户输入的桌面窗口
HDESK OpenInputDesktop( DWORD dwFlags, BOOL fInherit, ACCESS_MASK dwDesiredAccess );
如:HDESK hOriginalDesk = ::OpenInputDesktop( 0, FALSE, DESKTOP_SWITCHDESKTOP );
//创建桌面窗口
HDESK CreateDesktop( LPCTSTR lpszDesktop, LPCTSTR lpszDevice, LPDEVMODE pDevmode, DWORD dwFlags, ACCESS_MASK dwDesiredAccess, LPSECURITY_ATTRIBUTES lpsa );
如:HDESK hDesk = ::CreateDesktop( _T("NewDesk"), NULL, NULL, 0, GENERIC_ALL, NULL );
//切换到指定桌面窗口
BOOL SwitchDesktop( HDESK hDesktop );
//打开桌面窗口
HDESK OpenDesktop( LPTSTR lpszDesktop, DWORD dwFlags, BOOL fInherit, ACCESS_MASK dwDesiredAccess );
//关闭桌面窗口句柄
BOOL CloseDesktop( HDESK hDesktop );
//为当前的线程指定特定的运行桌面
BOOL SetThreadDesktop( HDESK hDesktop );
//获取指定线程的运行桌面
HDESK GetThreadDesktop( DWORD dwThreadId );
PS: 创建一个新的桌面后,应调用Windows程序userinit.exe来初始化桌面,这样才会出现任务栏桌面ListView等元素:
BOOL InitDeskTop( LPTSTR lpszDeskName )
{
BOOL bRet = FALSE;
DWORD dwExitCode;
STARTUPINFO si;
PROCESS_INFORMATION pi;
ZeroMemory( &si, sizeof(si) );
si.cb = sizeof(si);
si.dwFlags = STARTF_USESHOWWINDOW;
si.wShowWindow = SW_SHOWMAXIMIZED;
si.lpDesktop = lpszDeskName;
ZeroMemory( &pi, sizeof(pi) );
bRet = ::CreateProcess( NULL, _T("userinit.exe"), NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi );
bRet = ::GetExitCodeProcess( pi.hProcess,&dwExitCode );
return bRet;
}