Click to See Complete Forum and Search --> : closing a program
bob323
Aug 12th, 2000, 10:47 PM
I'm totally stumped I want to have a button that closes internet explorer, but I don't have a clue how to get it done.
Anyone have any ideas?
You could use this program which will list the exe and when you select the exe and you click the button on the list, it will close. Here is the program: App List and Kill (http://www.planet-source-code.com/vb/scripts/ShowCode.asp?lngWId=1&txtCodeId=4377)
Try this:
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
Const WM_CLOSE = &H10
Const WM_DESTROY = &H2
Private Sub Command1_Click()
'Find the hWnd of the IE
hParent = FindWindow("IEFrame", vbNullString)
'If it's found then close it
If hParent <> 0 Then
PostMessage hParent, WM_CLOSE, 0, 0
PostMessage hParent, WM_DESTROY, 0, 0
End If
End Sub
gwdash
Aug 13th, 2000, 11:09 AM
Megatron-How many times have you posted that code, i see it three times a day!!!
gwdash, Megatron only answers the question, he doesn't go searching for it and tell them that he posted it.
I don't think he really wants to waste time looking for a post he made several hours ago.
He does do it sometimes though, but if people did what I did, and searched for the answer of the question before posting the question on the vb-world forums, than the same question wouldn't be asked over and over again.
But people usually want the answer now, and than they post their question, Megatron or anyone comes along and either searches for it fast or knows it and they reply and both are satisfied, usually, and go on with their lives..only to ask another question a few hours later :).
I think Megatron does a good job, he answers a lot of posts everyday and usually satisfies everyone with their answer.
Or if someone posts something, Megatron always has something better..hehe :D.
Well, I'm just speaking what's on my mind. Hope it gets to you :p.
V(ery) Basic
Aug 13th, 2000, 01:49 PM
Unfortunately Megatron's standard is not as high as mine, but he'll learn.
gwdash: As long as the question is answered, it doesn't make a difference how I get it or how many times a day I answer it. People come to these forums looking for answers and I'll do my best to provide them with it.
msuryadarma
Jan 25th, 2001, 10:24 AM
Hi, sorry to dig up an old post, but this might be the question to my problem.
Megatron, how did you know the window name of IE is
"IEFrame"? Doesn't it show whatever webpage it's currently displaying? Or is there a generic name like IEFrame?
If IEFrame is a generic name, how do I find out the generic name for an application? I have a program that constantly changes the title on the title bar, just like IE.
Thanks!
Wow, this thread is from months ago! :o
Use the GetClassName (http://www.vbapi.com/ref/g/getclassname.html) API function to get the class of a window.
msuryadarma
Jan 25th, 2001, 12:04 PM
Brilliant! Thanks Matt!
Or you can use the tool called Spy++, which is shipped with Visual Studio.
Lethal
Jan 25th, 2001, 07:40 PM
Ok, I'm in the process of trying to learn how to use the API. From the above question, I went and used the SPY++ prog, and for IE it told me "Internet Explorer_Server". Why isn't it the same as what Megatron used in his code??? Thanks
That's because IEFrame is the window itself, you are getting the class of the control inside of the window.
Example:
Dim ieframe As Long, shelldocobjectview As Long, internetexplorerserver As Long
ieframe = FindWindow("ieframe", vbNullString)
shelldocobjectview = FindWindowEx(ieframe, 0&, "shell docobject view", vbNullString)
internetexplorerserver = FindWindowEx(shelldocobjectview, 0&, "internet explorer_server", vbNullString)
NerdWigger
Jan 29th, 2001, 02:32 PM
I don't have netscape, but can someone use spy++ to tell me what its handle is? I know for Internet Explorer it is IEFrame, but i need to know the handle foe Netscape.
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.