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

Detect When Popup Menus Are Visible...

761 views
Skip to first unread message

Scott Price

unread,
Jun 28, 2001, 7:19:40 AM6/28/01
to
Hi Folks,


Quick question. Has anyone got a solution to determine when a Popup Menu is
visible?

The API Function "AnyPopup" is a legacy thing which tells you if any POPUP
windows have their VISIBLE bit set. Downside of this being, if you look in
WinSight at almost all of the POPUP windows, they already have that bit set,
even if not visible on screen. So, this pretty much means that it is going
to return true almost all the time.

Next I thought I could use IsWindowVisible(hHandleOfPopupMenu) to do the
required job. That doesn't work either.

Finally I thought I could use FindWindow with the '#32768:PopupMenu' class
type to find the window when it was shown on screen. This even failed!

Does anyone out there that likes a challenge know how to achieve this?


Regards,


Scott.


Ahmad

unread,
Jun 28, 2001, 7:40:58 AM6/28/01
to

Scott Price <sco...@knowledgeuk.com> wrote in message
news:3b3b01f2$1_1@dnews...

I'd say:
Assign PopupMenu property of the form to the PopupMenu at design time and
whenever in code you want to make invisible then assign PopupMenu property
to nil:
Form1.PopupMenu := [Your popupmenu)
if Form1.PopupMenu <> nil then
do something
to make it invisible then Form1.PopupMenu := nil
hope this helps
regards


Bruno Lovatti

unread,
Jun 28, 2001, 8:33:09 AM6/28/01
to
This code may help. I THINK was sent to me by Peter Below.

Declare this unit in uses clause.


unit UPopupEx;

{
In D5 there is a solution to your problem. Add this unit to your project
(no further code is needed) and the active form will get the custom
messages declared in the units interface. You could destroy the popup menu
instance when you see CM_EXITMENULOOP. This solution does not work in
earlier versions of Delphi which did not expose the Popuplist to the
outside world. In these versions the only solution would be to install a
WH_CALLWNDPROC hook (thread specific) when the menu is popped up and remove
it again when it gets the WM_EXITMENULOOP message.
}

interface

uses Controls;

const
CM_MENUCLOSED = CM_BASE - 1;
CM_ENTERMENULOOP = CM_BASE - 2;
CM_EXITMENULOOP = CM_BASE - 3;

implementation

uses Messages, Forms, Menus;

type
TExPopupList = class( TPopupList )
protected
procedure WndProc(var message: TMessage); override;
end;

{ TExPopupList }

procedure TExPopupList.WndProc(var message: TMessage);

procedure Send( msg: Integer );
begin
if Assigned( Screen.Activeform ) then
Screen.ActiveForm.Perform( msg, message.wparam, message.lparam );
end;

begin
case message.Msg Of
WM_ENTERMENULOOP: Send( CM_ENTERMENULOOP );
WM_EXITMENULOOP : Send( CM_EXITMENULOOP );
WM_MENUSELECT :
with TWMMenuSelect( message ) do
if (Menuflag = $FFFF) and (Menu = 0) then
Send( CM_MENUCLOSED );
end; { Case }
inherited;
end;

initialization
Popuplist.Free;
PopupList := TExPopupList.Create;
// Note: will be freed by Finalization section of Menus unit.

end.


Now, you can get the messages sent by this unit.

Declare

procedure WmEnterMenuLoop(var msg: TMessage); message CM_ENTERMENULOOP;
procedure WmExitMenuLoop(var msg: TMessage); message CM_EXITMENULOOP;

and the code

procedure TfTray.WmEnterMenuLoop(var msg: TMessage);
begin
//
end;

procedure TfTray.WmExitMenuLoop(var msg: TMessage);
begin
//
end;


Bruno
Sorry for english mistakes!


Scott Price

unread,
Jul 5, 2001, 5:01:18 AM7/5/01
to
Thanks. I will look into it, but the down-side is that it would need to
work with Delphi 3 built applications!

Many Thanks,


Scott


0 new messages