Thema: Delphi TPopupMenu.OnClose?

Einzelnen Beitrag anzeigen

Benutzerbild von Sprint
Sprint

Registriert seit: 18. Aug 2004
Ort: Edewecht
712 Beiträge
 
Delphi 5 Professional
 
#3

Re: TPopupMenu.OnClose?

  Alt 27. Okt 2004, 22:22
Zitat von Shaman:
Ich vermisse beim PopupMenu das Ereignis, wenn es geschlossen wird - egal wie, auch durch Klick irgendwo ausserhalb. Wie bekomme ich das mit?
Windows sendet dazu die Nachricht WM_EXITMENULOOP. Bei TMainMenu kannst du die ohne weiters abfangen, weil dort die Nachricht an
die Form geschickt wird. Bei TPopupMenu's musst du das Fensterhandle von TPopupList subclassen. Das kannst du zum Beispiel so machen...

Delphi-Quellcode:
type
  TForm1 = class(TForm)
  ...
  private
    { Private-Deklarationen }
    OldPopupListWndProc: TFNWndProc;
    NewPopupListWndProc: TFNWndProc;
    procedure PopupListWndProc(var Message: TMessage);
  ...
  end;
Delphi-Quellcode:
{--------------------------------------------------------------------------------------------------}

procedure TForm1.FormCreate(Sender: TObject);
begin
  NewPopupListWndProc := MakeObjectInstance(PopupListWndProc);
  OldPopupListWndProc := TFNWndProc(GetWindowLong(PopupList.Window, GWL_WNDPROC));
  SetWindowLong(PopupList.Window, GWL_WNDPROC, Longint(NewPopupListWndProc));
end;

{--------------------------------------------------------------------------------------------------}

procedure TForm1.FormDestroy(Sender: TObject);
begin
  SetWindowLong(PopupList.Window, GWL_WNDPROC, Longint(OldPopupListWndProc));
end;

{--------------------------------------------------------------------------------------------------}

procedure TForm1.PopupListWndProc(var Message: TMessage);
begin
  with Message do
  begin
    case Msg of
      WM_ENTERMENULOOP:; // PopupMenu wird geöffnet
      WM_EXITMENULOOP:; // PopupMenu wird geschlossen
    end;
    Result := DefWindowProc(PopupList.Window, Msg, WParam, LParam);
  end;
end;

{--------------------------------------------------------------------------------------------------}
Ciao, Sprint.

"I don't know what I am doing, but I am sure I am having fun!"
  Mit Zitat antworten Zitat