Why doesn't this work? idCommand always comes back as zero. It is finding the correct hWnd for the toolbar.
VB Code:
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 SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long Private Const WM_USER = &H400 Private Const TB_BUTTONCOUNT = (WM_USER + 24) Private Const TB_GETBUTTON = (WM_USER + 23) Private Const TB_PRESSBUTTON = (WM_USER + 3) Private Type TBBUTTON iBitmap As Long idCommand As Long fsState As Byte fsStyle As Byte bReserved1 As Byte bReserved2 As Byte dwData As Long iString As Long End Type Private Sub ClickToolbarButton() Dim lToolbarHwnd As Long Dim lButtonCount As Long Dim MyButton As TBBUTTON lToolbarHwnd = FindWindow("IEFrame", "Google - Microsoft Internet Explorer") lToolbarHwnd = FindWindowEx(lToolbarHwnd, 0, "WorkerW", vbNullString) lToolbarHwnd = FindWindowEx(lToolbarHwnd, 0, "ReBarWindow32", vbNullString) lToolbarHwnd = FindWindowEx(lToolbarHwnd, 0, "ToolbarWindow32", "") Debug.Print lToolbarHwnd lButtonCount = SendMessage(lToolbarHwnd, TB_BUTTONCOUNT, 0, 0) For lButton = 1 To lButtonCount SendMessage lToolbarHwnd, TB_GETBUTTON, lButton, MyButton Debug.Print lButton & " : " & MyButton.idCommand SendMessage lToolbarHwnd, TB_PRESSBUTTON, MyButton.idCommand, True Next lButton End Sub




Reply With Quote