Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
FindWindow() vs FindWindowA().... Handle for word app se
Message
From
28/03/2001 14:39:13
 
 
To
27/03/2001 03:59:54
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
General information
Forum:
Visual FoxPro
Category:
COM/DCOM and OLE Automation
Miscellaneous
Thread ID:
00488612
Message ID:
00489584
Views:
1128
Hi Cetin,

Turn the volumn up on your computer so you can hear the ding when the messagebox comes up. Now run the code below. Open a new document when WORD comes up and then click on format|font. Allow the font dialog to stay on the screen for 20 to 50 seconds. You won't get an ole busy error but you will fall out of the sleep loop. You will hear the ding of the vfp messagebox that proves it.

Any thoughts?

Dr. G. (Neil)


application.OLEServerBusyRaiseError = .T.

declare Sleep in win32API integer

** create WORD server
oo = createobject("word.application")
oo.visible = .t.
oo.windowstate = 1
oo.activate

do while type('oo.DisplayRecentFiles')#'U'
=Sleep(1000) && Do nothing for 1 sec
enddo
do returnme
messagebox("You closed WORD")
oo = .null.
release oo
messagebox("Automation Reference Is Gone")

procedure returnme
messagebox("You are in Procedure: Returnme")



>Neil,
>Since this is now on UT let's continue here :)
>As George explained it wouldn't make a difference on the result if you used FindWindow() or FindWindowA() (I suggest FindWindow() for it maps to A or W).
>In the original code I sent it's assumed that there is a document window. Otherwise title is just 'Microsoft Word' :
>
declare integer FindWindow in win32API string @ cClass, string @ cTitle
>oword = CREATEOBJECT("Word.Application")
>with oWord
>	.visible = .t.
>	.activate
>	hWnd = FindWindow(0,'Microsoft Word')
>        ? hWnd
>endwith
>However this is same as saying FindWindow('OpusApp',0). Null is not the trick because just specifying classname or a title like 'Microsoft Word' you have no way to be sure that the window you found is the one you created. (BTW getobject() wouldn't help either). With only one word app active in the system it would work. Otherwise it is like saying :
>
dimension myArray[3]
>myArray[1]=1
>myArray[2]=2
>myArray[3]=3
>? myArray
Where you always get the first element found. There are alternative APIs but they need callback functions not supported in VFP (you'd need FLL or another 3rd party versions to use them).
>With word this thing is complex because unlike Excel and other apps Word spawns only one process for multipl word launches. If you already have a word session (say user launched independently from your app and you launch your own) and your session is closed hWnd (IsWindow(hWnd)) still hangs out there till first launch is closed. If you check title for hWnd however you'd get "". As George said you could observe this with Spy++ tool.
>If you get your handle after there is a doc hence title than it's OK. There is one thing you should be carefull here though. If a doc is already opened you could get it readonly in your call thus causing (readonly) embedded in the title. If you fail to check that you'd get handle to other session.
>
>Actually though I still support oWord.DisplayRecentFiles checking and sleeping in between. OLEServerBusyRaiseError=.T. prevents error in VFP if any modal dialog in word is activated. I don't remember if we were discussing this code portion with you so I provide it here again :
>
application.OLEServerBusyRaiseError = .T.
>
>declare Sleep in win32API integer
>
>** create WORD server
>oo = createobject("word.application")
>oo.visible = .t.
>oo.windowstate = 1
>oo.activate
>
>do while type('oo.DisplayRecentFiles')#'U'
>   =Sleep(1000) && Do nothing for 1 sec
>enddo
>do returnme
>messagebox("You closed WORD")
>oo = .null.
>release oo
>messagebox("Automation Reference Is Gone")
>
>procedure returnme
>messagebox("You are in Procedure: Returnme")
Cetin
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform