Created
January 29, 2016 13:34
-
-
Save xameeramir/f42ec89f679d5067face to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Public Class ieTools | |
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long | |
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long | |
Private Declare Function ObjectFromLresult Lib "oleacc" (ByVal lResult As Long, riid As UUID, ByVal wParam As Long, ppvObject As Object) As Long | |
Private Declare Function RegisterWindowMessage Lib "user32" Alias "RegisterWindowMessageA" (ByVal lpString As String) As Long | |
Private Declare Function SendMessageTimeout Lib "user32" Alias "SendMessageTimeoutA" (ByVal hWnd As Long, ByVal msg As Long, ByVal wParam As Long, lParam As Object, ByVal fuFlags As Long, ByVal uTimeout As Long, lpdwResult As Long) As Long | |
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hWnd As Long, ByVal lpString As String, _ | |
ByVal cch As Long) As Long | |
Private Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hWnd As Long) As Long | |
Private Declare Function GetWindow Lib "user32" (ByVal hWnd As Long, ByVal wCmd As Long) As Long | |
Private Declare Function GetParent Lib "user32" (ByVal hWnd _ | |
As Long) As Long | |
Private Declare Function SendNotifyMessage Lib "user32.dll" Alias "SendNotifyMessageA" (ByVal hWnd As Integer, _ | |
ByVal msg As Integer, ByVal wParam As Integer, ByVal lParam As String) As Integer | |
Public lhWndP As Long | |
Public sStr As String | |
Private Const GW_HWNDNEXT = 2 | |
Private Structure UUID | |
Dim Data1 As Long | |
Dim Data2 As Integer | |
Dim Data3 As Integer | |
Dim Data4() As Byte | |
End Structure | |
Private Const SMTO_ABORTIFHUNG = &H2 | |
Public Function GetWinIE(ByVal caption As String) As Long | |
Dim ButtonHandle As Object | |
Dim WindowHandle As Object | |
Dim h As Long | |
h = FindWindow(vbNullString, caption) | |
'MsgBox "" & h.innerHTML | |
h = FindWindowEx(h, 0, "Internet Explorer_Server", vbNullString) | |
If h = 0 Then | |
ButtonHandle = FindWindowEx(WindowHandle, 0, "Button", "&Open") | |
End If | |
GetWinIE = h | |
End Function | |
Public Function GetWinIEDOM(ByVal hWnd As Long) As IHTMLDocument | |
Dim typUUID As UUID, lngRes As Long, lngMsg As Long | |
lngMsg = RegisterWindowMessage("WM_HTML_GETOBJECT") | |
If lngMsg <> 0 Then | |
Call SendMessageTimeout(hWnd, lngMsg, 0, 0, SMTO_ABORTIFHUNG, 1000, lngRes) | |
If lngRes <> 0 Then | |
With typUUID | |
.Data1 = &H626FC520 | |
.Data2 = &HA41E | |
.Data3 = &H11CF | |
.Data4(0) = &HA7 | |
.Data4(1) = &H31 | |
.Data4(2) = &H0 | |
.Data4(3) = &HA0 | |
.Data4(4) = &HC9 | |
.Data4(5) = &H8 | |
.Data4(6) = &H26 | |
.Data4(7) = &H37 | |
.Data4(8) = &H38 | |
End With | |
Call ObjectFromLresult(lngRes, typUUID, 0, GetWinIEDOM) | |
End If | |
End If | |
End Function | |
Private Function GetWindowTitle(ByVal hWnd As Long) As String | |
Dim L As Long | |
Dim s As String | |
L = GetWindowTextLength(hWnd) | |
s = Space(L + 1) | |
GetWindowText(hWnd, s, L + 1) | |
GetWindowTitle = Left$(s, L) | |
End Function | |
End Class |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment