添加和删除显示任务栏图标示例
void CProcessDlg::addTray()//添加显示任务栏图标
{
NOTIFYICONDATA tnd;
tnd.cbSize=sizeof(NOTIFYICONDATA);
tnd.hWnd=this->m_hWnd;
tnd.uID=IDI_ICON1;//任务栏显示的图标
tnd.uFlags=NIF_MESSAGE|NIF_ICON|NIF_TIP;
tnd.uCallbackMessage=WM_TRAY;//
tnd.hIcon=LoadIcon(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDI_ICON1));
strcpy(tnd.szTip,"屏蔽系统鼠标右健程序,双击图标弹出窗口");//图标提示为"测试程序"
Shell_NotifyIcon(NIM_ADD,&tnd);//向任务栏添加图标
}
void CProcessDlg::delTray()//删除任务栏图标
{
NOTIFYICONDATA tnd;
tnd.cbSize=sizeof(NOTIFYICONDATA);
tnd.hWnd=this->m_hWnd;
tnd.uID=IDI_ICON1;
tnd.uFlags=NIF_MESSAGE|NIF_ICON|NIF_TIP;
tnd.uCallbackMessage=NULL;//
tnd.hIcon=LoadIcon(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDI_ICON1));
strcpy(tnd.szTip,"屏蔽系统鼠标右健程序,双击图标弹出窗口");//图标提示为"测试程序"
Shell_NotifyIcon(NIM_DELETE,&tnd);//向任务栏添加图标
}
LRESULT CProcessDlg::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
// TODO: Add your specialized code here and/or call the base class
switch(message)
{
case WM_SYSCOMMAND:
if(wParam==SC_MINIMIZE)
{
addTray();
ShowWindow(SW_HIDE);
return 0;
}
break;
case WM_TRAY:
if(lParam==WM_RBUTTONUP||lParam==WM_LBUTTONUP)
{
ShowWindow(SW_SHOW);
delTray();
}
break;
}
return CDialog::WindowProc(message, wParam, lParam);
}