系统托盘图标VC

NOTIFYICONDATA myshell;

OnInitDialog():

//在托盘中显示图标
     myshell.cbSize=sizeof(NOTIFYICONDATA);
    myshell.hWnd=m_hWnd;
    myshell.uID=IDR_POP_MENU;
    myshell.uFlags=NIF_MESSAGE|NIF_ICON|NIF_TIP;
    myshell.uCallbackMessage=WM_USER+100;
    myshell.hIcon=AfxGetApp()->LoadIcon(IDR_MAINFRAME);
                strcpy(myshell.szTip,"正通信...");
    Shell_NotifyIcon(NIM_ADD, &myshell);
             ShowWindow(SW_HIDE);
//在托盘中显示图标

OnTimer(UINT nIDEvent) :

case 1:
   { 

      KillTimer(1); 
       ShowWindow(SW_HIDE);//隐藏程序界面
      break;
   }

DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam) 为:

LRESULT CMBSTATEDlg::DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
 // TODO: Add your specialized code here and/or call the base class
 switch(message)
 {
 case WM_USER + 100:
  if(lParam == WM_RBUTTONDOWN)
  {
   CMenu menu;
   if(!menu.LoadMenu(IDR_POP_MENU)) break;
   CMenu* pSubMenu = menu.GetSubMenu(0);
   CPoint pos;
   GetCursorPos(&pos);
   pSubMenu->TrackPopupMenu(TPM_LEFTALIGN,pos.x,pos.y, this, NULL);
   menu.DestroyMenu();
  }
  break;
 }
 
 return CDialog::DefWindowProc(message, wParam, lParam);
}

单击系统托盘图标右键显示"Exit",退出程序.

今天忙活了大半天,解决了这个问题,与大家分享一下:)

 

你可能感兴趣的:(系统托盘图标VC)