Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to close a popup menu

30 views
Skip to first unread message

Thomas Matthews

unread,
Jan 17, 2002, 1:06:55 PM1/17/02
to
Hi,

I have a Popup menu associated with a Rich Edit window. The popup menu
contains one MenuItem.
That MenuItem has one event handler associated with the OnClick event.
This event handler
highlights the line in the Rich Edit window.

The user left clicks on a line. The user then right clicks in the Rich
Edit window. A menu pops up.
The user selects the only option to highlight the line. The line is
then highlighted, but the menu doesn't
go away unless the user clicks on the menu or somewhere else.

How do I close the Popup Menu so the user doesn't have to click
elsewhere?

I want the menu to go away after the line is highlighted.

-- Thomas


Remy Lebeau

unread,
Jan 17, 2002, 2:36:15 PM1/17/02
to
How are you displaying the popup menu? Are you assigning it to the
PopupMenu property and setting AutoPopup to true? Or are you displaying it
by calling Popup() manually?


Gambit

"Thomas Matthews" <thomas....@pb.com> wrote in message
news:3C4712BF...@pb.com...

Thomas Matthews

unread,
Jan 18, 2002, 10:05:03 AM1/18/02
to
I have the AutoPopup property set to true.
-- Thomas

Remy Lebeau

unread,
Jan 18, 2002, 12:30:29 PM1/18/02
to
Popup menus not disappearing correctly is a long-standing bug in the OS
itself, not the VCL's code. The usual workaround is as follows:

SetForegroundWindow(Handle);
// display menu
SendMessage(Handle, WM_NULL, 0, 0);

Since you're working with an AutoPopup menu, you could call
SetForegroundWindow() in the OnPopup event, and SendMessage() in the OnClick
handler.

The other alternative is to try simply sending a WM_CANCELMODE message in
the OnClick handler:

SendMessage(Handle, WM_CANCELMODE, 0, 0);

Both of these are untested. AutoPopup menus always work fine for me. I
only resort to the SFW()/WM_NULL trick for menus displayed manually via
Popup()


Gambit

"Thomas Matthews" <thomas....@pb.com> wrote in message

news:3C48399F...@pb.com...

robin

unread,
Jan 18, 2002, 2:42:28 PM1/18/02
to

SFW/WM_NULL trick works for no-AutoPopup. You have to set AutoPopup to fasle. Then write event handler for OnContextPopup and PopupMenu->Click.

Would you please tell me why WM_NULL works?

Remy Lebeau

unread,
Jan 18, 2002, 3:06:47 PM1/18/02
to
Have no idea why it works exactly, but it does. It's a long-known and
common trick for dealing with non-closing menus.


Gambit

"robin" <ro...@mdi.ca> wrote in message news:3c487aa4$1_1@dnews...

0 new messages