Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
FindWindow() vs FindWindowA().... Handle for word app se
Message
De
27/03/2001 03:59:54
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
 
À
26/03/2001 17:09:13
Information générale
Forum:
Visual FoxPro
Catégorie:
COM/DCOM et OLE Automation
Divers
Thread ID:
00488612
Message ID:
00488869
Vues:
42
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
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform