1 #include "stdafx.h"
2 #include "CNotifyIcon.h"
3 #include "MusicPlayer2.h"
4
CNotifyIcon()5 CNotifyIcon::CNotifyIcon()
6 {
7 }
8
9
~CNotifyIcon()10 CNotifyIcon::~CNotifyIcon()
11 {
12 }
13
Init(HICON hIcon)14 void CNotifyIcon::Init(HICON hIcon)
15 {
16 m_ntIcon.cbSize = sizeof(NOTIFYICONDATA); //该结构体变量的大小
17 m_ntIcon.hIcon = hIcon; //设置图标
18 m_ntIcon.hWnd = theApp.m_pMainWnd->GetSafeHwnd(); //接收托盘图标通知消息的窗口句柄
19 CCommon::WStringCopy(m_ntIcon.szTip, 128, APP_NAME);
20 m_ntIcon.uCallbackMessage = MY_WM_NOTIFYICON; //应用程序定义的消息ID号
21 m_ntIcon.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP; //图标的属性:设置成员uCallbackMessage、hIcon、szTip有效
22 }
23
SetIcon(HICON hIcon)24 void CNotifyIcon::SetIcon(HICON hIcon)
25 {
26 m_ntIcon.hIcon = hIcon;
27 }
28
AddNotifyIcon()29 void CNotifyIcon::AddNotifyIcon()
30 {
31 ::Shell_NotifyIcon(NIM_ADD, &m_ntIcon);
32 }
33
DeleteNotifyIcon()34 void CNotifyIcon::DeleteNotifyIcon()
35 {
36 ::Shell_NotifyIcon(NIM_DELETE, &m_ntIcon);
37 }
38
SetIconToolTip(LPCTSTR strTip)39 void CNotifyIcon::SetIconToolTip(LPCTSTR strTip)
40 {
41 if (m_tool_tip_str != strTip)
42 {
43 CCommon::WStringCopy(m_ntIcon.szTip, 128, strTip);
44 ::Shell_NotifyIcon(NIM_MODIFY, &m_ntIcon);
45 }
46 m_tool_tip_str = strTip;
47 }
48
OnNotifyIcon(UINT msgId,HWND hMiniMode)49 void CNotifyIcon::OnNotifyIcon(UINT msgId, HWND hMiniMode)
50 {
51 if (msgId == WM_LBUTTONUP)
52 {
53 if (hMiniMode != NULL)
54 {
55 ::ShowWindow(hMiniMode, SW_RESTORE);
56 ::SetForegroundWindow(hMiniMode);
57 }
58 else
59 {
60 theApp.m_pMainWnd->ShowWindow(SW_RESTORE);
61 theApp.m_pMainWnd->SetForegroundWindow();
62 }
63
64 }
65 if (msgId == WM_RBUTTONUP)
66 {
67 theApp.m_pMainWnd->SetForegroundWindow();
68
69 //在通知区点击右键弹出右键菜单
70 CPoint point;
71 GetCursorPos(&point); //获取当前光标的位置
72 theApp.m_menu_mgr.GetMenu(MenuMgr::NotifyMenu)->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, point.x, point.y, theApp.m_pMainWnd); //在指定位置显示弹出菜单
73 }
74 if (msgId == WM_LBUTTONDBLCLK)
75 {
76 }
77 }
78