The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 1,860 other subscribers

missing TPopupMenu feature: checking for visibility

Posted by jpluimers on 2019/06/25

a method to detect when the menu was closed without a selection (i.e. none of the menuitem OnClick handlers fired). Add the unit below to your project and the form the popup menu is on will receive the custom messages defined in the unit when the menu appears or closes.

The solution by Peter Below in ExPopupList works from D5 on:  [Archive.ismissing TPopupMenu features? – Google Groups.

Now you can hook the [WayBackTControl.OnContextPopup Event for a [WayBackTPopupMenu activation, and the custom Windows messages CM_MENUCLOSED, CM_ENTERMENULOOP and CM_EXITMENULOOP to monitor the state of the popup menu.

Via:

–jeroen

In D5 there is finally a method to detect when the menu was closed without a
selection (i.e. none of the menuitem OnClick handlers fired). Add the unit
below to your project and the form the popup menu is on will receive the
custom messages defined in the unit when the menu appears or closes.

view raw

README.md

hosted with ❤ by GitHub


unit ExPopupList;
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.

view raw

ExPopupList.pas

hosted with ❤ by GitHub

 

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.