Any help in using this Code....

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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
 
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.
 
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top