Title bar in embedded word document not responsive
I want to embed a word application in a form of my program. I am using the following code:
procedure TAMainForm.Button1Click(Sender: TObject);
var
WordApp: Variant;
WordHandle: THandle;
TempTitle: string;
begin
WordApp := CreateOleObject('Word.Application');
TempTitle := 'Temp - ' + IntToStr(Random(1000000));
WordApp.Caption := TempTitle;
WordHandle := FindWindow(nil, PChar(TempTitle));
WordApp.Visible := True;
Windows.SetParent(WordHandle, Handle);
SetWindowPos(WordHandle, 0, Left+20, Top+50, 700, 500, SWP_ASYNCWINDOWPOS);
end;
It puts word into my form all right and It seems to works ok. However the title bar of the word application is all black and does not respond to mouse clicks. What is wrong with my code?
Having a cross-process parent-child relationship of windows might technically be legal to do, but it is very difficult to manage and would require both processes involved to be aware of this situation. This is explained in detail by Raymond Chen in his blog post Is it legal to have a cross-process parent/child or owner/owned window relationship? Such a cross-process relationship is likely the cause of the problem you are facing.
If you are trying to achieve that your form stays on top of Word, you may implement a workaround based on the Application.WindowActivate
event. Whenever the Word window is activated you can bring your own form to the top, eg using SetWindowPos
.
上一篇: 将Word OLE对象转换为Word表
下一篇: 嵌入式文档中的标题栏无法响应