开发者

Getting application title from a Word OLE application object

开发者 https://www.devze.com 2023-04-10 21:55 出处:网络
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.

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 c开发者_如何学JAVAaption>.

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

0

精彩评论

暂无评论...
验证码 换一张
取 消