I'm trying to get the taskbar button ID for my App. I only need to do this once, so I figured I'd just loop through buttons, get the caption and compare it to my app's caption. I'm using TB_GETBUTTONTEXT to get the captions, but whilst its returning the length of the caption, it's not populating the buffer.
Here's the code:Any ideas?VB Code:
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" ( _ ByVal lpClassName As String, ByVal lpWindowName As String) As Long Public 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 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 Const WM_USER = &H400 Public Const TB_GETBUTTONTEXT = (WM_USER + 45) Public Function GetAppsID(ByVal sCaption As String) As Long Dim lhWnd As Long, N As Long, lLen As Long, sBuff As String lhWnd = FindWindow("Shell_TrayWnd", vbNullString) lhWnd = FindWindowEx(lhWnd, 0&, "ReBarWindow32", vbNullString) lhWnd = FindWindowEx(lhWnd, 0&, "MSTaskSwWClass", vbNullString) lhWnd = FindWindowEx(lhWnd, 0&, "ToolbarWindow32", vbNullString) Do lLen = SendMessage(lhWnd, TB_GETBUTTONTEXT, N, Null) If lLen = -1 Then Exit Do sBuff = Space$(lLen + 1) lLen = SendMessage(lhWnd, TB_GETBUTTONTEXT, N, sBuff) Debug.Print N, lLen, Trim$(sBuff) N = N + 1 Loop Until N = 50 End Function
be warned: passing the lParam ByVal causes an error in explorer.




Reply With Quote