Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Icon added to system trat but popup menu not disappear if I click somewhere else

Icon added to system trat but popup menu not disappear if I click somewhere else

Scheduled Pinned Locked Moved C / C++ / MFC
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Z Offline
    Z Offline
    zahid_ash
    wrote on last edited by
    #1

    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.

    H V 2 Replies Last reply
    0
    • Z zahid_ash

      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.

      H Offline
      H Offline
      Hamid Taebi
      wrote on last edited by
      #2

      See Minimize your app to systray in 8 easy steps[^] maybe it is some helpful to you_**


      **_

      whitesky


      Z 1 Reply Last reply
      0
      • H Hamid Taebi

        See Minimize your app to systray in 8 easy steps[^] maybe it is some helpful to you_**


        **_

        whitesky


        Z Offline
        Z Offline
        zahid_ash
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        • Z zahid_ash

          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.

          V Offline
          V Offline
          Viorel
          wrote on last edited by
          #4

          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 before TrackPopupMenu, and then to post a benign message immediately after TrackPopupMenu:

          ::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

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups