Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How can I close an another program?
Message
From
14/07/2000 08:43:04
 
 
To
All
General information
Forum:
Visual FoxPro
Category:
Windows API functions
Title:
How can I close an another program?
Miscellaneous
Thread ID:
00392323
Message ID:
00392323
Views:
55
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?

********
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
Next
Reply
Map
View

Click here to load this message in the networking platform