Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Spell checking in Visual FoxPro using Word - Word spellcheck dialogue box won't come to foreground 1

Status
Not open for further replies.

wtotten

IS-IT--Management
Apr 10, 2002
181
US
Hi,

I used the sample code from this Tek-tips posting ( about using Word to spellcheck from within a VFP application. If I run it on XP, the Word spellcheck dialog box appears in the foreground. However, if I run it on Windows 7, it doesn't come to the foreground. I have to Alt+Tab over to it to see it. I need some help in getting this resolved please - so it comes to the foreground in Windows 7 (I'm not really worried about Windows 8 or 10 for now).

Thank you,
Bill
 
Just so you can try out SetForegroundWindow:

Code:
* Prerequisite: goWordDoc is a Word Doc object you got from Documents.Add()
DECLARE INTEGER SetForegroundWindow IN user32 INTEGER hwnd

Local lnHwnd
lnHwnd = goWordDoc.Windows.Item(1).Hwnd
SetForegroundWindow(lnHwnd)

Do this somewhere before calling .CHECKSPELLING() and of course after the goWordDoc was created.

Bye, Olaf.

PS: All Windows API declarations for VFP and many sample usages are available at the very well known site
 
Olaf,

Thank you very much for your help. What you provided worked.
* Prerequisite: goWordDoc is a Word Doc object you got from Documents.Add()
DECLARE INTEGER SetForegroundWindow IN user32 INTEGER hwnd

Local lnHwnd
lnHwnd = goWordDoc.Windows.Item(1).Hwnd
SetForegroundWindow(lnHwnd)


Thank you for the code and for the link to the API web site.
Bill
 
Mike,

Thanks for the info on Meaning Cloud. Looks interesting. Olaf's answer solved this particular problem.

Bill
 
Olaf,

I ran into a problem. I used your code:
* Prerequisite: goWordDoc is a Word Doc object you got from Documents.Add()
DECLARE INTEGER SetForegroundWindow IN user32 INTEGER hwnd

Local lnHwnd
lnHwnd = goWordDoc.Windows.Item(1).Hwnd
SetForegroundWindow(lnHwnd)

I tested it on a computer that has Word 2013 and it worked fine. I then tried it on a computer running Word 2007 and it fails. The line that fails is:
lnHwnd = goWordDoc.Windows.Item(1).Hwnd

There is no .Hwnd property for the goWordDoc.Windows.Item(1) object. Since I am frankly clueless how the logic and syntax of this Win API works I don't know how else to get this to work for other versions of Word (in this case I need it to work for Word 2007). Can you help?

Thank you,
Bill
 
Your problem is not about Windows API, but the ever changing Word object model. If there is no hwnd property, you have to use FindWindow with the caption of word, eg Document1.

DECLARE INTEGER FindWindow IN user32;
STRING lpClassName,;
STRING lpWindowName
lnHwnd = FindWindow(.NULL.,'Document1')

You may also find the caption in goWordDoc.Windows.Item(1).Caption. You know, different Office versions, different object models and different behaviour.

Bye, Olaf.
 
Olaf,

Thanks for this. I appreciate the help very much.

Bill
 
Olaf,

Is there a method (a way) for me to name the document when I Add() it? That way when I look for the caption I'll be sure that I'm working with the proper document?

thank you,
Bill
 
Well, I can't tell for Word2007. You can set goWordDoc.Windows.Item(1).Caption = Sys(2015) and then FindWindow(.NULL.,oDoc.Windows.Item(1).Caption+" - Word"), but when you have that you also could take hwnd.
To be sure you have the right hwnd you'd need to iterate all windows before adding a new doc, then add a doc and again iterate all windows to see which is the newest.

Bye, Olaf.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top