|
@@ -22,6 +22,11 @@
|
|
|
#define new DEBUG_NEW
|
|
|
#endif
|
|
|
|
|
|
+#if USE_TRAYICON
|
|
|
+#define WM_MY_TRAY_NOTIFICATION WM_USER + 108
|
|
|
+const UINT WM_TASKBARCREATED = ::RegisterWindowMessage(_T("UB530"));
|
|
|
+#endif
|
|
|
+
|
|
|
// CMainFrame
|
|
|
|
|
|
IMPLEMENT_DYNAMIC(CMainFrame, CMDIFrameWndEx)
|
|
@@ -35,25 +40,116 @@ BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWndEx)
|
|
|
ON_UPDATE_COMMAND_UI(ID_VIEW_CAPTION_BAR, &CMainFrame::OnUpdateViewCaptionBar)
|
|
|
ON_COMMAND(ID_TOOLS_OPTIONS, &CMainFrame::OnOptions)
|
|
|
ON_WM_SETTINGCHANGE()
|
|
|
+#if USE_TRAYICON
|
|
|
+ ON_MESSAGE(WM_MY_TRAY_NOTIFICATION, OnTrayNotification)
|
|
|
+ ON_REGISTERED_MESSAGE(WM_TASKBARCREATED, OnTaskBarCreated)
|
|
|
+#endif
|
|
|
END_MESSAGE_MAP()
|
|
|
|
|
|
// CMainFrame 构造/析构
|
|
|
|
|
|
-CMainFrame::CMainFrame() noexcept
|
|
|
+CMainFrame::CMainFrame() noexcept :m_trayIcon(IDR_MAINFRAME)
|
|
|
{
|
|
|
// TODO: 在此添加成员初始化代码
|
|
|
theApp.m_nAppLook = theApp.GetInt(_T("ApplicationLook"), ID_VIEW_APPLOOK_VS_2008);
|
|
|
+#if USE_TRAYICON
|
|
|
+ m_isNotify = TRUE;
|
|
|
+ m_bNoticeTray = TRUE;
|
|
|
+#endif
|
|
|
}
|
|
|
|
|
|
CMainFrame::~CMainFrame()
|
|
|
{
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+#if USE_TRAYICON
|
|
|
+void CMainFrame::InitTrayIcon()
|
|
|
+{
|
|
|
+ m_trayIcon.SetNotificationWnd(this, WM_MY_TRAY_NOTIFICATION);
|
|
|
+ m_trayIcon.SetIcon(IDR_MAINFRAME, _T("UB530"));
|
|
|
+ m_trayIcon.SetIconInfos(IDR_MAINFRAME, IDR_MAINFRAME, IDR_MAINFRAME);
|
|
|
+ m_trayIcon.SetDefaultTip(_T("UB530"));
|
|
|
+}
|
|
|
+
|
|
|
+LRESULT CMainFrame::OnTaskBarCreated(WPARAM wp, LPARAM lp)
|
|
|
+{
|
|
|
+ Shell_NotifyIcon(NIM_ADD, &m_trayIcon.m_nid);
|
|
|
+ return 0;
|
|
|
+}
|
|
|
+
|
|
|
+// Handle notification from tray icon: display a message.
|
|
|
+LRESULT CMainFrame::OnTrayNotification(WPARAM uID, LPARAM lEvent)
|
|
|
+{
|
|
|
+ if (m_isNotify)
|
|
|
+ {
|
|
|
+ static LPCSTR MouseMessages[] = { "WM_MOUSEMOVE",
|
|
|
+ "WM_LBUTTONDOWN", "WM_LBUTTONUP", "WM_LBUTTONDBLCLK",
|
|
|
+ "WM_RBUTTONDOWN", "WM_RBUTTONUP", "WM_RBUTTONDBLCLK",
|
|
|
+ "WM_MBUTTONDOWN", "WM_MBUTTONUP", "WM_MBUTTONDBLCLK" };
|
|
|
+ }
|
|
|
+
|
|
|
+ if (uID != IDR_MAINFRAME)
|
|
|
+ return m_trayIcon.OnTrayNotification(uID, lEvent);
|
|
|
+
|
|
|
+ switch (lEvent)
|
|
|
+ {
|
|
|
+ case WM_RBUTTONUP:
|
|
|
+ TrayRight();
|
|
|
+ break;
|
|
|
+ case WM_LBUTTONUP:
|
|
|
+ break;
|
|
|
+ case WM_LBUTTONDBLCLK:
|
|
|
+ TaskNotifyIcon();
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ return 0;
|
|
|
+}
|
|
|
+
|
|
|
+void CMainFrame::TrayRight()
|
|
|
+{
|
|
|
+ CMenu menu;
|
|
|
+ if (!menu.LoadMenu(IDR_MAINFRAME))
|
|
|
+ return;
|
|
|
+
|
|
|
+ CMenu* pSubMenu = menu.GetSubMenu(4);
|
|
|
+ if (!pSubMenu)
|
|
|
+ return;
|
|
|
+
|
|
|
+ CPoint point;
|
|
|
+ GetCursorPos(&point);
|
|
|
+ ::SetForegroundWindow(m_hWnd);
|
|
|
+ pSubMenu->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, point.x, point.y, this);
|
|
|
+}
|
|
|
+
|
|
|
+void CMainFrame::TaskNotifyIcon()
|
|
|
+{
|
|
|
+ if (!m_bNoticeTray)
|
|
|
+ {
|
|
|
+ m_trayIcon.SetIcon(IDR_MAINFRAME, _T("UB530采集程序"));
|
|
|
+ ShowWindow(SW_SHOWNORMAL);
|
|
|
+ m_bNoticeTray = TRUE;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ m_trayIcon.SetIcon(IDR_MAINFRAME, _T("UB530采集程序"));
|
|
|
+ ShowWindow(SW_HIDE);
|
|
|
+ m_bNoticeTray = FALSE;
|
|
|
+ }
|
|
|
+}
|
|
|
+#endif
|
|
|
+
|
|
|
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
|
|
|
{
|
|
|
if (CMDIFrameWndEx::OnCreate(lpCreateStruct) == -1)
|
|
|
return -1;
|
|
|
|
|
|
+#if USE_TRAYICON
|
|
|
+ InitTrayIcon();
|
|
|
+#endif
|
|
|
+
|
|
|
BOOL bNameValid;
|
|
|
|
|
|
#if __TAB_BAR__
|