从Word OLE应用程序对象获取应用程序标题 [英] Getting application title from a Word OLE application object
问题描述
FindWindow
获取窗口。 我正在创建一个OLE对象并添加现有文档,如下所示:
App:= CreateOLEObject('Word.Application');
App.Visible:= True;
App.Activate;
Doc:= App.Documents.Open('File.doc');
此时,标题值如下:
App.Caption => 'Microsoft Word'
Doc.ActiveWindow.Caption => 'File.doc [兼容模式]'
但是,窗口标题实际上是 File.doc [兼容模式] - Microsoft Word
。
有没有办法从OLE对象获取此窗口标题(有没有使用 FindWindow
)而不是更好地获取HWND本身?我怀疑这个窗口标题永远是< doc caption> - < app caption>
。
我想使用 FindWindow
功能来获取窗口的句柄,以使其能够前进(参见。
EDIT
以下是使用 http://support.microsoft.com/kb/258511
App:= CreateOLEObject ('Word.Application');
//获取句柄
TempTitle:='Temp - '+ IntToStr(Random(1000000));
App.Caption:= TempTitle;
句柄:= FindWindow('OpusApp',PWideChar(TempTitle));
App.Caption:= EmptyStr;
App.Visible:= True;
App.Activate;
Doc:= App.Documents.Open('File.doc');
//带前端
SetForegroundWindow(Handle);
这是你要找的?
Is there a way of getting the window title from a Word.Application OLE object? I'd like to use it to try get the window using FindWindow
.
I'm creating an OLE object and adding an existing document, like so:
App := CreateOLEObject('Word.Application');
App.Visible := True;
App.Activate;
Doc := App.Documents.Open('File.doc');
At this point, the caption values are the following:
App.Caption => 'Microsoft Word'
Doc.ActiveWindow.Caption => 'File.doc [Compatibility Mode]'
However, the window title is actually File.doc [Compatibility Mode] - Microsoft Word
.
Is there some way of getting this window title from the OLE object (there does not seem to be a better way of getting the HWND itself without using FindWindow
)? I doubt it is safe to assume the window title will always be <doc caption> - <app caption>
.
I'd like to use the FindWindow
function to get a handle to the window to be able to bring it to the foreground (see OLE Automation to launch MS Word and bring to front) in a slightly safer manner by passing in the correct title.
EDIT
Here's the fix using the workaround described in http://support.microsoft.com/kb/258511
App := CreateOLEObject('Word.Application');
// get the handle
TempTitle := 'Temp - ' + IntToStr(Random(1000000));
App.Caption := TempTitle;
Handle := FindWindow('OpusApp', PWideChar(TempTitle));
App.Caption := EmptyStr;
App.Visible := True;
App.Activate;
Doc := App.Documents.Open('File.doc');
// bring to front
SetForegroundWindow(Handle);
Is this what you are looking for?
How to obtain the window handle for an Office Automation server
这篇关于从Word OLE应用程序对象获取应用程序标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!