我用自定义消息在主窗口用PostMessage(Findhd, WM_USER+500, 0, 0);向子窗口发送消息,在子窗口接受消息如下:unit bbb;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs; const
WM_CCC=WM_USER+500;type
TForm2 = class(TForm)
private public
{ Private declarations }
{ Public declarations }
end; typeTmypaint=recordmsgid:cardinal; msize:word; mcolor:longint; msgresult:longint; end; type
Tmycontrol=class(TControl)
protected
procedure WMBarIcon1(var
Message: TMessage); message WM_CCC;end;var
Form2: TForm2;implementationprocedure Tmycontrol.WMBarIcon1
(var Message:TMessage);
var
lpData:Tmypaint;
begin
if Message.WParam = WM_CCC then
begin
ShowMessage('ccccccccccc');
end;
end;{$R *.dfm}end.
为什么我收不到消息?
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs; const
WM_CCC=WM_USER+500;type
TForm2 = class(TForm)
private public
{ Private declarations }
{ Public declarations }
end; typeTmypaint=recordmsgid:cardinal; msize:word; mcolor:longint; msgresult:longint; end; type
Tmycontrol=class(TControl)
protected
procedure WMBarIcon1(var
Message: TMessage); message WM_CCC;end;var
Form2: TForm2;implementationprocedure Tmycontrol.WMBarIcon1
(var Message:TMessage);
var
lpData:Tmypaint;
begin
if Message.WParam = WM_CCC then
begin
ShowMessage('ccccccccccc');
end;
end;{$R *.dfm}end.
为什么我收不到消息?
TForm2 = class(TForm)
private
public
{ Private declarations }
procedure WMBarIcon1(var Message: TMessage); message WM_CCC; 放到这里才可以.
{ Public declarations }
end;
begin
ShowMessage('ccccccccccc');
end;
Message.LParam = 0;
if Findhd <> 0 then
begin
PostMessage(Findhd, WM_CCC, WM_CCC, 0);
end else
ShowMessage('not find windows');
我把WM_CCC改成WM_Close就会把窗口关掉,
PostMessage(
HWND hWnd, // handle of destination window
UINT Msg, // message to post
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
);
begin
PostMessage(Form2.Handle, WM_USER+500, 0, 0);
end;。procedure TForm2.WMBarIcon1(var Message: TMessage);
begin
ShowMessage('ccccccccccc');
end;
上面运行没有任何问题。
WM_CCC=WM_USER+500;type
TForm2 = class(TForm)
Button1: TButton;
private
procedure WMBarIcon1(var Message: TMessage); message WM_CCC;
public
{ Public declarations }
end;