General information
Category:
COM/DCOM and OLE Automation
Hi George,
Thanx for jumping in. This is what I found.
** instantiate WORD automation
oWord=createobj("word.application")
** get a handle to the word application server.
oWordHandle = FindWindowA("OpusApp", NULL) && null is the trick
Now that I have the handle on the server, I can do use a host of API calls. The reason why I wanted this predicatable method of getting a handle on the server is this. While waiting for WORD to come up on the desktop, a grumpy user could start clicking on things like icons and then something like GetForeGroundWindow() might not reliably give me WORD'S handle. FindWindowA() works great and is just what I needed.
Thanx
Again
DR. G. (Neil)
>>Hi Cetin,
>>I posted this email to UT so everyone can benefit.
>>
>>
>>Thank you for your response. I ran the following code:
>>declare integer FindWindow in win32API string @ cClass, string @ cTitle
>>
>>oword = CREATEOBJECT("Word.Application")
>>with oWord
>> .documents.add
>> .Activedocument.SaveAs('c:\My documents\A long filename word document')
>> .visible = .t.
>> .activate
>> lcDocName = .ActiveDocument.Fullname
>> if at('\',lcDocName)>0 && If has path info too
>> lcDocName = substr(lcDocName,rat('\',lcDocName)+1)
>> endif
>> hWnd = FindWindow(0,lcDocName+' - Microsoft Word')
>> ? lcDocName,hWnd
>>endwith
>>
>>When I closed WORD the hWnd variable was displayed as 0 not a valid handle. Did I misunderstand something? I also have another question.
>>
>>Doesn't FindWindow() return a handle on a WORD document's window and FindWindowA() return a handle on the server application's window ie:WORD?
>>If we used FindWindowA(), instead of FindWindow(), it wouldn't matter what the name of the active document was.
>>
>>Page 180 of Tamars' Book discusses FindWindowA(), not FindWindow(), with the Class for WORD = OpusApp.
>>But FindWindowA("OpusApp", oword.caption) returns .T. Either the class of OpusApp is wrong or I am missing something.
>>
>>Any thoughts ?
>>regards,
>>
>Dr.G. (Neil),
>
>Nope OpusApp is correct for the window frame, but not the document. When you instantiate a Word.Application, of course, there's no document window.
>
>As for FindWindowA(), it is the same function as FindWindow(). Many functions that return strings come in two flavors A and W (and I don't mean root beer, either< g >). The A versions are regular ASCII. The W version are for Unicode character sets. Which is being used depends on the localized version of Windows.
>
>One suggestion. If you have access to the complete Visual Studio, there's a tool named Spy++. If you play around with that and Word you'll probably find some new stuff out.
Previous
Next
Reply
View the map of this thread
View the map of this thread starting from this message only
View all messages of this thread
View all messages of this thread starting from this message only