Solved

Closing a menu popup

Posted on 1998-09-17
12
297 Views
Last Modified: 2013-12-03
I am using C++Builder

I am disabling a menu on a timer. If the popup is active at
this time though it is not closed. I cannot seem to get the
popup to close whatever I do. I have tried sending several messages but to no avail ...

I only have access to the TMenu item (I even have it's HMENU), but that is not for the popup that appears when clicking on the menu.

Any suggestions
0
Comment
Question by:gysbert1
[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
  • 6
  • 6
12 Comments
 
LVL 20

Expert Comment

by:Madshi
ID: 1414505
gysbert1,

I'm using Delphi but I think the components are almost the same. So I guess you use TPopupMenu. What does you mean with having only access to the TMenu item?

I think you should be able to do something like that:

DestroyWindow(popup1.windowHandle);

Hope this helps...

Regards, Madshi.
0
 
LVL 2

Author Comment

by:gysbert1
ID: 1414506
That is exactly my problem !

I am using a TMainMenu. It pops up a popup menu when you choose one of the main items listing the sub items. It is this menu I need to close. The popup is created dynamically.

    --------------
    |  File     |   <- Main Menu that was Clicked
    =========
    ||  Open      ||   <- Popup that I need to kill when I disable the File Menu
    ||  Close      ||
    ||--------------- ||
    ||  Print       ||
    ||  Options  ||
    =========

Exuse the skew art but it will give you an Idea.

If I can get the handle to the Popup I will be able to kill it, but how do I get that ?

0
 
LVL 20

Expert Comment

by:Madshi
ID: 1414507
gysbert1,

do the following:

  EnableWindow(handle,false); EnableWindow(handle,true);

This will close the menu. It's a little bit tricky but works (at least with Delphi).

Regards, Madshi.
0
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 
LVL 2

Author Comment

by:gysbert1
ID: 1414508
Sorry !

That is exactly what the problem is !

How do I get the handle that I can pass to EnableWindow in order to close the menu window ? Actually I do not only want to disable the input to the window, I want to close it as well (as in CloseWindow(handle); ), but I WILL need the handle to do that.

The menu has a WindowHandle property, but that is the command handling entity's handle and not the Menu Window itself ...

0
 
LVL 20

Expert Comment

by:Madshi
ID: 1414509
The TMainMenu component belongs to a form, doesn't it? Then just give the handle of the form in EnableWindow(...).
0
 
LVL 2

Author Comment

by:gysbert1
ID: 1414510
What good will that do ?

I want the form to keep on working and still be displayed. I want the thingy drawn above in my comment that pops up when you click on file in my application to dissapear without any action from the user.

Closing the form or disabling input to the form will prevent the user to access the Login menu that still has to be active in order for the user to gain full access again ...
0
 
LVL 20

Expert Comment

by:Madshi
ID: 1414511
Have you read my whole comment?

I wrote:

EnableWindow(handle,false); EnableWindow(handle,true);

That means, your form is disabled for about 0.00000000000000000001 seconds. You won't even see that.

AND the menu is closed with these two function calls. Just what you wanted. Please try it out!
0
 
LVL 2

Author Comment

by:gysbert1
ID: 1414512
WOW !!!

I am real stupid today ...

Sorry but I completely misunderstood your answer ... Should have commented first, I know ...

Bonus for you, in apology I adjusted the points. Please post an answer ...

0
 
LVL 20

Accepted Solution

by:
Madshi earned 200 total points
ID: 1414513
gysbert1,

no problem.   :-)
Thanx for the bonus points.

Regards, Madshi.

P.S: That means it works now?
0
 
LVL 2

Author Comment

by:gysbert1
ID: 1414514
Hows that for a bonus, twice what it was !!

Thanx for the help, not quite what I expected though ...


0
 
LVL 20

Expert Comment

by:Madshi
ID: 1414515
gysbert1,

  keybd_event(VK_ESCAPE,0,0,              0);
  keybd_event(VK_ESCAPE,0,KEYEVENTF_KEYUP,0);

is that better? This code simulates an escape key click.

Ok, both variants are not nice. Normally C++ Builder should close the popup for you. But since it doesn't you'll have to hack a little bit... I found no "normal" way to close that popup menu.   :-(

Regards, Madshi.
0
 
LVL 2

Author Comment

by:gysbert1
ID: 1414516
Aha !

That was what I thought would work. I cannot decide which would be best though :^(

I also would have liked the popup to be disabled automatically but it is not to be.

Thanx for the help !




0

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.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VBA Error Since Excel 2016 x64 5 166
ClickOnce Install - Shortcut Question 3 111
What is MicroStrategy.NET? 2 90
How can my static class become undefined?? 8 94
This article shows how to make a Windows 7 gadget that accepts files dropped from the Windows Explorer.  It also illustrates how to give your gadget a non-rectangular shape and how to add some nifty visual effects to text displayed in a your gadget.…
This article describes how to add a user-defined command button to the Windows 7 Explorer toolbar.  In the previous article (http://www.experts-exchange.com/A_2172.html), we saw how to put the Delete button back there where it belongs.  "Delete" is …
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

732 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