执行“显示桌面”来自 C++

发布于 2024-11-18 07:19:28 字数 175 浏览 4 评论 0原文

我正在设计一个系统,用户做出手势,然后我的程序捕获它(使用网络摄像头),我的程序在规则系统(基于 XML)中查找它必须执行的操作。

好的,一旦我解释了背景,我想知道如何让我的程序“执行”显示桌面按钮。我想为用户提供执行手势并显示桌面的可能性。是否可以?我一直在寻找执行“显示桌面”按钮的程序(.exe),但恐怕它不存在。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

请爱~陌生人 2024-11-25 07:19:29

摘自这篇 MSDN 博客文章(日期为 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();   

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();   
木格 2024-11-25 07:19:29

来自 http://www.codeguru.com/forum/showthread.php?t= 310202

#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;
}

希望有帮助。它至少做了它应该做的事情,即最小化所有窗口。显示桌面。

From http://www.codeguru.com/forum/showthread.php?t=310202:

#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;
}

Hope it helps. It at least does what it should, minimizes all the windows aka. shows desktop.

神回复 2024-11-25 07:19:29

您需要调用 ToggleDesktop

You need to call ToggleDesktop.

糖粟与秋泊 2024-11-25 07:19:29

在 Windows 中,您可以将脚本复制

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

到文件“somefile.scf”中,并通过手动执行“somefile.scf”从 shell 调用它。这对于 C++ 也是可能的。

In Windows you can copy the script:

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

into a file "somefile.scf" and invoke it from the shell by executing "somefile.scf" by hand. This is also possible with C++.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文