Is there an api you could use to shut down program from another program?
IceSoft
Printable View
Is there an api you could use to shut down program from another program?
IceSoft
Get the handle of the window that should be desroyed usinf FindWindow and then do
VB Code:
Declare Function DestroyWindow Lib "user32" Alias "DestroyWindow" (ByVal hwnd As Long) As Long DestroyWindow hwndofthewindow
or use SendMessage first send the WM_CLOSE then the WM_DESTROY messages.
This has always worked for me.
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Const WM_CLOSE = &H10
Private Const WM_QUIT = &H12
Dim CloseIt As Long
CloseIt = FindWindow(vbNullString, "Caption Of Window To Be Closed")
PostMessage CloseIt, WM_CLOSE, CLng(0), CLng(0)
ok tanx allot.
IceSoft
Hack,
I have a similar requirement where I am using ShellExecute to open the regsvr32.exe to unregister Dlls. This leaves the Notification Messager Window open. I want to close this and proceed. I tried this code u posted. It works fine when I trace thru the program, bringing focus to the VB App. But When i let it run by itself, the Notification Window has focus and wouldn't let the code continue to close it. Have u any suggestions? Hope I have explained myself clear here. If not, pls verify with me.
Thanks,
Jemima.
Make your window the topmost window so it will always have focus regardless of what other windows are displayed.
how would I do that?
JemimaChadwick,
Couldn't you just run regsvr32 with the /s option for silent running (no message boxes)?
Michael
JemimaChadwick:
Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Private Const SWP_NOMOVE = 2
Private Const SWP_NOSIZE = 1
Private Const FLAGS = SWP_NOMOVE Or SWP_NOSIZE
Private Const HWND_TOPMOST = -1
Private Const HWND_NOTOPMOST = -2
Private Function SetTopMostWindow(hwnd As Long, Topmost As Boolean) As Long
On Error Goto ErrRtn
If (Topmost) Then
SetTopMostWindow = SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, 0, FLAGS)
Else
SetTopMostWindow = SetWindowPos(hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, FLAGS)
SetTopMostWindow = False
End If
Exit Function
ErrRtn:
MsgBox "Error in SetTopMostWindow " & Err & " " & Error, vbExclamation + vbOKCancel
End Function
'In Form Load Event, put...
SetTopMostWindow Me.hwnd, TRUE
Thanks Michael. That did it.
Thanks Hack. Michael's suggestion fixed the requirement. I tried this too. The window did remain on top always but the focus was transeferred to the called appln.
Anyways, its done. Thanks.
Sorry Icesoft for stealing ur space!
-Jemima.