Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Executing "Show Desktop" from C++

I am designing a system where the user makes a gesture, then my program captures it (using a web cam) and my program looks in a rule system (based on XML) which are the actions that it has to do.

Ok, once I have explained the background, I'd like to know how I could make my program "execute" the Show Desktop button. I'd like to provide the user the possibility to do a gesture and show the desktop. Is it possible? I have been looking the program (.exe) that executes the Show Desktop button and I am afraid that does not exist.

like image 403
Oni Avatar asked Jul 05 '11 11:07

Oni


1 Answers

From this MSDN blog post (dated 2004 but surely still valid), you must call ToggleDesktop().

in 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();

EDIT

C++ version:

#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();   
like image 188
CharlesB Avatar answered Oct 05 '22 14:10

CharlesB