码迷,mamicode.com
首页 > 编程语言 > 详细

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

时间:2014-09-25 19:26:47      阅读:293      评论:0      收藏:0      [点我收藏+]

标签:托盘图标

有时我们创建的托盘图标会无缘无故的消失了,搜索了下谷歌,发现是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);
}

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

标签:托盘图标

原文地址:http://blog.csdn.net/rmxming/article/details/39555101

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!