Some netizens developed their own pallet class, to achieve a slightly cumbersome. Here I recommend a simple and very effective pallet class (which I learned in a book).
1. Copy TrayIcon.cpp and TrayIcon.cpp to your project directory and add it to your project.
2, add #include "TrayIcon.h" in DemoDlg.h
3, add member variable Ctrayicon M_ctrayicon through Class Cdemodlg to guide class;
4, the establishment of menu resources, so that its ID: idr_demo, Design menu:
To add an event handler to Demo1 and exit:
void CDemoDlg::OnFileDemo1()
{
ShowWindow(SW_SHOW);
m_TrayIcon.RemoveIcon();
}
void CDemoDlg::OnFileExit()
{
m_TrayIcon.RemoveIcon();
OnCancel();
}
5. Customize the message #define Wm_icon_notify wm_user+10 in DemoDlg.cpp and declare the message handler function at the declaration message:
BEGIN_MESSAGE_MAP(CDemoDlg, CDialog)
......
ON_MESSAGE(WM_ICON_NOTIFY, OnTrayNotification)
……
END_MESSAGE_MAP()
To add a member function to the class Cdemodlg:
LRESULT OnTrayNotification(WPARAM wParam,LPARAM lParam);
Implementation section:
LRESULT CDemoDlg::OnTrayNotification(WPARAM wParam,LPARAM lParam)
{
return m_TrayIcon.OnTrayNotification(wParam,lParam);
}
6, add the "Start" button in the dialog box, and double-click the "Start" button to edit the handler:
void CDemoDlg::OnBnClickedButton1()
{
m_TrayIcon.Create(this,WM_ICON_NOTIFY,"鼠标指向时显示",m_hIcon,IDR_DEMO); //构造
ShowWindow(SW_HIDE); //隐藏窗口
}
7, you can flexibly use other class member functions. such as: SetIcon change the icon, you can use the timer message to achieve the tray icon animation effect.
8, delete tray icon: M_trayicon.removeicon ();
This article supporting source code