|
-
Sep 26th, 2001, 05:02 AM
#1
Thread Starter
Junior Member
Api to shutt down prog
Is there an api you could use to shut down program from another program?
IceSoft
-
Sep 26th, 2001, 06:14 AM
#2
Frenzied Member
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.
-
Sep 26th, 2001, 06:43 AM
#3
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)
-
Sep 26th, 2001, 07:32 AM
#4
Thread Starter
Junior Member
-
Sep 26th, 2001, 07:38 AM
#5
Hyperactive Member
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.
-
Sep 26th, 2001, 08:38 AM
#6
Make your window the topmost window so it will always have focus regardless of what other windows are displayed.
-
Sep 26th, 2001, 08:54 AM
#7
Hyperactive Member
-
Sep 26th, 2001, 10:47 AM
#8
Addicted Member
JemimaChadwick,
Couldn't you just run regsvr32 with the /s option for silent running (no message boxes)?
Michael
Application/Web Developer
Visual Basic 6.0 SP5
Active Server Pages
Oracle 9i
- I'm going to live forever, or die trying!
-
Sep 26th, 2001, 11:16 AM
#9
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
-
Sep 27th, 2001, 01:37 AM
#10
Hyperactive Member
Done
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|