Retrieving an Application Header from a Word OLE Application Object

Is there a way to get the window title from a Word.Application OLE object? I would like to use it to try to get a window using FindWindow .

I create an OLE object and add an existing document, for example:

 App := CreateOLEObject('Word.Application'); App.Visible := True; App.Activate; Doc := App.Documents.Open('File.doc'); 

At this point, the header values ​​are as follows:

 App.Caption => 'Microsoft Word' Doc.ActiveWindow.Caption => 'File.doc [Compatibility Mode]' 

However, the window name is actually File.doc [Compatibility Mode] - Microsoft Word .

Is there a way to get this window title from an OLE object (there seems to be no better way to get HWND without using FindWindow )? I doubt it is safe to assume that the window title will always be <doc caption> - <app caption> .

I would like to use the FindWindow function to get a window handle to bring it to the foreground (see OLE Automation to launch MS Word and bring to the foreground ) in a slightly more secure way by going to the correct name.

EDIT

Here's a fix that uses the workaround described at 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); 
+7
source share
1 answer
+3
source

All Articles