Icon added to system trat but popup menu not disappear if I click somewhere else
-
I have dowloaded a code from codeproject that adds a icon in systemtray and also a popup menu appears when a right click is made on the icon, but the if I do not select any option fron popup menu and click on some where else this popup menu do not disappear, why it is happening. How it can disappear if i do not select any option and click some else where it should disappear. Code snipts are here : in header file afx_msg void OnTrayNotify(WPARAM wParam, LPARAM lParam); in message map ON_MESSAGE(WM_TRAY_MESSAGE ,OnTrayNotify) Notify function defenition afx_msg void CTrayMinDlg::OnTrayNotify(WPARAM wParam, LPARAM lParam) { UINT uID; UINT uMsg; uID = (UINT) wParam; uMsg = (UINT) lParam; if (uID != 1) return; CPoint pt; switch (uMsg ) { case WM_LBUTTONDOWN: GetCursorPos(&pt); ClientToScreen(&pt); OnTrayLButtonDown(pt); break; case WM_RBUTTONDOWN: case WM_CONTEXTMENU: GetCursorPos(&pt); OnTrayRButtonDown(pt); break; } return; } void CTrayMinDlg::OnTrayLButtonDown(CPoint pt) { MessageBox("You have clicked Left mouse Button "); } void CTrayMinDlg::OnTrayRButtonDown(CPoint pt) { //m_menu is the member of CTrayMinDlg as CMenu m_menu; m_menu.GetSubMenu(0)->TrackPopupMenu(TPM_BOTTOMALIGN| TPM_LEFTBUTTON|TPM_RIGHTBUTTON,pt.x,pt.y,this); } Regards.
-
I have dowloaded a code from codeproject that adds a icon in systemtray and also a popup menu appears when a right click is made on the icon, but the if I do not select any option fron popup menu and click on some where else this popup menu do not disappear, why it is happening. How it can disappear if i do not select any option and click some else where it should disappear. Code snipts are here : in header file afx_msg void OnTrayNotify(WPARAM wParam, LPARAM lParam); in message map ON_MESSAGE(WM_TRAY_MESSAGE ,OnTrayNotify) Notify function defenition afx_msg void CTrayMinDlg::OnTrayNotify(WPARAM wParam, LPARAM lParam) { UINT uID; UINT uMsg; uID = (UINT) wParam; uMsg = (UINT) lParam; if (uID != 1) return; CPoint pt; switch (uMsg ) { case WM_LBUTTONDOWN: GetCursorPos(&pt); ClientToScreen(&pt); OnTrayLButtonDown(pt); break; case WM_RBUTTONDOWN: case WM_CONTEXTMENU: GetCursorPos(&pt); OnTrayRButtonDown(pt); break; } return; } void CTrayMinDlg::OnTrayLButtonDown(CPoint pt) { MessageBox("You have clicked Left mouse Button "); } void CTrayMinDlg::OnTrayRButtonDown(CPoint pt) { //m_menu is the member of CTrayMinDlg as CMenu m_menu; m_menu.GetSubMenu(0)->TrackPopupMenu(TPM_BOTTOMALIGN| TPM_LEFTBUTTON|TPM_RIGHTBUTTON,pt.x,pt.y,this); } Regards.
-
Yes I used the same one. the popup menu apeared on clicking the tray icon do not disappear if i click on some other window. It remains there, and to make it disappear I have to select something from menu. I want to hide the popup menu when I click on some other menu or in some other area Regards.
-
I have dowloaded a code from codeproject that adds a icon in systemtray and also a popup menu appears when a right click is made on the icon, but the if I do not select any option fron popup menu and click on some where else this popup menu do not disappear, why it is happening. How it can disappear if i do not select any option and click some else where it should disappear. Code snipts are here : in header file afx_msg void OnTrayNotify(WPARAM wParam, LPARAM lParam); in message map ON_MESSAGE(WM_TRAY_MESSAGE ,OnTrayNotify) Notify function defenition afx_msg void CTrayMinDlg::OnTrayNotify(WPARAM wParam, LPARAM lParam) { UINT uID; UINT uMsg; uID = (UINT) wParam; uMsg = (UINT) lParam; if (uID != 1) return; CPoint pt; switch (uMsg ) { case WM_LBUTTONDOWN: GetCursorPos(&pt); ClientToScreen(&pt); OnTrayLButtonDown(pt); break; case WM_RBUTTONDOWN: case WM_CONTEXTMENU: GetCursorPos(&pt); OnTrayRButtonDown(pt); break; } return; } void CTrayMinDlg::OnTrayLButtonDown(CPoint pt) { MessageBox("You have clicked Left mouse Button "); } void CTrayMinDlg::OnTrayRButtonDown(CPoint pt) { //m_menu is the member of CTrayMinDlg as CMenu m_menu; m_menu.GetSubMenu(0)->TrackPopupMenu(TPM_BOTTOMALIGN| TPM_LEFTBUTTON|TPM_RIGHTBUTTON,pt.x,pt.y,this); } Regards.
MSDN library mentions this problem in the description of
::TrackPopupMenu
function. In order to solve it, there is a recomendation to make the window foreground beforeTrackPopupMenu
, and then to post a benign message immediately afterTrackPopupMenu
:::SetForegroundWindow(hwnd);
::TrackPopupMenu(...);
::PostMessage(hwnd, WM_NULL, 0, 0);Or, in case of MFC, inside a member:
SetForegroundWindow();
TrackPopupMenu(...);
PostMessage(WM_NULL);Hope this will help. -- modified at 10:11 Friday 2nd June, 2006