MFC托盤圖示建立
1.頭檔案中加入函數定義:
void ToTray();//托盤圖示
NOTIFYICONDATA m_nid;//是用于設定托盤圖示的的結構體
2.構造函數中添加
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
memset(&m_nid, 0, sizeof(m_nid)); // Initialize NOTIFYICONDATA struct
m_nid.cbSize = sizeof(m_nid);
m_nid.uFlags = NIF_ICON | NIF_TIP | NIF_MESSAGE;
3.析構函數中添加
m_nid.hIcon = NULL;
Shell_NotifyIcon(NIM_DELETE, &m_nid);
4.函數實作:
void CXXXDlg::ToTray()
{
m_nid.hWnd = GetSafeHwnd();
m_nid.uCallbackMessage = UM_TRAYNOTIFY;
// Set tray icon and tooltip
m_nid.hIcon = m_hIcon;
// Set tray notification tip information
CString strToolTip = _T("簽字服務程式");
_tcsncpy_s(m_nid.szTip, strToolTip, strToolTip.GetLength());
Shell_NotifyIcon(NIM_ADD, &m_nid);
}
5.OnInitDialog()中調用 ToTray();
好了,一個完整的托盤圖示就完成啦。