25/03/2020, 11:36
accessman
böyle bir kod var hiç kullanan oldu mu
Option Explicit
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 SendMessageAny Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Integer, ByVal lParam As Any) As Long
Private Const WM_GETTEXT As Long = &HD
Private Const WM_GETTEXTLENGTH As Long = &HE
Private Function GetIE8AddressBar(ByVal MyClassName As String, Optional ByVal MyTitle As String) As Long
Dim RetParent As Long
Dim RetChild As Long
RetParent = FindWindow(MyClassName, MyTitle)
If RetParent Then
RetChild = FindWindowEx(RetParent, 0&, "WorkerW", vbNullString) 'Caption= Navigation Bar
RetChild = FindWindowEx(RetChild, 0&, "ReBarWindow32", vbNullString) 'previous child is the parent of this child
RetChild = FindWindowEx(RetChild, 0&, "Address Band Root", vbNullString) 'previous child is the parent of this child
RetChild = FindWindowEx(RetChild, 0&, "Edit", vbNullString)
GetIE8AddressBar = RetChild
End If
End Function
Private Sub Command1_Click()
Dim MyIE8AddyBar As Long
Dim RetStr As String
MyIE8AddyBar = GetIE8AddressBar("IEFrame", vbNullString) 'call my function
If MyIE8AddyBar Then 'if child editbox found
RetStr = GetText(MyIE8AddyBar)
Me.Caption = RetStr
End If
End Sub
'gets the text of a textbox or a caption of most controls
'most people use GetWindowText API, but it doesnt seem to work for the IE8 editbox in my tests.
Private Function GetText(pHandle As Long) As String
Dim Buffer As String
Dim TextLength As Long
TextLength = SendMessageAny(pHandle, WM_GETTEXTLENGTH, 0&, 0&)
Buffer = String$(TextLength, 0&)
SendMessageAny pHandle, WM_GETTEXT, TextLength + 1, Buffer
GetText = Buffer
End Function