This seems a bit easier (I used Delphi 2007):
In the WM_CONTEXTMENU message handler, a pop-up menu will appear before calling the inherited handler, you can set your flag. After calling the inherited popup menu has been closed, reset your flag.
procedure TForm1.WMContextMenu(var Message: TWMContextMenu); begin FPopupActive := True; try OutputDebugString(PChar(Format('popup opening', []))); inherited; finally FPopupActive := False; OutputDebugString(PChar(Format('popup closed', []))); end; end;
source share