[VC孤芳自赏]NT下Explorer崩溃后NotifyTray图标的生成
有些同学在编程中常问我关于程序在Explorer崩溃重建后,该如何把系统托盘上的小图标重建回去。其实这个很简单,Explorer重建之后,会产生一个TaskbarCreated事件,我们在程序里向系统注册这个事件,
const UINT WM_TASKBARCREATED = ::RegisterWindowMessage(_T("TaskbarCreated"));
然后在程序的WindowProc里处理注册的消息;
LRESULT XXXXXX::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
// TOD Add your specialized code here and/or call the base class
if (message == WM_TASKBARCREATED)
{
m_nid.uFlags = NIF_MESSAGE|NIF_ICON|NIF_TIP;
Shell_NotifyIcon(NIM_ADD, &m_nid);
}
return CFrameWnd::WindowProc(message, wParam, lParam);
}
在接收到Explorer重建的消息后,我们用NIM_ADD参数重建自已的消息图标。 <P>MSDN上说是在IE4以后的系统中会有这个产生</P>
<P>With Internet Explorer 4.0 and later, the Shell notifies applications that the taskbar has been created. When the taskbar is created, it registers a message with the TaskbarCreated string and then broadcasts this message to all top-level windows. When your taskbar application receives this message, it should assume that any taskbar icons it added have been removed and add them again. This feature generally applies only to services that are already running when the Shell begins execution. The following example shows a very simplified method for handling this case.</P>
LRESULT CALLBACK WndProc(HWND hWnd, UINT uMessage, WPARAM wParam,
LPARAM lParam)
{
static UINT s_uTaskbarRestart;
switch(uMessage)
{
case WM_CREATE:
s_uTaskbarRestart = RegisterWindowMessage(TEXT("TaskbarCreated"));
break;
default:
if(uMessage == s_uTaskbarRestart)
AddTaskbarIcons();
break;
}
return DefWindowProc(hWnd, uMessage, wParam, lParam);
}
[此贴子已经被作者于2004-12-13 23:50:57编辑过]
什么跟什么呀???看不懂 <P>编译一下,发下出来.我这没VC</P> 编译后的文件还有意义吗? 我要这程序 <P>我要这程序有用啊~~~</P> 要这东西有什么用? <P>天书/?</P> 挂传奇世界的时候,下面的图表。。。有时候出错了就不见了 那没有用的……只能修复本身的。我可以考虑做一个你要的。
页:
[1]