Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
WORD automation and busy signals
Message
From
15/01/2001 21:39:31
 
 
To
15/01/2001 19:18:23
John Ryan
Captain-Cooker Appreciation Society
Taumata Whakatangi ..., New Zealand
General information
Forum:
Visual FoxPro
Category:
COM/DCOM and OLE Automation
Miscellaneous
Thread ID:
00463296
Message ID:
00464040
Views:
25
>Ed
>
>Thanks for the reply!
>
>The plot thickens.
>
>SetForegroundWindow() only works for Word if a document is open!
>
>I'm going to < gasp > post the code...
>
>
>Procedure MakeWordComeToTheFront
>
>if type('pgHwndWord')="U"
>  DECLARE integer GetForegroundWindow in WIN32API
>  DECLARE integer SetForegroundWindow in WIN32API integer
>  DECLARE short IsWindow in WIN32API integer
>  public pgHwndWord,poWordApplication
>endif
>
>if empty(pgHwndWord) or ! iswindow(pgHwndWord)
>
>  ** create WORD server
>  poWordApplication= createobject("word.application")
>  poWordApplication.visible = .t.
>  ** maximize WORD
>  poWordApplication.windowstate = 1
>  poWordApplication.activate
>

This does not guarentee that Word is the Foreground window, especially if something else has a modal UI object in effect; you'd be better off setting the caption of the Windows document window to a distinct, known value on a temporary basis, and using FindWindow() to grab the hWnd based on the caption text. I'm not an expert on Word automation by any stretch, but I suspect that either the Word.Application or Word.Document object has a hook to the hWnd; both have a Windows collection and an ActiveWindow property that might be used to reveal a useful hWnd.

>  pgHwndWord = GetForegroundWindow() && Save word window handle
>else
>  SetForegroundWindow(pgHwndWord)
>endif
>

>
>Yeah, in "real life" all those publics are object properties.
>
>If you try it, Word only comes to the front if you have a document open.
>
>Looking at http://msdn.microsoft.com/library/psdk/winui/windows_1eev.htm I see that this flashing business is the default behaviour- it calls SetActiveWindow() and FlashWindowEx() if the user is using another window which they are by default in an app. Apparently at application install time you can alter the behaviour using
>
>
>SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT, 0, (LPVOID)0, SPIF_SENDWININICHANGE | SPIF_UPDATEINIFILE);
>



I've gotten some interesting behavior under Win2K out of:
DECLARE INTEGER SystemParametersInfo IN win32api ;
   integer, integer, integer, integer
*  At times, the third parameter pvVoid is used as a pointer, so it would
*  need to be declared INTEGER @ or STRING @ instead.  Read MSDN docs for
*  exact details based on the action requested by uiAction, the 1st parameter

#DEFINE SPI_SETACTIVEWINDOWTRACKING 0x1001  && pop window on active
#DEFINE SPI_SETACTIVEWNDTRKZORDER 0x100D    && select foreground by mouseover
#DEFINE SPIF_SENDWININICHANGE 2             && notify other Windows of change

=SystemParametersInfo(SPI_SETACTIVEWINDOWTRACKING, 0, 1, SPIF_SENDWININICHANGE)
=SystemParametersInfo(SPI_SETACTIVEWNDTRKZORDER, 0, 1, SPIF_SENDWININICHANGE)
SUSPEND
* Help now pops rather than flashes, although behind VFP, and sliding the mouse
* over an activatable Window brings it to foreground and activates it.  It is a
* useful effect for me running two monitors but will definitely confuse the
* masses.  The normal settings and behaviors are restored by:
=SystemParametersInfo(SPI_SETACTIVEWINDOWTRACKING, 0, 0, SPIF_SENDWININICHANGE)
=SystemParametersInfo(SPI_SETACTIVEWNDTRKZORDER, 0, 0, SPIF_SENDWININICHANGE)
>
>I'm afraid this is much too complex for me, so can you tell me whether this is something I can do easily using the VFP install Wizard or is this something clever? Or can I run it somehow from my app?
>

Your call requires the indirected version of my DECLARE for the call above and the #DEFINEs provided in WINUSER.H, would read:
DECLARE INTEGER SystemParametersInfo IN win32api ;
   integer, integer, integer @, integer
#DEFINE SPI_SETFOREGROUNDLOCKTIMEOUT 0x2001 && Set Foreground lockout timeout
#DEFINE SPI_GETFOREGROUNDLOCKTIMEOUT 0x2000 && Get Foreground lockout timeout
#DEFINE SPIF_SENDWININICHANGE 2             && notify other Windows of change
#DEFINE SPIF_UPDATEINIFILE 1                && write change to ini/registry
nTimeOut = 0
=SystemParametersInfo(SPI_GETFOREGROUNDLOCKTIMEOUT, ;
                      0, ;
                      @nTimeOut, ;
                      0)  && save current setting to nTimeOut

=SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT, ;
                      0, ;
                      0, ;
                      SPIF_SENDWININICHANGE + SPIF_UPDATEINIFILE) && set to 0

=SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT, ;
                      0, ;
                      nTimeOut, ;
                      SPIF_SENDWININICHANGE + SPIF_UPDATEINIFILE) && restore
The behavior seems similar to SPI_SETACTIVEWINDOWTRACKING set to 1, but I assume your source suggests using this instead. The last call resets the behavior to restore the value at startup, so it'd probably be in your shutdown code somewhere, and I'd probably actually stash the value somewhere I can retrieve it later, so if VFP crashes, I can restore the original setting from it's known storage point, but that's a personal preference - I wouldn't write the update to the INI file, either.
EMail: EdR@edrauh.com
"See, the sun is going down..."
"No, the horizon is moving up!"
- Firesign Theater


NT and Win2K FAQ .. cWashington WSH/ADSI/WMI site
MS WSH site ........... WSH FAQ Site
Wrox Press .............. Win32 Scripting Journal
eSolutions Services, LLC

The Surgeon General has determined that prolonged exposure to the Windows Script Host may be addictive to laboratory mice and codemonkeys
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform