>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
>
>SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT, 0, (LPVOID)0, SPIF_SENDWININICHANGE | SPIF_UPDATEINIFILE);
>
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)>
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) && restoreThe 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.