拖盘图标用法

只写出代码,具体的资源不说了

 

1.ON_MESSAGE(WM_TRAY_NOTIFICATION,OnTrayNotification)
2.afx_msg LRESULT OnTrayNotification(WPARAM wParam,LPARAM lParam);
3.
//系统托盘
LRESULT CNetCapDlg::OnTrayNotification(WPARAM wParam,LPARAM lParam)
{
 // static BOOL Flag = TRUE;
 if ((wParam == IDI_ICON1)&&(lParam == WM_LBUTTONDOWN))
 {
  this->OnShowTray();
 }
 else if ((lParam == WM_RBUTTONDOWN))  
 { 
  CMenu oMenu;
  if (oMenu.LoadMenu(IDR_TRAY))       
  {
   CMenu* pPopup = oMenu.GetSubMenu(0);
   ASSERT(pPopup != NULL);
   CPoint oPoint;
   if (IsWindowVisible())// 将显示改为隐藏
    oMenu.ModifyMenu(ID_SHOW_TRAY,MF_STRING,ID_SHOW_TRAY,"隐藏(&H)");
   else
    oMenu.ModifyMenu(ID_SHOW_TRAY,MF_STRING,ID_SHOW_TRAY,"显示(&S)");
   //确定鼠标位置,以便在该位置附近显示菜单
   GetCursorPos( &oPoint );
   SetForegroundWindow();
   pPopup->TrackPopupMenu(
    TPM_LEFTALIGN | TPM_RIGHTBUTTON,
    oPoint.x, oPoint.y, this);
  }  
 } 
 return 0;
}


4.OnInitDialog()中添
//系统拖盘
 NOTIFYICONDATA NofityData;
 NofityData.cbSize=sizeof(NOTIFYICONDATA);
 NofityData.hWnd=this->m_hWnd;
 NofityData.uID=IDI_ICON1;
 NofityData.uFlags=NIF_MESSAGE|NIF_ICON|NIF_TIP;
 NofityData.uCallbackMessage=WM_TRAY_NOTIFICATION;
 HICON hIcon;
 hIcon=AfxGetApp()->LoadIcon(IDI_ICON1);
 NofityData.hIcon=hIcon;
 lstrcpyn(NofityData.szTip,"NetCap",sizeof(NofityData.szTip)); 

 ::Shell_NotifyIcon(NIM_ADD,&NofityData);


5.函数退出时候,删除托盘
void CNetCapDlg::OnQuitTray()
{
 // TODO: Add your command handler code here
 CDialog::OnCancel();
 /
 NOTIFYICONDATA NofityData1;
 NofityData1.cbSize=sizeof(NOTIFYICONDATA);
 NofityData1.hWnd=this->m_hWnd;
 NofityData1.uID=IDI_ICON1;
 NofityData1.uFlags=NIF_MESSAGE|NIF_ICON|NIF_TIP;
 ::Shell_NotifyIcon(NIM_DELETE,&NofityData1);
}

6.修改托盘信息
NOTIFYICONDATA NofityData;
  NofityData.cbSize=sizeof(NOTIFYICONDATA);
  NofityData.hWnd=this->m_hWnd;
  NofityData.uID=IDR_MAINFRAME;
  NofityData.uFlags=NIF_MESSAGE|NIF_ICON|NIF_TIP;
  HICON hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  NofityData.hIcon = hIcon;
  NofityData.uCallbackMessage=WM_MY_TRAY_NOTIFICATION;
  lstrcpyn(NofityData.szTip,"ServiceCPP",sizeof(NofityData.szTip));
  ::Shell_NotifyIcon(NIM_MODIFY,&NofityData);  


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值