• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 369
  • Last Modified:

popup menu on an icon in the system tray

I create an icon in the system tray with:

tnd.uCallbackMessage      = MYWM_NOTIFYICON;
Shell_NotifyIcon(NIM_ADD,&tnd);

works fine...

LRESULT CMyDlg::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
    switch (message) {

    case MYWM_NOTIFYICON: //----- something happened on my icon in the system tray
        switch(lParam) {
        case WM_RBUTTONUP: //----- have to create a popup menu
            CMenu menu, *pPopup;
            CPoint point;

            VERIFY(menu.LoadMenu(IDR_SYSTRAY_POPUP_MENU));
            pPopup = menu.GetSubMenu(0);
            ASSERT(pPopup != NULL);
      
            GetCursorPos(&point);          

            pPopup->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, point.x, point.y, this);
            break;
        }
        break;
    }
            
    return CDialog::WindowProc(message, wParam, lParam);
}

problem starts there:
when I right click on the icon, the menu appears, fine ! But this menu is supposed to disappear when I lButtonDown outside the menu...

the menu disappears only if I LButtonDown on my CMyDlg...

the style of this dlg is Modal, Popup, with no title bar & frame...

I am gratefull to the ones who wish to help me in my quest to a promised heaven...
0
amby
Asked:
amby
  • 5
1 Solution
 
ambyAuthor Commented:
Edited text of question
0
 
ambyAuthor Commented:
Edited text of question
0
 
ambyAuthor Commented:
Edited text of question
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
ambyAuthor Commented:
Edited text of question
0
 
Tommy HuiCommented:
Set your dialog to the foreground before doing the trackpopupmenu:

  SetForegroundWindow();
  pPopup->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, point.x, point.y, this);

0
 
ambyAuthor Commented:
Great !!

I had answers from 2 gurus of MFC !!!

I want to sleep with you too, like galfin...

PS: I would not have thought about that...
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now