[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

How to cause TrackPopUpMenu to return before the it's normal return conditions.

Posted on 2003-10-28
34
Medium Priority
?
637 Views
Last Modified: 2013-11-20
I have implemented logic to detect when a user clicks on a submenu on a popup menu that was created using TrackPopUpMenu.
Now I want to have this cause the Menu to close (and the function to return).
How can I do this ?
Thank in advance.
0
Comment
Question by:ElishaKlein
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 19
  • 13
  • +1
34 Comments
 
LVL 1

Expert Comment

by:rushinmonkey
ID: 9638060
have you tried DestroyMenu() ?
0
 
LVL 23

Accepted Solution

by:
Roshan Davis earned 1050 total points
ID: 9639225
post ESCAPE keyboard event. Just a tricky way, might have some other solutions

use "keybd_event()"

// Simulate a key press
         keybd_event( VK_ESCAPE,
                      0x45,
                      KEYEVENTF_EXTENDEDKEY | 0,
                      0 );

      // Simulate a key release
         keybd_event( VK_ESCAPE,
                      0x45,
                      KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP,
                      0);
0
 
LVL 6

Expert Comment

by:melodiesoflife
ID: 9639953
Please try:

CMenu menu;
CPoint pos;
GetCursorPos(&pos);


menu.LoadMenu (IDR_YOURMENU);
CMenu* pContextMenu = menu.GetSubMenu (0);
pContextMenu->TrackPopupMenu (TPM_LEFTALIGN |TPM_LEFTBUTTON
                        |TPM_RIGHTBUTTON, pos.x,
                                                   pos.y,this);//AfxGetMainWnd ());
pContextMenu->DestroyMenu();


Hope this help.
0
Survive A High-Traffic Event with Percona

Your application or website rely on your database to deliver information about products and services to your customers. You can’t afford to have your database lose performance, lose availability or become unresponsive – even for just a few minutes.

 
LVL 1

Author Comment

by:ElishaKlein
ID: 9643929
Ok Rosh,
Interesting problem here.
I have a menu with submenus with submenus .....
The goal is when the user clicks on a menu item with submenus do something (navigate to a web page)... and close the menu.
I keep track of the parent of each menu in a map.
I know which menu item is highlighted so I backtrack through parents in a loop till I get to the top and each time I simulate one escape press (good idea there).
The problem is after a small delay the submenu of the selected item appears - if the user clicks before this the I have one more escape than I need (and this screws up my logic to navigate to a web site since the escape cancles my navigation).
If he clicks after the submenu appears it works fine.
How can I either detect whether the submenu has appeared already or detect that the delay time has past (how long is it ?) or best if possible set the menu to open submenus without delay when highlighted.
Thanks a lot.
0
 
LVL 23

Expert Comment

by:Roshan Davis
ID: 9647744
I think the similar problem will occure in IE also
I'm checking that...
0
 
LVL 1

Author Comment

by:ElishaKlein
ID: 9647892
No in IE when you click an item with a submenu it just opens the submenu. I need different behavior.
0
 
LVL 23

Expert Comment

by:Roshan Davis
ID: 9647900
Just a wild guess

put a message peeking/dispatiching loop in the ESCAPE simulating program, and remove the WM_LBUTTON/UP messages without processing.

Rosh
0
 
LVL 1

Author Comment

by:ElishaKlein
ID: 9648640
Sorry I didn't follow your last comment.
0
 
LVL 1

Author Comment

by:ElishaKlein
ID: 9648642
Can you explain please ?
0
 
LVL 23

Expert Comment

by:Roshan Davis
ID: 9648684
Just a gues
Something like this

MSG msg;

while ( your ESCAPE simulate loop )
{
      while ( ::PeekMessage(&msg, NULL, NULL, NULL, PM_REMOVE) )
      {
            if ( msg.message != WM_LBUTTONDOWN &&
                   msg.message != WM_LBUTTONUP )
            {
                  ::TranslateMessage(&msg);
                  ::DispatchMessage(&msg);
            }
      }
}

Rosh :)
0
 
LVL 1

Author Comment

by:ElishaKlein
ID: 9648704
I don't understand how it's related to WM_LBUTTONDOWN and WM_LBUTTONUP.
0
 
LVL 1

Author Comment

by:ElishaKlein
ID: 9648744
I think we have a misunderstanding. My only problem is how many times to simulate escape.
Simple example.
Menu Item 1 > Menu item 2
Menu Item 1 is an item in the main popup menu.
Menu Item 2 is an item in the submenu.
I am detecting the click on Menu item 1 to do something.
When the mouse hovers over Menu item 1 menu item 2 will apear (after a little while).
The problem is if the user clicks menu item 1 after the submenu opens i need to hit escape twice. If he clicks before the submenu appears I need to click escape only once.
How do I know ?
0
 
