在VC++中如何实现显示桌面的功能即全部最小化显示桌面(整理收集)

在VC++中如何实现显示桌面的功能即全部最小化显示桌面(整理收集)

来源(www.asm32.net)

From: http://www.asm32.net/article_disp.asp?ID=4231


传统的办法是 写一个如下内容的文本文件命名为 显示桌面.scf (Show Desktop.scf)


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

[Taskbar]
Command=ToggleDesktop


---------------------------------------------------------------

模拟最小化屏幕快捷键Window+D

keybd_event(VK_LWIN,0,0,0);
keybd_event('D',0,0,0);
keybd_event(VK_LWIN,0,KEYEVENTF_KEYUP,0);
keybd_event('D',0,KEYEVENTF_KEYUP,0);


---------------------------------------------------------------

正统的办法如下:

#include  <windows.h>
#include  <shldisp.h>

int main(){
    CoInitialize(0);
    IShellDispatch4 * pdisp = NULL;
    CoCreateInstance(CLSID_Shell, NULL, CLSCTX_ALL, __uuidof(IShellDispatch4), (void **)&pdisp);
    pdisp->ToggleDesktop();  //  这句是用来切换桌面的
    pdisp->Release();
    CoUninitialize();
};


---------------------------------------------------------------

可以模拟发出windows+m试试看

---------------------------------------------------------------

还有另外一种方法,比较耗费时间,就是查找所有窗口FindWindow,如果发现可见的窗口IsWindowVisible,就发送最小化消息(WM_SYSCOMMAND,wParam==SC_MINIMIZE),

这个方法好处就是可以保留你自己的程序而不最小化

---------------------------------------------------------------

IShellDispatch4::ToggleDesktop

This method behaves like the toggle desktop icon on the quick launch bar. It hides all open windows and shows the desktop, or hides the desktop and shows all open windows. The ToggleDesktop method does not display any user interface, it just invokes the toggle action.

Link: http://www.asm32.net/article_disp.asp?ID=4231

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值