Submitting WM_COMMAND to TMenuItem

In my OnShow method of a Delphi form, I specify that the dialog should open automatically after the form is open - and I should be able to do this by simulating a click on the menu element.

However, when calling menuitem.Click, it opens a dialog before the main form opens - this is not what I want.

I expect that I should do what I want, but I can’t find which parameters to pass for “wparam” in order to send a click to my menu item.

PostMessage(handle, WM_COMMAND, wparam, 0)

MSDN WM_COMMAND docs talk about IDM_ * identifiers, but how does this manifest in Delphi?

+3
source share
6 answers

, OnActivate? , OnActivate , , , , :

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

( , , , , - , .)
-

"TMenuItem" Command. WM_COMMAND 'wParam' '0', ;

PostMessage(Handle, WM_COMMAND, MakeWParam(MyMenuItem.Command, 0), 0);

;

PostMessage(Handle, WM_COMMAND, MyMenuItem.Command, 0);


: VCL . PopupList Window ;

PostMessage(PopupList.Window, WM_COMMAND, MyPopupMenuItem.Command, 0);
+5

, , Show/ShowModal, ( ..), - ?

tmrKickOff : a TTimer, 100 ms interval, disabled at design time, 
fires off a 'tmrKickOffTimer' event.


in form create,
tmrKickOff.Enabled:=false; //just in case something happened in IDE

in form show, at end of all other stuff;
tmrKickOff.Enabled:=true;

in tmrKickOffTimer
begin
  tmrKickOffTimer.Enabled:=false;
  menuItemClick(nil);
end;

, : -)

0

Application.OnIdle - ...

if not DialogDone then
begin
    MyDialogForm.ShowModal; // or menuItem.Click ....
    DialogDone := true;
end;

OnIdle ( ), , .

0

, , . , , ( , ) , .

-

procedure WMPostStartup(var Message: TMessage); message WM_POSTSTARTUP;

procedure TMainForm.WMPostStartup(var Message: TMessage);
begin
  Self.Refresh;
  // Now show the dialog box.
end;
0

, MarkF , , , :

const
  wm_SpecialProc = wm_User + 1;

procedure TForm1.WMSpecialProc(var Message:tMessage); message wm_SpecialProc;
begin
  Form2.ShowModal;
end;

procedure TForm1.OnShow(Sender:tObject);
begin
  if true then
    PostMessage(Application.MainForm.Handle,wm_SpecialProc,0,0);
end;

, , lparam wparam, . application.mainform, .

0

Source: https://habr.com/ru/post/1714856/


All Articles