P
pfsardella
I'm using a variation of this code from a posting by Chip Pearson to
try to close a browser window that I opened. The code works fine when
I use it with Notepad (closes the Notepad window that I opened), but
fails to close the Internet Explorer window (fails to close a browser
that I opened).
FindWindow is retrieving the handle correctly. SendMessage is at
fault. If I substitute PostMessage for SendMessage, then the browser
closes.
Just curious as to why. Any insights?
http://www.google.com/groups?hl=en&lr=lang_en&ie=UTF-8&c2coff=1&safe=off&th=30d9d56bb8ecc7fb&rnum=2
Public Declare Function SendMessage Lib "user32" Alias
"SendMessageA" _
(ByVal hWnd As Long, ByVal wMsg As Long, _
ByVal wParam As Long, lParam As Any) As Long
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA"
_
(ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long
Sub CloseCalc()
On Error Resume Next
Dim hWnd As Long
Const WM_CLOSE = &H10
hWnd = FindWindow(vbNullString, "Calculator")
If hWnd > 0 Then
SendMessage hWnd, WM_CLOSE, 0&, 0&
End If
End Sub
Many thanks in advance for any and all responses.
Paul
try to close a browser window that I opened. The code works fine when
I use it with Notepad (closes the Notepad window that I opened), but
fails to close the Internet Explorer window (fails to close a browser
that I opened).
FindWindow is retrieving the handle correctly. SendMessage is at
fault. If I substitute PostMessage for SendMessage, then the browser
closes.
Just curious as to why. Any insights?
http://www.google.com/groups?hl=en&lr=lang_en&ie=UTF-8&c2coff=1&safe=off&th=30d9d56bb8ecc7fb&rnum=2
Public Declare Function SendMessage Lib "user32" Alias
"SendMessageA" _
(ByVal hWnd As Long, ByVal wMsg As Long, _
ByVal wParam As Long, lParam As Any) As Long
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA"
_
(ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long
Sub CloseCalc()
On Error Resume Next
Dim hWnd As Long
Const WM_CLOSE = &H10
hWnd = FindWindow(vbNullString, "Calculator")
If hWnd > 0 Then
SendMessage hWnd, WM_CLOSE, 0&, 0&
End If
End Sub
Many thanks in advance for any and all responses.
Paul