#define WM_SHOWTASK (WM_USER + 101)
ON_MESSAGE(WM_SHOWTASK,onShowTask)
afx_msg LRESULT onShowTask(WPARAM wParam,LPARAM lParam);
NOTIFYICONDATA nid ;
nid.cbSize=(DWORD)sizeof(NOTIFYICONDATA);
nid.hWnd=this->m_hWnd;
nid.uID=IDR_MAINFRAME;
nid.uFlags=NIF_ICON|NIF_MESSAGE|NIF_TIP ;
nid.uCallbackMessage=WM_SHOWTASK;
nid.hIcon=LoadIcon(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDR_MAINFRAME));
strcpy(nid.szTip,"mfc ");
Shell_NotifyIcon(NIM_ADD,&nid);
ShowWindow(SW_HIDE);
LRESULT CTCP_ChatDlg::onShowTask(WPARAM wParam,LPARAM lParam)
{
if(wParam!=IDR_MAINFRAME)
return 1;
switch(lParam)
{
case WM_RBUTTONUP:
{
LPPOINT lpoint=new tagPOINT;
::GetCursorPos(lpoint);
CMenu menu;
menu.CreatePopupMenu();
menu.AppendMenu(MF_STRING,WM_DESTROY,"¹Ø±Õ");
menu.AppendMenu(MF_STRING,WM_DESTROY,"ÓÐÖÖµãÎÒ°¡");
//È·¶¨µ¯³öʽ²Ëµ¥µÄλÖÃ
SetForegroundWindow() ;
menu.TrackPopupMenu(TPM_LEFTALIGN,lpoint->x,lpoint->y,this);
HMENU hmenu=menu.Detach();
menu.DestroyMenu();
delete lpoint;
Shell_NotifyIcon(NIM_DELETE,&nid);
}
break;
case WM_LBUTTONDBLCLK:
{
this->ShowWindow(SW_SHOW);
Shell_NotifyIcon(NIM_DELETE,&nid);
}
break;
}
return 0;
}