Why doesn't this work? idCommand always comes back as zero. It is finding the correct hWnd for the toolbar.

VB Code:
  1. Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
  2. 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
  3. 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
  4.  
  5. Private Const WM_USER = &H400
  6. Private Const TB_BUTTONCOUNT = (WM_USER + 24)
  7. Private Const TB_GETBUTTON = (WM_USER + 23)
  8. Private Const TB_PRESSBUTTON = (WM_USER + 3)
  9.  
  10. Private Type TBBUTTON
  11.    iBitmap      As Long
  12.    idCommand    As Long
  13.    fsState      As Byte
  14.    fsStyle      As Byte
  15.    bReserved1   As Byte
  16.    bReserved2   As Byte
  17.    dwData       As Long
  18.    iString      As Long
  19. End Type
  20.  
  21. Private Sub ClickToolbarButton()
  22.    
  23.     Dim lToolbarHwnd    As Long
  24.     Dim lButtonCount    As Long
  25.     Dim MyButton        As TBBUTTON
  26.    
  27.     lToolbarHwnd = FindWindow("IEFrame", "Google - Microsoft Internet Explorer")
  28.     lToolbarHwnd = FindWindowEx(lToolbarHwnd, 0, "WorkerW", vbNullString)
  29.     lToolbarHwnd = FindWindowEx(lToolbarHwnd, 0, "ReBarWindow32", vbNullString)
  30.     lToolbarHwnd = FindWindowEx(lToolbarHwnd, 0, "ToolbarWindow32", "")
  31.  
  32.     Debug.Print lToolbarHwnd
  33.  
  34.     lButtonCount = SendMessage(lToolbarHwnd, TB_BUTTONCOUNT, 0, 0)
  35.    
  36.     For lButton = 1 To lButtonCount
  37.    
  38.         SendMessage lToolbarHwnd, TB_GETBUTTON, lButton, MyButton
  39.         Debug.Print lButton & " : " & MyButton.idCommand
  40.         SendMessage lToolbarHwnd, TB_PRESSBUTTON, MyButton.idCommand, True
  41.  
  42.     Next lButton
  43.  
  44. End Sub