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.
Created
October 13, 2017 16:22
-
-
Save jpluimers/cd3c42564bebe76a3b54af2f6cfb15c9 to your computer and use it in GitHub Desktop.
ExPopupList.pas by Peter Below from "missing TPopupMenu features?" at https://groups.google.com/forum/#!topic/borland.public.delphi.winapi/1L47R-u_MOA
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment