Search code examples
delphiwinapipostmessagetmenuitem

Sending WM_COMMAND to a TMenuItem


In my Delphi form's OnShow method, I determine that a dialog must be opened automatically once the form is opened - and I should be able to do this by simulating a click on a menuitem.

However, calling menuitem.Click brings up the dialog before the main form has opened - which is not what I want.

I expect that should do what I want, but I cannot find what parameters to pass for "wparam" to send the click to my menuitem.

PostMessage(handle, WM_COMMAND, wparam, 0)

The MSDN WM_COMMAND docs talk about IDM_* identifiers, but how does that appear in Delphi?


Solution

  • Perhaps you can try to open the dialog in the OnActivate event ? I am not really sure if the OnActivate gets fired again other than when the form is shown but if it does you can use :

    procedure TForm1.FormActivate(Sender: TObject);
    begin
      Form2.ShowModal;
      Self.OnActivate := nil;
    end;