gpt4 book ai didi

windows - Delphi:如何向其他应用程序发送命令?

转载 作者:可可西里 更新时间:2023-11-01 12:36:16 24 4
gpt4 key购买 nike

如何从其他 Delphi 创建的应用程序发送和接收命令?我想向我编写的另一个应用程序发送命令。

最佳答案

发件人:

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;

const
WM_MY_MESSAGE = WM_USER + 1;

type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
h: HWND;
begin
h := FindWindow(nil, 'My Second Window');
if IsWindow(h) then
SendMessage(h, WM_MY_MESSAGE, 123, 520);
end;

end.

接收者:

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs;

const
WM_MY_MESSAGE = WM_USER + 1;

type
TForm1 = class(TForm)
private
{ Private declarations }
protected
procedure WndProc(var Message: TMessage); override;
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.WndProc(var Message: TMessage);
begin
inherited;
case Message.Msg of
WM_MY_MESSAGE:
ShowMessageFmt('The other application sent the data %d and %d.', [Message.WParam, Message.LParam]);
end;
end;

end.

确保接收表格的标题是“我的第二个窗口”。

关于windows - Delphi:如何向其他应用程序发送命令?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6115296/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com