Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Bringing Excel window forward
Message
From
25/10/2019 16:21:50
 
 
To
25/10/2019 16:05:39
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
01671640
Message ID:
01671694
Views:
54
>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