PDA

Click to See Complete Forum and Search --> : How to close another app with a twist


f40nz
Jun 16th, 2000, 06:53 PM
I am trying to close another application & can make it work with the FindWindow & PostMessage API's, however the other application needs to know the unload mode, and this can not be the same as clicking the X control button.

My code says

ProcessID = FindWindow(vbNullString, AppName)
RetVal=PostMessage(ProcessID, WM_CLOSE,0,0)

This works, however in my other program I have

Private Sub Form_QueryUnload(Cancel as Integer, UnloadMode as Integer)

If UnloadMode=vbFormControlMenu Then MsgBox "Are You Sure"

End Sub

I am trying to get the program to close without the prompt if I close it automatically, & to have the prompt if the user closes the program.

The problem I am trying to solve revolves around the fact that the UnloadMode value is always the same as the vbFormControlMenu constant. I have tried passing other values in the 3rd & 4th parameters of the PostMessage, also tried using a SendMessage instead of PostMessage. I have also tried the TerminateProcess API but can not seem to find the correct process id to pass to it to even get it to close the program.

Can anybody help?

Thanks

Steve

123dwhite
Jun 20th, 2000, 04:17 AM
This site may have the answer you need.
check out the example on:
http://www.vbapi.com/ref/f/findwindowex.html