Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How can I close an another program?
Message
De
14/07/2000 08:52:34
 
 
À
14/07/2000 08:43:04
Information générale
Forum:
Visual FoxPro
Catégorie:
Fonctions Windows API
Divers
Thread ID:
00392323
Message ID:
00392327
Vues:
11
>Hi All,
>
>Suppose I run Notepad and it gives the window title as "Untitled - Notepad". If I call the below program
> CloseProgram("Untitled - Notepad")
>it does not close the notepad. Could anyone please explain the reason?
>

GetWindow as you're using it will only close child Windows of the current Desktop window. It will find at most one occurance, and not that if the Window in question is not active.

You'd be better off using the Wscript.Shell's AppActivate to bring the desired application to the active state and its SendKeys method to send whatever keystrokes were needed to shut down the application; it's documented in the help for the Windows Scripting Host as pointed to in my signature block.

>********
>
FUNCTION CloseProgram
>LPARAMETERS cWindowName
>Local hMainWnd, hWnd, cWindowTitle
>#define GW_CHILD 5
>#define GW_HWNDNEXT 2
>#define CRLF Chr(13)+Chr(10)
>
>DECLARE INTEGER GetDesktopWindow IN WIN32API
>DECLARE INTEGER GetWindow IN WIN32API INTEGER, INTEGER
>DECLARE INTEGER GetWindowText IN WIN32API INTEGER, STRING, INTEGER
>DECLARE INTEGER IsWindowVisible IN WIN32API INTEGER
>DECLARE INTEGER SetForegroundWindow IN WIN32API INTEGER
>DECLARE INTEGER DestroyWindow IN WIN32API INTEGER
>
>hMainWnd = GetDesktopWindow()
>hWnd = GetWindow(hMainWnd, GW_CHILD)
>Do While hWnd > 0
>   If IsWindowVisible(hWnd) <> 0
>      cWindowTitle = Space(100)
>      GetWindowText(hWnd, @cWindowTitle, 100)
>      cWindowTitle = Trim(cWindowTitle)
>      cWindowTitle = Left(cWindowTitle, Len(cWindowTitle)-1)
>      If Upper(cWindowName) $ Upper(cWindowTitle)
>         =DestroyWindow(hwndNext)
>         Exit
>      EndIf
>    EndIf
>    hWnd = GetWindow(hWnd, GW_HWNDNEXT)
>EndDo
>ENDFUNC
>***************
>
>I even tried below
>
>
=SetForegroundWindow(hwndNext)
>Keyboard '{ALT+F4}'
>*****************
>This one closes my program only :-) What am I missing here? Thanks for your valuable time and response.
>
>Regards
>Vijay
EMail: EdR@edrauh.com
"See, the sun is going down..."
"No, the horizon is moving up!"
- Firesign Theater


NT and Win2K FAQ .. cWashington WSH/ADSI/WMI site
MS WSH site ........... WSH FAQ Site
Wrox Press .............. Win32 Scripting Journal
eSolutions Services, LLC

The Surgeon General has determined that prolonged exposure to the Windows Script Host may be addictive to laboratory mice and codemonkeys
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform