c語言如何打開桌面?
虛擬一個桌面,然后在虛擬桌面啟動explorer進程,用戶可以用"ALT+Q"來切換現有桌面與這個虛擬桌面,用戶需要運行什么軟件,自己在虛擬桌面打開就是了。原理很簡單,實現同樣也很簡單,下面是代碼:
#include
HINSTANCE hInst; //當前實例
TCHAR szAppName[] = TEXT ("VirtualDesk") ; //程序名稱
HWND hwnd ; //主窗體句柄
HDESK hVirtualDesk; //虛擬桌面句柄
HDESK hCurrent; //當前桌面句柄
PROCESS_INFORMATION piExplor; //Explorer進程的PROCESS_INFORMATION結構
LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM);
//每次運行首先檢測注冊表相關項,如果未發現,則設置開機自動運行
void SetStartup(HINSTANCE hInst)
{
HKEY hKey;
DWORD DataType = REG_SZ;
PCSTR data_run = "Software\Microsoft\Windows\CurrentVersion\Run";
long ret = RegOpenKeyEx(HKEY_LOCAL_MACHINE,data_run,0,KEY_ALL_ACCESS,&hKey);
if(ret != ERROR_SUCCESS)
{
MessageBox(NULL,"無法打開注冊表鍵","Error",0);
return;
}
CString ProcessName;
int len = GetModuleFileName(hInst,ProcessName.GetBuffer(256),256);
if(len == 0)
{
MessageBox(NULL,"無法獲取進程的當前目錄","Error",0);
return;
}
ProcessName.ReleaseBuffer(len);
DWORD direcLen = ProcessName.GetLength() + 1;
LPBYTE direc = new BYTE[direcLen];
Zero