VC++界面编程之--托盘图标无缘无故被隐藏的原因

有时我们创建的托盘图标会无缘无故的消失了,搜索了下谷歌,发现是explorer.exe有时会记不住增加的托盘图标,当它记不住时,会发送消息询问窗口:有没有需要增加托盘图标的?然后你的窗口重新做一次增加托盘图标的动作即可。以下是原文:

When you’re a programmer, it seems like you learn something new every day. One of the things I’ve been working on in the next version of TopDesk is making it survive Explorer crashes. TopDesk has quite a few hooks into explorer.exe, so when Explorer goes down, TopDesk goes with it. After banging my head against the wall several times I managed to fix the problem, but I noticed that even with the fix in place the TopDesk system tray (sorry, taskbar notification area) icon failed to re-appear when Explorer came back to life.

What’s happening is that when Explorer crashes, the taskbar notification area crashes too, forgetting any icons it had. When Explorer starts back up, it re-creates the taskbar notification area and sends out a registered window message called (strangely enough) TaskbarCreated to all top-level windows. It’s up to an application to check for this message and re-initialize any taskbar notification area icons it has. Here’s how you do it in C/C++:

1. Register your application so it can receive TaskbarCreated messages:

UINT wmTaskbarCreated = RegisterWindowMessage(_T("TaskbarCreated"));

2. Handle the message in your window procedure:

LRESULT CALLBACK WindowProcedure(HWND hWnd, UINT nMessage, WPARAM wParam, LPARAM lParam)
{
	switch(nMessage)
	{
	default:
		{
			if(nMessage == wmTaskbarCreated)
			{
				// Call your system tray icon initialization function/method here
			}
		}
		break;
	}

	return DefWindowProc(hWnd, uMessage, wParam, lParam);
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值