1.声明变量NOTIFYICONDATA m_traydata; 2.在OnInitDialog()函数中,增加: m_traydata.cbSize = sizeof(NOTIFYICONDATA); m_traydata.hIcon = AfxGetApp()->LoadIcon(IDI_TRAYICON);//IDI_TRAYICON为导入的托盘图标ICON m_traydata.hWnd = m_hWnd; char *m_str = "托盘提示标语"; strncpy(m_traydata.szTip,m_str,strlen(m_str)+1);//strlen +1表示将空字符拷贝到目标字符串中 m_traydata.uCallbackMessage = WM_TRARMESSAGE; m_traydata.uFlags = NIF_ICON|NIF_MESSAGE|NIF_TIP; 3.缩小时,显示托盘图标 增加函数 afx_msg void OnSysCommand(UINT nID, LPARAM lParam); 在函数void CTrayPopMenuDlg::OnSysCommand(UINT nID, LPARAM lParam)其中加入判断条件: else if ((nID & 0xFFF0) == SC_MINIMIZE ) //缩小操作 { ShowWindow(SW_HIDE); Shell_NotifyIcon(NIM_ADD,&m_traydata); } 4.退出时,同时退掉托盘图标 在退出函数OnCancel()中加入:Shell_NotifyIcon(NIM_DELETE,&m_traydata); 5.增加托盘消息函数 afx_msg void OnTrayMessage(WPARAM wParam, LPARAM lParam); ON_MESSAGE(WM_TRARMESSAGE,OnTrayMessage) void CTestDlg::OnTrayMessage(WPARAM wParam, LPARAM lParam) { if (lParam == WM_LBUTTONDOWN) { ShowWindow(SW_RESTORE); } else if (lParam == WM_RBUTTONDOWN) { CPoint m_point; ::GetCursorPos(&m_point); //显示弹出菜单 CMenu* m_submenu = (Menu*)m_menu.GetSubMenu(0); m_submenu->TrackPopupMenu(TPM_LEFTALIGN|TPM_RIGHTBUTTON, m_point.x,m_point.y,AfxGetApp()->m_pMainWnd,TPM_LEFTALIGN); } }
托盘显示
最新推荐文章于 2020-04-09 22:24:16 发布