LVL 23

Expert Comment

by:Roshan Davis
ID: 9648844
Now I understood.

Post a user defined message, from there do the keybd_event. So that will execute after showing the child popup menu.

0
 
LVL 1

Author Comment

by:ElishaKlein
ID: 9648890
Ok I'll try that. Thanks.
0
 
LVL 23

Expert Comment

by:Roshan Davis
ID: 9648898
Good Luck :o)
0
 
LVL 1

Author Comment

by:ElishaKlein
ID: 9648930
I am trying to make this call from :
LRESULT CALLBACK CBandToolBarCtrl::MouseProc(
  int nCode,      // hook code
  WPARAM wParam,  // message identifier
  LPARAM lParam   // mouse coordinates
)

How do I know which HWND to post the message to ?
0
 
LVL 1

Author Comment

by:ElishaKlein
ID: 9648937
It's a static member function.
0
 
LVL 23

Expert Comment

by:Roshan Davis
ID: 9648948
What "AfxGetMainWnd()->m_hWnd" ?

This will be your application's main window (MainFrame)

Rosh :)
0
 
LVL 1

Author Comment

by:ElishaKlein
ID: 9648961
It's not an MFC application !
0
 
LVL 1

Author Comment

by:ElishaKlein
ID: 9649010
Ok I found the HWND but the solution of posting a message didn't work. I think the submenu appears after a delay not when a message is handled.
Any other ideas ?
0
 
LVL 23

Expert Comment

by:Roshan Davis
ID: 9649024
then you can assign one global member assign the hwnd value when you are creating the main window

Rosh :)
0
 
LVL 1

Author Comment

by:ElishaKlein
ID: 9649048
I already did that. But the message posting idea didn't help me. I still have the same problem.
Thanks for you help.
Any more ideas.
0
 
LVL 1

Author Comment

by:ElishaKlein
ID: 9649054
How about if I peek for escape when TrackPopUpMenu returns then wait for the extra escape to go before I do the navigation ?
How could I code that ?
0
 
LVL 1

Author Comment

by:ElishaKlein
ID: 9649066
Sorry I'm not mch of a windows programmer I'm more into ATL, COM ...
:)
0
 
LVL 23

Expert Comment

by:Roshan Davis
ID: 9649068
Set a 500 milli second Timer, from there use the keybd_event
Don't forget to kill that timer. That you can do from the timer function itself
Rosh :)
0
 
LVL 23

Expert Comment

by:Roshan Davis
ID: 9649179
Is that okay? I can provide code, if needed
0
 
LVL 1

Author Comment

by:ElishaKlein
ID: 9649251
I want to try removing the extra escape from the message loop after TrackPopUpMenu returns first. (That way I don't have a delay for the user).
0
 
LVL 1

Author Comment

by:ElishaKlein
ID: 9649271
How about this:
MSG msg;
PeekMessage(&msg, NULL, NULL, NULL, PM_REMOVE);
if ( (msg.message != WM_WM_KEYDOWN) ||  (int)msg.wParam != VK_ESCAPE)
PostMessage...
PeekMessage(&msg, NULL, NULL, NULL, PM_REMOVE);
if ( (msg.message != WM_WM_KEYUP) ||  (int)msg.wParam != VK_ESCAPE)
PostMessage...

Would that work ?
Can you help me with the syntax ?
0
 
LVL 23

Expert Comment

by:Roshan Davis
ID: 9649283
keybd_event is sending the message, not posting, so that will not work.

Delay is the simple one, for that you can use Timer.
0
 
LVL 1

Author Comment

by:ElishaKlein
ID: 9649293
So I don't understand why the extra escape is canceling my navigation if it's handeled before the menu closes.
0
 
LVL 23

Expert Comment

by:Roshan Davis
ID: 9649312
ESCAPE is the short-cut of *STOP* in IE
0
 
LVL 1

Author Comment

by:ElishaKlein
ID: 9650388
grrrrrrrrrrrrrrrrrr
keybd_event( VK_F10,0x45,KEYEVENTF_EXTENDEDKEY | 0,0);

What a nice way to waste a day....
Thanks for your help :)
                         
0
 
LVL 23

Expert Comment

by:Roshan Davis
ID: 9655321
Is that problem solved?
0
 
LVL 1

Author Comment

by:ElishaKlein
ID: 9655946
Yes thats the solution f10 - just once and it closes the menu.
0

Featured Post

Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question