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

TrackPopupMenu question

Hi,
how can I know when a popup menu created by "TrackPopupMenu" is closed ???

thanks,
Yoav.

0
yoavo
Asked:
yoavo
1 Solution
 
peterchen092700Commented:
You can use teh TMP_RETURNCMD flag, so TrackPopupMenu will not return before user selected a command (or calcened the menu). The return value is the command id of the selected item, or 0 if the user did cancel.

Helped?
Peter
0
 
MaheshSundararamanCommented:
Dear yoavo

According to TrackPopupMenu syntax

BOOL TrackPopupMenu( UINT nFlags, int x, int y, CWnd* pWnd, LPCRECT lpRect = NULL );

Return Value

Nonzero if the function is successful; otherwise 0.

So capture the return value and chaeck if greater than zero..successful completion means it has executed successfully


0
 
Meir RivkinFull stack Software EngineerCommented:
yoavo: use TMP_RETURNCMD flag according to peterchen, and use switch() to determine user's selection:

int nRes = menu->TrackPopupMenu(TPM_CENTERALIGN|TPM_RETURNCMD , point.x, point.y, this);

switch(nRes)
{
case 0: //no sub menu item was selected
.
.
.
}

good luck
0
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

 
yoavoAuthor Commented:
TrackPopupMenu returns immediately even with the TPM_RETURNCMD. with out waiting the popup menu selection.
0
 
Meir RivkinFull stack Software EngineerCommented:
thats not true my man, TrackPopUpMenu doesn't return a value until the menu is closed either by selection of the user or by clicking on other window which causes termination of the menu
0
 
MaheshSundararamanCommented:
i agree with sedgwick
0
 
DanRollinsCommented:
yoavo,
you may be experiencing a problem that can be seen when working with so-called "tray icons"  It is related to the tray-icon's window not being the foreground application.  There is a simple solution if this is your problem.

  GetCursorPos(&pt);
  ::SetForegroundWindow( m_rNID.hWnd );  // bug Q135788
  pSubMenu->TrackPopupMenu(0, pt.x,pt.y, this, NULL);

-- Dan
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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