如何进行进程间的通讯???(50分)

  • 主题发起人 主题发起人 lnjamn
  • 开始时间 开始时间
L

lnjamn

Unregistered / Unconfirmed
GUEST, unregistred user!
程序A(待写)向程序B中的窗口FORM1中的LABEL8(在GROUPBOXA里面)控件发送一个单击事件??
问:要如何写程序A??
我用了
h:=findwindows(nil,'form1');
ph:=findwindowsex(h,0,nil,'label8');
但是PH:=0,
 
Label是静态标签,要有SS_NOTIFY style才能响应事件
delphi中的Label标签我没有看源码?不知是否是Windows static标签。


procedure TForm1.FormCreate(Sender: TObject);
var
Label1: HWND;
begin
Label1 := Windows.CreateWindow('static', 'testing', SS_NOTIFY or WS_VISIBLE or WS_CHILD,
10, 10, 100, 25, GroupBox1.Handle, 0, hInstance, nil);
if Label1 <> 0 then ;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
PH: HWND;
begin
//你要先找出GroupBox1.Handle的句柄
PH := FindWindowEx(GroupBox1.Handle, 0, nil, 'testing');
if PH <> 0 then ShowMessage(Format('%2.2X', [PH]));

end;
 
完整的例子API
unit Unit1;

interface

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

type
TForm1 = class(TForm)
Button1: TButton;
GroupBox1: TGroupBox;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);

private
{ Private declarations }
procedure WinProc(var Message: TMessage);
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}
var
Label1: HWND;
OldProc: TWndMethod;
procedure TForm1.FormCreate(Sender: TObject);
begin
//你单击这个标签试试
Label1 := Windows.CreateWindow('static', 'testing', SS_NOTIFY or WS_VISIBLE or WS_CHILD,
10, 10, 100, 25, GroupBox1.Handle, 0, hInstance, nil);
if Label1 <> 0 then begin
OldProc := GroupBox1.WindowProc;
GroupBox1.WindowProc := WinProc;
end;
end;


procedure TForm1.Button1Click(Sender: TObject);
var
PH: HWND;
begin
//你要先找出GroupBox1.Handle的句柄
PH := FindWindowEx(GroupBox1.Handle, 0, nil, 'testing');
if PH <> 0 then begin
SendMessage(GroupBox1.Handle, WM_COMMAND, 0, PH);
// ShowMessage(Format('%2.2X', [PH]));
end;

end;


procedure TForm1.WinProc(var Message: TMessage);
begin
if Message.LParam = Label1 then
begin
if HIWORD(Message.WParam) = BN_CLICKED then
ShowMessage('testing notify click');
end
else OldProc(Message);
end;

end.

dfm:
=========
object Form1: TForm1
Left = 192
Top = 107
Width = 696
Height = 480
Caption = 'Form1'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
OnCreate = FormCreate
PixelsPerInch = 96
TextHeight = 13
object Button1: TButton
Left = 256
Top = 152
Width = 75
Height = 25
Caption = 'Button1'
TabOrder = 0
OnClick = Button1Click
end
object GroupBox1: TGroupBox
Left = 56
Top = 16
Width = 185
Height = 105
Caption = 'GroupBox1'
TabOrder = 1
end
end
 
TO JFYES:
非常感谢,
我不知道这个是不是两个程序间的通讯!?
 
路过学习 帮你顶
 
两个进程间也可以呀?
windows是用句柄的
 
我没有试过,但看到过用共享内存区去进行数据通信的
 
接受答案了.
 
后退
顶部