CXTTrayIcon m_TrayIcon;
在OnCreate()函数里,创建
if (!m_TrayIcon.Create(
_T("Power Tools for MFC!"), // Toolktip text
this, // Parent window
IDR_MAINFRAME, // Icon resource ID
IDR_POPUP_TRAY, // Resource ID of popup menu
IDC_RESTORE, // Default menu item for popup menu
false)) // True if default menu item is located by position
{
TRACE0("Failed to create tray icon/n");
return -1;
}
//重载OnSysCommand()函数
void CMainFrame::OnSysCommand(UINT nID, LPARAM lParam)
{
// TODO: Add your message handler code here and/or call default
switch(nID) //如果鼠标点击最小化按钮
{
case SC_MINIMIZE:
UpdateData();
m_TrayIcon.MinimizeToTray(this);//最小化到托盘
m_TrayIcon.ShowBalloonTip("asdsad", "Information",NIIF_INFO, 10);//弹出
return;
}
CFrameWnd::OnSysCommand(nID, lParam);
}
//写一个回复窗口的函数
void CMainFrame::OnRestore()
{
// TODO: Add your command handler code here
m_TrayIcon.MaximizeFromTray(this);
}
//写一个退出程序的函数
//顺便说一下发送WM_SYSCOMMAND消息
SendMessage(WM_SYSCOMMAND,SC_MINIMIZE,NULL);
SendMessage(WM_SYSCOMMAND,SC_CLOSE,NULL);