Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Is there a better kludge for SetForegroundWindow?
Message
 
To
03/07/2002 06:46:43
General information
Forum:
Visual FoxPro
Category:
Windows API functions
Miscellaneous
Thread ID:
00671245
Message ID:
00675231
Views:
28
>>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')  && for use of MainHwnd()
>>myhwnd = MainHwnd()                     && obtain HWND for VFP main window
>>run /n explorer.exe /e,/select,c:\      && launch Explorer against 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)         && try to bring VFP back to foreground
>>
>>
>>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)    && minimize the VFP window
>>? ShowWindow (m.myhwnd, SW_RESTORE)     && restore to normal zoom state
>>
>>
>>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

It was a good thought, Zlatin. I had meant to try out the WSH approach, but forgot about that one. Unfortunately, my test under Win2K Pro indicates that this does not work: it just produces the flashing taskbar button.

I've also discovered that one doesn't need to resort to API calls, since the following equivalent kludge does work:
_screen.windowstate = 1			&& minimized
_screen.windowstate = 0			&& normal
That still leaves me looking for a better solution, though. Thanks for giving it another try.

Mike
Montage

"Free at last..."
Previous
Reply
Map
View

Click here to load this message in the networking platform