views:

330

answers:

1

I'm attempting to run this in a timer:

Application.Minimize;
ShowWindow( Application.handle, SW_HIDE );

It's been in the code forever and we just discovered that it doesn't work when you have a popupmenu active, it doesn't minimize the MDI parent window.

I figure if I can close the popup menu before running this code, then I'll be ok. Problem is, this code is in an MDI Parent and I have no idea where the current popup menu is. It doesn't matter if it's part of another form's tool bar, this forms tool bar, the product of a right click or that seemingly pointless key next to the space bar.

So, is there a way to hide the active popup menu in my entire program?

Also, if there's a better hunk of code than what I'm using to minimize that'll circumvent this issue, that'd be awesome info too.

+6  A: 

To close a popup menu you can use

  if GetCapture <> 0 then
    SendMessage(GetCapture, WM_CANCELMODE, 0, 0);

in your code before you try to minimize the form.

mghie
AWESOME!!!! I would not have guessed that one in a million years.
Peter Turner
COOL! The GetCapture API is AWESOME!
Edwin