Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

WM_CLOSE not working on console app

Status
Not open for further replies.

Panthaur

IS-IT--Management
Jul 26, 2002
78
0
0
US
I have a console app (DOS window) that I am trying to close with the following command:

SendMessage hwnd, WM_CLOSE, 0, ByVal 0

It works fine under 2K/XP, but under 95/98 it tells me i'm trying to close a running app and then I have to click YES or NO.

Can someone give me a better way of shutting this down without having to answer the YES/NO question for the console app? I've tried WM_DESTROY (value of &H2) but it doesn't do anything at all.

HELP!!
Panthaur
 
If you are starting your program with the shell command, then it will return that instances Process Id.

You can then use that process id to terminate it.


Private Const PROCESS_TERMINATE = 1

'** Required APIs to terminate other functions.
Private Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long

Private Sub Form_Load()
Dim MyPID As Long
Dim PIDToKill As Long

MyPID = Shell("C:\windows\notepad.exe")

PIDToKill = OpenProcess(PROCESS_TERMINATE, 0, MyPID)
KillRunningProgram = TerminateProcess(PIDToKill, 0)
End Sub


This would terminate the notepad application that was just started in code.

'I don't have a 9x machine to test this out on so you will have to try it to see if the yes/no appears
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top