#define TRAY_ICON_01 1 #define MY_SYSTEM_TRAY_MSG (WM_APP+1657) // ------------------------------------------------------------------------ ON_MESSAGE (MY_SYSTEM_TRAY_MSG, OnSysTrayIconClick) // ------------------------------------------------------------------------ void CMainFrame::AddMyIcon (void) { NOTIFYICONDATA tnid; CString csTip ; tnid.cbSize = sizeof(NOTIFYICONDATA); tnid.hWnd = GetSafeHwnd(); tnid.uID = TRAY_ICON_01; // personal ID tnid.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP; tnid.uCallbackMessage = MY_SYSTEM_TRAY_MSG; tnid.hIcon = m_hIconPhone ; if (csTip.LoadString (IDS_TRAY_MENU_TIP)) strncpy (tnid.szTip, csTip, sizeof(tnid.szTip)); else tnid.szTip[0] = '\0'; Shell_NotifyIcon (NIM_ADD, &tnid); } // ------------------------------------------------------------------------ afx_msg LONG CMainFrame::OnSysTrayIconClick (WPARAM wParam, LPARAM lParam) { switch (wParam) { // bunch of other code omitted here. Note that the // ID here matches that specified when the icon // was inserted, in the uID structure member. case TRAY_ICON_01: switch (lParam) { case WM_LBUTTONDOWN: case WM_RBUTTONDOWN: ShowLittleMenu (); break ; } break ; default: OutputDebugString ("invalid icon id from tray\n"); break ; } return TRUE ; } // ------------------------------------------------------------------------ void CMainFrame::ShowLittleMenu () { POINT CurPos ; GetCursorPos (&CurPos); SetForegroundWindow ();// Bodge to get around a documented bug in Explorer // Display the menu. m_hLittleMenu is a popup loaded elsewhere. TrackPopupMenu (m_hLittleMenu, TPM_LEFTBUTTON, CurPos.x, CurPos.y, 0, GetSafeHwnd(), NULL); PostMessage (WM_NULL, 0, 0);// Bodge to get around a documented bug in Explorer } // ------------------------------------------------------------------------ // ------------------------------------------------------------------------