Win11 22H2 (10.0.22621) can't support TB_BUTTONCOUNT message of System Toolbar

Ryan 0 Reputation points
2024-01-08T08:37:11.82+00:00

TB_BUTTONCOUNT message can't get system tray icon's count any more after Win11 22H2 (10.0.22621).

https://learn.microsoft.com/en-us/windows/win32/controls/tb-buttoncount

The following code can get system tray icon's information in the Win10 system, and the following code is invalid after upgrading to 22621, that always get 0.

Is there a new method or API that can get system tray icon's information after Win11 22621?

HWND m_HWND = ::FindWindow(_T("Shell_TrayWnd"), NULL);
if (m_HWND != NULL) m_HWND = ::FindWindowEx(m_HWND, NULL, _T("TrayNotifyWnd"), NULL);  
if (m_HWND != NULL) m_HWND = ::FindWindowEx(m_HWND, NULL, _T("SysPager"), NULL); 
if (m_HWND != NULL) m_HWND = ::FindWindowEx(m_HWND, NULL, _T("ToolbarWindow32"), NULL); LRESULT nTrayCount = ::SendMessageW(m_HWND, TB_BUTTONCOUNT, 0, 0);
Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,447 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Castorix31 82,036 Reputation points
    2024-01-08T08:59:07.15+00:00

    I don't have Windows 11, but it could work with UI Automation, like in this test ; https://learn.microsoft.com/en-us/answers/questions/115440/how-to-find-taskbar-button-screen-rect-of-a-window

    (maybe by changing the FindWindowEx calls, if the hierarchy has changed (check with Inspect tool))

    1 person found this answer helpful.

  2. jian wei zhang 0 Reputation points
    2024-05-11T01:01:07.8533333+00:00

    I'm having the same issue in windows 11 23H2