动态创建的WebBrowser显示不出来。

同桌老王 2003-10-17 09:07:19
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, IdBaseComponent, IdComponent, IdTCPConnection,
IdTCPClient, IdHTTP, OleCtrls, SHDocVw;
type
TMyWebBrowser = class(TWebBrowser)
public
procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); dynamic;

end;
type
TForm1 = class(TForm)
procedure FormShow(Sender: TObject);
procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
private
{ Private declarations }


public
{ Public declarations }
end;

var
Form1: TForm1;
web2:TMyWebBrowser;
implementation

{$R *.dfm}

procedure TForm1.FormShow(Sender: TObject);
begin
web2:=TMyWebBrowser.CreateParented(Form1.Handle);
web2.Left:=100;
web2.Top:=12;
web2.Width:=300;
web2.Height:=300;
web2.Visible:=True;
web2.Align:= alClient;
web2.Show;
web2.Navigate('http://www.sina.com.cn');

end;

procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
Application.MessageBox('sss','sss',0);
end;


procedure TMyWebBrowser.MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
ShowMessage('ok');
end;
end.
...全文
175 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
halfdream 2003-11-08
  • 打赏
  • 举报
回复
VCL 控件设计思路是将子控件接收到的消息事件一层层主动向父控件传递通知.
而封装的ACTIVEX则例外,它一般不会按照VCL的规则通知父控件,
解决思路一般是主动抢先截获消息.用TapplicationEvent在消息事件里面处理
就可以了.


dickeybird888 2003-11-07
  • 打赏
  • 举报
回复
(··)
linzhisong 2003-11-07
  • 打赏
  • 举报
回复
这种要用applicationEven接受就可以了!
同桌老王 2003-10-17
  • 打赏
  • 举报
回复
那个问题已经解决了,不过有新的问题:
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, IdBaseComponent, IdComponent, IdTCPConnection,
IdTCPClient, IdHTTP, OleCtrls, SHDocVw,StdCtrls;
type
TMyButton = class (TButton)
end;
type
TMyWebBrowser = class(TWebBrowser)
public
procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); dynamic;

end;
type
TForm1 = class(TForm)
IdHTTP1: TIdHTTP;
procedure FormShow(Sender: TObject);
procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure mmm(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);

private
{ Private declarations }


public
{ Public declarations }
end;

var
Form1: TForm1;
web2:TMyWebBrowser;
btn:TMyButton;
btn2:TButton;
implementation

{$R *.dfm}

procedure TForm1.FormShow(Sender: TObject);
begin

web2:=TMyWebBrowser.Create(nil);
web2.Left:=100;
web2.Top:=12;
web2.Width:=300;
web2.Height:=300;
web2.Visible:=True;
web2.Align:= alClient;
web2.SetParent(Form1);
web2.OnMouseDown:=mmm;
web2.OnClick:=nil;
web2.Show;
web2.Navigate('http://chartse.stockstar.com/special?module=chartserver&proc=aindex');


end;
procedure TForm1.mmm(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
showmessage('ookk');
end;
procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
Application.MessageBox('sss','sss',0);
end;


procedure TMyWebBrowser.MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
ShowMessage('ok');
end;
end.
为什么以上的code的目的: 接管鼠标按键不起作用?
linzhisong 2003-10-17
  • 打赏
  • 举报
回复
web2:=TMyWebBrowser.CreateParented(Form1.Handle);
换成这个试试
web2:=TMyWebBrowser.create(self);
web2.parent:=self;

5,379

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