Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Bringing Excel window forward
Message
From
25/10/2019 18:19:17
 
 
To
25/10/2019 17:55:21
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
01671640
Message ID:
01671697
Views:
60
>Still having trouble with this - I can indeed bring forward a Word window but I actually want to bring forward the document that has just been created. So instead of referencing the Word instance, I tried to change the caption, which is actually called .Name but found out it is read-only. And then I found out that unlike Excel, Word will open 2 documents of the same name - so by rights it would be better if the window name was unique. Any thoughts?

I think you're working mostly with non-root objects. You need the root object to get this to work. The word.application object has a property called "Caption".

The code I gave you worked on my computer with Microsoft Office 365.

>Going to shut down for the day soon anyhow but if you have any, might poke at it again tomorrow.
>Thanks for all your help.
>Albert
>
>>>Hi Rick,
>>>
>>>Works great for Excel but for Word, it does not seem to have an .hwnd property on the application. I poked around the object but could not find it.
>>
>>
>>Yeah, Microsoft has never exposed the HWND on Word.application. So, you have to find it another way:
>>
>>
lo = CREATEOBJECT("word.application")
>>lo.Visible = .t.
>>
>>DECLARE INTEGER FindWindow IN WIN32API STRING cClass, STRING cName
>>lcOldCaption = lo.Caption
>>lcNewCaption = SYS(2023) + "Changed to something unique momentarily to find only me"
>>lo.Caption = lcNewCaption
>>lnHwnd = FindWindow(NULL, lcNewCaption)
>>lo.Caption = lcNewCaption
>>
>>* Use lnHwnd like normal in the Excel example
>>
>>>>>Hi Rick,
>>>>>How do I get an hwnd handle to an Excel object? I got an error loWorkbook.HWnd. Do I have to do another function call to get the handle from the OS?
>>>>
>>>>The example I included in my OP worked for me from the command prompt. Make sure you're using the root Excel.Application object, and not an object reference from something deeper. You may also be able to reference it contextually from a lower object using loWorkbook.parent.parent.HWnd or something along those lines. Never tried it.
>>>>
>>>>>>>Hi,
>>>>>>>
>>>>>>>Can someone post code as to how to bring an Excel window forward using api calls? My current code creates an Excel document, inserts all the data and then uses .Activate() which just activates it on the toolbar so that it is flashing - it does not actually bring it forward. I figure Win api calls would need to be used to do this.
>>>>>>>
>>>>>>>I have looked in the VFP Office automation book but the constants used are old and figure someone might have a nice function to do this.
>>>>>>
>>>>>>
lo = CREATEOBJECT("Excel.Application")
>>>>>>lo.visible = .t.
>>>>>>
>>>>>>DECLARE INTEGER BringWindowToTop IN WIN32API INTEGER hWnd
>>>>>>DECLARE INTEGER ShowWindow       IN WIN32API INTEGER hWnd, LONG nCmdShow
>>>>>>
>>>>>>ShowWindow(lo.HWnd, 1)
>>>>>>BringWindowToTop(lo.HWnd)
>>>>>>
>>>>>>Works with any window you can get an HWnd to (thisForm, _screen, etc.).
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform