從C++

2011-07-05 29 views
8

執行「顯示桌面」我設計了用戶做出的手勢,然後我的程序捕捉它(使用網絡攝像頭),我的程序會在一個規則系統(基於XML),這是操作的系統,它必須這樣做。從C++

好了,一旦我解釋的背景下,我想知道我怎麼能讓我的程序「執行」顯示桌面按鈕。我想爲用戶提供做手勢並顯示桌面的可能性。可能嗎?我一直在尋找執行「顯示桌面」按鈕的程序(.exe),恐怕不存在。

回答

7

this MSDN blog post(日期爲2004年,但肯定仍然有效),你必須調用ToggleDesktop().

在C#:

// Create an instance of the shell class 
Shell32.ShellClass objShel = new Shell32.ShellClass(); 
// Show the desktop 
((Shell32.IShellDispatch4) objShel).ToggleDesktop(); 
// Restore the desktop 
((Shell32.IShellDispatch4) objShel).ToggleDesktop(); 

編輯

C++版本:

#include <Shldisp.h> 

CoInitialize(NULL); 
// Create an instance of the shell class 
IShellDispatch4 *pShellDisp = NULL; 
HRESULT sc = CoCreateInstance(CLSID_Shell, NULL, CLSCTX_SERVER, IID_IDispatch, (LPVOID *) &pShellDisp); 
// Show the desktop 
sc = pShellDisp->ToggleDesktop(); 
// Restore the desktop 
sc = pShellDisp->ToggleDesktop(); 
pShellDisp->Release(); 
+0

它完美的作品。謝謝:) – Oni

4

從0123開始309393:

#define MIN_ALL  419 
#define MIN_ALL_UNDO 416 
int main(int argc, char* argv[]) 
{ 
    HWND lHwnd = FindWindow("Shell_TrayWnd",NULL); 
    SendMessage(lHwnd,WM_COMMAND,MIN_ALL,0); // Minimize all windows 
    Sleep(2000); 
    SendMessage(lHwnd,WM_COMMAND,MIN_ALL_UNDO,0); // Bring all back up again. 
    return 0; 
} 

希望它有幫助。它至少做它應該做的事,最大限度地減少所有的窗口。顯示桌面。

+0

嗯,這是靠三重無證行爲:在任務欄上的「最小化所有」命令ID,併爲「撤消最小化所有」命令ID的類名。所有這些值都可以隨時更改。 –

1

在Windows中,你可以將腳本複製:

[Shell] 
Command=2 
IconFile=explorer.exe,3 
[Taskbar] 
Command=ToggleDesktop 

到文件「somefile.scf」,並通過手動執行「somefile.scf」從外殼調用它。這也可以用C++來完成。