how to add popup menu on right click on systray icon

I have icon in systray area. How can I add popup menu when user right clicks on my icon?
amakalskiAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
jkrConnect With a Mentor Commented:
BTW, if you need another (MFC) sample on how to show a menu, take a lok at http://www.codeguru.com/shell/systemtray.shtml 
0
 
amakalskiAuthor Commented:
MFC code is fine
0
 
jkrCommented:
Check out the sample at http://www.codeproject.com/shell/systemtray.asp - it comes with all the code you need
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
amakalskiAuthor Commented:
@jrk,
thanks, but I already created icon in Systray using Shell_NotifyIcon (the article introduces whole class for that). All I need is to know how to create popup menu whenever user right-clicks on the icon and where to process menu commands
0
 
jkrCommented:
>>All I need is to know how to create popup menu

That is covered in the sample also, which was the main reason for me to post it.
0
 
amakalskiAuthor Commented:
Oh well, after an extensive lookup in the last sample I finally compiled code that I need to create and run popup menu:

      CMenu menu_bar;
      menu_bar.LoadMenu(IDM_POPUP_MENU);
      CMenu *popup_menu = menu_bar.GetSubMenu(0);
      assert( popup_menu != NULL );

      // Display and track the popup menu
      CPoint pos;
      GetCursorPos(&pos);

      this->SetForegroundWindow();  
      popup_menu->TrackPopupMenu(0,pos.x, pos.y, this, NULL);
      // BUGFIX: See "PRB: Menus for Notification Icons Don't Work Correctly"
    this->PostMessage(WM_NULL, 0, 0);

      menu_bar.DestroyMenu();
0
All Courses

From novice to tech pro — start learning today.