|
-
Sep 29th, 2003, 08:18 PM
#1
Thread Starter
New Member
Close an application that was started using shellexecute
i wish to close another program that was started by using the shell execute. i looked at send message and postmessage API's but it doesnt seem to work. I have attached sample code below. an help that you can provide will be greately appriciated.
thanks
Option Explicit
'Private Declare Function GetForegroundWindow Lib "user32" () As Long
Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function SendMessage Lib "user32"
Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Private Const WM_CLOSE = &H10
Private Sub Command1_Click()
tHwnd = ShellExecute(Me.hwnd, vbNullString, "c:\temp.jpg", vbNullString, "C:\", 1)
End Sub
Private Sub Command2_Click()
PostMessage tHwnd, WM_CLOSE, 0, 0
'i have also tried this
SendMessage tHwnd, WM_CLOSE, 0, 0
End Sub
both the functions dont work. please help.
thanks once again
-
Sep 29th, 2003, 10:08 PM
#2
So Unbanned
After: Private Const WM_CLOSE = &H10, put: Private tHwnd as Long
-
Sep 30th, 2003, 06:38 AM
#3
Thread Starter
New Member
oops, i did not notice that.
but inspite of adding the variable declaration i am unable to close the window that i had opened using shell execute. the code i am using now is attached with the variable declaration. thanks once again for trying to help.
Option Explicit
Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Private Const WM_CLOSE = &H10
Private thwnd As Long
Private Sub Command1_Click()
thwnd = ShellExecute(Me.hwnd, vbNullString, "c:\temp.jpg", vbNullString, "C:\", 1)
End Sub
Private Sub Command2_Click()
'PostMessage thwnd, WM_CLOSE, 0, 0
SendMessage thwnd, WM_CLOSE, 0, 0
End Sub
-
Sep 30th, 2003, 06:43 AM
#4
ShellExecute does not return a window handle. Look up ShellExecuteEx. Using that, you can obtain a process handle that you can use to terminate the process that is created.
Laugh, and the world laughs with you. Cry, and you just water down your vodka.
Take credit, not responsibility
-
Sep 30th, 2003, 07:25 AM
#5
Thread Starter
New Member
so do i use ShellExecuteEx to open the file instead of just ShellExecute? or use it in conjunction to find the window handle. Can you please point me to some example or give me a snippet if you already have some.
thanks alot
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
|