Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
API Function to detect and close a program?
Message
General information
Forum:
Visual FoxPro
Category:
Windows API functions
Miscellaneous
Thread ID:
00068236
Message ID:
00068302
Views:
28
>>>>I am trying to write some functions in VFP 5.0 to set up an OLE session with Novell's GroupWise 5 package. The program needs to be able to log into GroupWise using a specific email id, retrieve the messages for that id and process them. I've got code set up to do this, and it all works fine except for when GroupWise is already running with a different user's mailbox, or when Notify is running (a GroupWise program that runs in the Win95 system tray to watch for new messages).
>>>>
>>>>What I would like to know first of all, is if anybody knows of an API function that will detect both of these programs? I can find GroupWise using the FindWindow function, however, this does not work for Notify which exists only in the system tray. Ideally, does anyone know of a function that would return all running programs like you get when you press CTRL+ALT+DELETE?
>>>>
>>>>Second, once the programs have been detected, I would like to present a dialog box asking the user if he/she wants the detected GroupWise program to be closed. If the answer is yes, I want Foxpro to shut down the GroupWise program, and continue processing Once again, the ideal function here would be similar to pressing the "End Task" button in the Close Programs dialog when CTRL+ALT+DELETE is pressed.
>>>>
>>>>Any help will be greatly appreciated.
>>>>
>>>>Thanks in advance.
>>>>
>>>>- Eric Rolfe
>>>>erolfe@networkbta.com
>>>
>>>Eric,
>>>
>>>I've written a couple of functions which are available in the Files/Win32 & Other APIs section that will tell you if a particular application is running based on the known portion of the title bar.
>>>
>>>As to shutting down the application, that can be a rather tricky business. If the application was already active when VFP started up, I don't know if it's possible. The easiest way, if the application is DDE enabled, is to use that to tell it to shut itself down.
>>>
>>>hth,
>>>
>>>George
>>
>>George,
>>
>>Your functions work great for finding the main GroupWise application, but unfortunately, since the notify program runs only in the system tray, it doesn't have a window title that I can find. As to shutting down a program that's already active, I looked through the Win32 API Help File as Tony suggested, and found that I can shut down external programs by using the PostMessage function to send a WM_DESTROY message to the application I want to terminate. Using your IS_RUN32 function, the code is as follows:
>>
>>-------------
>>DECLARE INTEGER PostMessage IN WIN32API INTEGER WindowHandle, INTEGER Message, INTEGER Parameter1, INTEGER Parameter2
>>
>>lnHandle = IS_RUN32("GroupWise")
>>IF lnHandle > 0
>> PostMessage(lnHandle,2,0,0)
>>ENDIF
>>-------------
>>
>>The 2 is the numeric equivalent of WM_DESTROY. No parameters are necessary, so the zeros fill in the space.
>>
>>Thanks to you and Tony for the assistance in finding and closing the main GroupWise application. Now if I can only figure out how to take care of the system tray program, life will once again be good. :)
>>
>>- Eric Rolfe
>>erolfe@networkbta.com
>
>Eric,
>
>My thoughts along this line were to post a WM_QUIT message, which requires an application specific exit code. I must admit I'd be a bit wary of WM_DESTROY, however, if it works without any noticable side effects, terrific.
>
>hth,
>
>George

Actually, I had to go with WM_DESTROY because the WM_QUIT message caused Groupwise to throw an "Invalid Page Fault" error. I have no idea why, but it did. Maybe it didn't like the fact that it was getting the quit message externally.

- Eric Rolfe
erolfe@networkbta.com
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform