系统托盘图标

  1. 类中添加变量 NOTIFYICONDATA m_Nid; 
  2. 在OnInitDialog()中添加TrayIcon m_Nid.cbSize = sizeof(NOTIFYICONDATA); m_Nid.hWnd = GetSafeHwnd(); m_Nid.uID = 0; m_Nid.hIcon = m_hIcon; //设置图标 m_Nid.uFlags = NIF_ICON | NIF_TIP | NIF_MESSAGE; m_Nid.uCallbackMessage = WM_COMMAND; CString sTitle = _T("TrayIconTest"); _tcscpy(m_Nid.szTip, sTitle); Shell_NotifyIcon(NIM_ADD, &m_Nid); 
  3. 增加对WM_DESTROY的响应void CTrayIconTestDlg::OnDestroy() { CDialog::OnDestroy(); Shell_NotifyIcon(NIM_DELETE, &m_Nid); }  
  4. 尝试为托盘图标添加响应(添加菜单)
  5. 响应WM_COMMAND,覆盖CDialog的OnCommand()函数BOOL CTrayIconTestDlg::OnCommand(WPARAM wParam, LPARAM lParam) { if (!wParam) { switch (lParam) { case WM_RBUTTONUP: //显示操作菜单 CMenu Menu, *pMenu; Menu.LoadMenu(IDR_MENU1); pMenu=Menu.GetSubMenu(0); SetForegroundWindow(); POINT pt; //设置菜单显示位置 GetCursorPos(&pt); pMenu->TrackPopupMenu(TPM_LEFTALIGN | TPM_BOTTOMALIGN | TPM_LEFTBUTTON | TPM_RIGHTBUTTON, pt.x, pt.y, this); break; } } return CDialog::OnCommand(wParam, lParam); } 

你可能感兴趣的:(shell,command,delete,menu)