Solved

Closing a menu popup

Posted on 1998-09-17
12
289 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
  • 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
 
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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

In this article, I will show how to use the Ribbon IDs Tool Window to assign the built-in Office icons to a ribbon button.  This tool will help us to find the OfficeImageId that corresponds to our desired built-in Office icon. The tool is part of…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
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…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

747 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now