delphi 将Word嵌入Delphi中


本文整理自网络,侵删。

 
unit Main;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls,Comobj;
type
TForm1 = class(TForm)
Panel1: TPanel;
Panel2: TPanel;
Label1: TLabel;
Button1: TButton;
Button2: TButton;
Button3: TButton;
procedure Panel1Resize(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
FComApp:OleVariant;
gWaveHwnd:Hwnd;
public
{ Public declarations }
procedure SetParentWindow(pParent: TWinControl);
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
{ TForm1 }
procedure TForm1.Button1Click(Sender: TObject);
var
Word : Variant;
begin
FComApp := CreateOLEObject('Word.Application');
FComApp.Documents.Open(extractfilepath(Application.ExeName)+'\test.doc',false);
FComApp.Visible := True;
Label1.Caption := FComApp.ActiveWindow.Caption;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
SetParentWindow(Panel1);
end;
procedure TForm1.Panel1Resize(Sender: TObject);
begin
if gWaveHwnd<>0 then
begin
FComApp.ActiveWindow.Height := Panel1.Height;
FComApp.ActiveWindow.Width := Panel1.Width;
Windows.MoveWindow(gWaveHwnd,0,0,Panel1.Width,Panel1.Height,false);
end;
end;
procedure TForm1.SetParentWindow(pParent: TWinControl);
var
lWaveHwnd : Hwnd;
lWidth, lHeight: Integer;
lWindowCaption: String;
begin
//lwaveHwnd := FindWindow(nil,'Microsoft Word');//窗口标题
lWindowCaption := FComApp.ActiveWindow.Caption;
lwaveHwnd := FindWindow(nil,pAnsiChar(lWindowCaption+' - Microsoft Word'));//窗口标题
//lwaveHwnd := FindWindowW(nil,pWideChar(String(FComApp.ActiveWindow.Caption)));//窗口标题
Windows.SetWindowLong(lWaveHwnd,GWL_STYLE,GetWindowLong(lWaveHwnd, GWL_STYLE)
and not (WS_CAPTION or WS_SYSMENU));
Windows.SetParent(lWaveHwnd,pParent.Handle);
gWaveHwnd:=lWaveHwnd;
lWidth := pParent.Width;
lHeight := pParent.Height;
Windows.MoveWindow(lWaveHwnd,0,0,lWidth,lHeight,false);
//mParent := pParent;
end;
end.

出处http://bigpower.blog.51cto.com/209892/90287

相关阅读 >>

Delphi 下载函数

Delphi整理五(枚举、子界、集合)

Delphi 通过wmi获取u盘硬件特征码

Delphi2010 图片格式转换bmp, png,jpeg, gif, tiff , wmphoto

Delphi tnethttpclient https忽略证书验证

Delphi setpriorityclass 设置当前程序的优先级

Delphi中单独编译pas生成dcu文件

Delphi 分解时间 �cdecodedate、decodetime … decodedatetime …

Delphi读写utf-8、unicode格式文本文件

Delphi在combobox下拉框里显示图片

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...