>Running under Win2K Pro with either VFP6 or VFP7, the following program demonstrates that the SetForegroundWindow API function fails to restore the focus to the main VFP window:
>
>
>set library to (home()+'foxtools.fll')
>myhwnd = MainHwnd()
>run /n explorer.exe /e,/select,c:\
>
>* pause long enough for the Explorer window to open
>DECLARE Sleep IN kernel32 INTEGER dwMilliseconds
>sleep(500)
>
>DECLARE INTEGER SetForegroundWindow IN user32 INTEGER hwnd
>? SetForegroundWindow(m.myhwnd)
>
>
>Instead of activating the VFP window at this point, its taskbar button starts flashing. I've tried lots of programmatic ways to get the focus to return to VFP, and the "best" I've been able to do so far is to use the following kludge instead of SetForegroundWindow:
>
>
>#define SW_MINIMIZE 6
>#define SW_RESTORE 9
>DECLARE INTEGER ShowWindow IN WIN32API INTEGER, INTEGER
>? ShowWindow (m.myhwnd, SW_MINIMIZE)
>? ShowWindow (m.myhwnd, SW_RESTORE)
>
>
>This works, but obviously it's a rather clunky approach. A search of Google Groups for "SetForegroundWindow" yields a huge number of hits about similar problems. I picked up the ShowWindow MINIMIZE/RESTORE hack from one of these threads, but it's exhausting to wade through all of these references. Has anyone found a better solution that would work for this example under Windows 2000? Please test to confirm if you think so. TIA for any help.
>
>Mike
I came upon another approach for self reactivating using the WSH:
WSHShell = CreateObject("WScript.Shell")
WSHShell.AppActivate(_screen.Caption)
HTH
Zlatin Zlatev,
MCSD (VS6)Make solutions, not programs!