现有一个frame嵌在form中,在该frame中要发一个自定义消息给form,按照一般的方法好像不行(100分)

  • 主题发起人 主题发起人 步惊云
  • 开始时间 开始时间

步惊云

Unregistered / Unconfirmed
GUEST, unregistred user!
在form中:
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;
const
USER_COTENTCHANGED=WM_USER+1;
type
TForm1 = class(TForm)
private
{ Private declarations }
procedure ContentChanged(var msg:TMessage); message USER_COTENTCHANGED;//说明消息处理过程,过程名任意
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.DFM}
procedure TForm1.ContentChanged(var msg:TMessage);//消息处理实现
begin

end;
end.

在frame中
用SendMessage(Application.Handle, USER_COTENTCHANGED, 0, 0);

form中无法收到该消息,不知是何缘故?
 
SendMessage(Form1.Handle, USER_COTENTCHANGED, 0, 0);
 
消息没试过,我只试过关闭

var
Aparent: Tcomponent; ///查找当前框架的拥有Form对象
begin
Aparent := Tcomponent(sender).getparentcomponent;
///查找当前框架的拥有Form对象
while not (Aparent is Tcustomform) do
Aparent := Aparent.getparentcomponent; ///查找当前框架的拥有Form对象
Tcustomform(Aparent).close; ///关闭拥有Form对象
end;
 
把上边的Aparent.handle取出来
SendMessage应该就行了
 
ok, 照ysai的方法可以了。 我想知道为什么对frame来说用 Application.Handle 不行,要用
Form1.Handle才可以呢? Form1正是程序的主窗口啊。
 
DELPHI程序隐藏了一个对象,既Application
任务栏上的按钮就是Application窗体,而不是MainForm
发往Application的消息不一定会被MainForm收到,
而自定义消息一定不会,除非加一行:
//DPR文件中
Application.OnMessage := MDIMainForm.AppMessageHandler;
//MDIMainForm.AppMessageHandler为主窗体中处理应用程序窗体的过程,声明如下
procedure TMDIMainForm.AppMessageHandler(var Msg:TMsg;var Handled:boolean);
这样就可以拦截发住应用程序的消息了
http://www.delphibbs.com/delphibbs/dispq.asp?lid=1566476
 
接受答案了.
 

Similar threads

I
回复
0
查看
800
import
I
S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
769
SUNSTONE的Delphi笔记
S
后退
顶部