Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Is there a better kludge for SetForegroundWindow?
Message
 
To
All
General information
Forum:
Visual FoxPro
Category:
Windows API functions
Title:
Is there a better kludge for SetForegroundWindow?
Miscellaneous
Thread ID:
00671245
Message ID:
00671245
Views:
61
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
Montage

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

Click here to load this message in the networking platform