[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 498
  • 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

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