By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,106 Members | 2,686 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,106 IT Pros & Developers. It's quick & easy.

Any help in using this Code....

P: n/a
Hi EveryBody:

I have the following code which just helpfull with Notepad:

Code:
<DllImport("user32", CharSet:=CharSet.Auto, SetLastError:=True)> _
Public Shared Function FindWindow(ByVal lpClassName As String, ByVal
lpWindowName As String) As Integer
'
End Function
<DllImport("user32", CharSet:=CharSet.Auto, SetLastError:=True)> _
Public Shared Function SendMessage(ByVal hwnd As Int32, ByVal wMsg As
Int32, ByVal wParam As Int32, ByVal lParam As Int32) As Int32
'
End Function
Private Const WM_CLOSE = &H10

Under button I put:

Dim intHandle As Integer = FindWindow("Notepad", vbNullString)
If intHandle > 0 Then
SendMessage(intHandle, WM_CLOSE, 0, 0)
End If

So I want to use this code to close the internet explorer,So i put Microsoft
Internet Explorer instaed of Notepad but it does not work and I put WordPad
instaed of Notepad also it does not work,how can I do that ?

any help will be appreciated

Husam
Nov 21 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
FindWindow can only find those windows that have window text (Captions) that
match your search string. You would be better off using EnumWindows to
search for internet explorer By using EnumWindows, you can search for the
words "Internet Explorer" anywhere in the window text..

Mike Ober.

"Husam" <Hu***@discussions.microsoft.com> wrote in message
news:17**********************************@microsof t.com...
Hi EveryBody:

I have the following code which just helpfull with Notepad:

Code:
<DllImport("user32", CharSet:=CharSet.Auto, SetLastError:=True)> _
Public Shared Function FindWindow(ByVal lpClassName As String, ByVal
lpWindowName As String) As Integer
'
End Function
<DllImport("user32", CharSet:=CharSet.Auto, SetLastError:=True)> _
Public Shared Function SendMessage(ByVal hwnd As Int32, ByVal wMsg As Int32, ByVal wParam As Int32, ByVal lParam As Int32) As Int32
'
End Function
Private Const WM_CLOSE = &H10

Under button I put:

Dim intHandle As Integer = FindWindow("Notepad", vbNullString)
If intHandle > 0 Then
SendMessage(intHandle, WM_CLOSE, 0, 0)
End If

So I want to use this code to close the internet explorer,So i put Microsoft Internet Explorer instaed of Notepad but it does not work and I put WordPad instaed of Notepad also it does not work,how can I do that ?

any help will be appreciated

Husam


Nov 21 '05 #2

P: n/a
That's my code I posted:

Internet Explorer's class name is 'IEFrame'

To close it you need to use PostMessage & not SendMessage:

Declarations:

Private Declare Function FindWindow Lib "user32" Alias "FindWindowA"
(ByVal lpClassName As String, ByVal lpWindowName As String) As Integer
Private Declare Function PostMessage Lib "user32" Alias "PostMessageA"
(ByVal hwnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal
lParam As Integer) As Integer

Private Const WM_CLOSE = &H10

' Behind a button:

Dim intHandle As Integer = FindWindow("IEFrame", vbNullString)
If intHandle > 0 Then
PostMessage(intHandle, WM_CLOSE, 0&, 0&)
End If

I hope this helps
Nov 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.