PDA

Click to See Complete Forum and Search --> : Close a background program.


Nico van Wijk
Jul 3rd, 2000, 10:34 AM
Hello,

I have a problem to close a program that runs in Windows. The program isn't visseble in a window, but a know it's on the background.

With a windows api I check wich programs are active, and I see that program. I try to close the program: I find the applications and want to close it with (RetVal = PostMessage(winHwnd, WM_CLOSE, 0&, 0&).

It doesn't work, I think it won't work because the program is not in a window but at the background.

Does anybody the answer?

Jul 3rd, 2000, 11:23 AM
See if this code works. It will close Calculator. Just replace Calculator with whatever program you want to close.

code for a Module.

Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal lpClassName As Any, ByVal lpWindowName As Any) As Long
Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Public Const WM_CLOSE = &H10


Code for a CommandButton

Private Sub Command1_Click()

' Get the Handle of Calculator
MyHandle = FindWindow(CLng(0), "Calculator")
' Send a Message to close it
SendMessage MyHandle, WM_CLOSE, CLng(0), CLng(0)

End Sub