Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Is there a better kludge for SetForegroundWindow?
Message
De
03/07/2002 06:46:43
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Fonctions Windows API
Divers
Thread ID:
00671245
Message ID:
00674879
Vues:
21
>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
Zlatin Zlatev,
MCSD (VS6)

Make solutions, not programs!

Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform