void RefreshToolBarIcons(void)
{
m_treeview.DeleteAllItems();
HWND hst = ::FindWindow(_T("Shell_TrayWnd"), NULL);
if (!hst)
{
return;
}
HWND htn = ::FindWindowEx(hst, NULL, _T("TrayNotifyWnd"), NULL);
if (!htn)
{
return;
}
HWND hsp = ::FindWindowEx(htn, NULL, _T("SysPager"), NULL);
if (hsp)
{
htn = hsp;
}
HWND htw = ::FindWindowEx(htn, NULL, _T("ToolbarWindow32"), NULL);
if (!htw)
{
return;
}
DWORD dwPId = 0;
::GetWindowThreadProcessId(htw, &dwPId);
HANDLE hProcess = ::OpenProcess(PROCESS_QUERY_INFORMATION|PROCESS_VM_READ|PROCESS_VM_OPERATION, FALSE, dwPId);
if (hProcess)
{
HMODULE hMod = NULL;
DWORD cbNeeded = 0;
TCHAR szProcessName[MAX_PATH] = _T("<unknown>");
if ( EnumProcessModules( hProcess, &hMod, sizeof(hMod), &cbNeeded) )
{
GetModuleFileNameEx( hProcess, hMod, szProcessName, sizeof(szProcessName)/sizeof(TCHAR) );
}
HTREEITEM hRoot = m_treeview.InsertItem(TVIF_TEXT|TVIF_PARAM, _T("TrayNotify"), 0, 0, 0, 0, dwPId, TVI_ROOT, TVI_ROOT);
//
DWORD dwRead = 0;
CToolBarCtrl tbCtrl = htw;
int nBtnCount = tbCtrl.GetButtonCount();
for (int i = 0; i < nBtnCount; ++i)
{
TBBUTTON tbn, pTbn;
memset(&tbn, 0, sizeof(tbn));
if(tbCtrl.GetButton(i, &pTbn))
{
if(::ReadProcessMemory(hProcess, &pTbn, &tbn, sizeof(tbn), &dwRead))
{
if(tbn.iString == -1)
{
continue;
}
TCHAR szName[MAX_PATH] = _T("NoName");
::ReadProcessMemory(hProcess, (void *)tbn.iString, szName, sizeof(szName)/sizeof(szName[0]), &dwRead);
szName[dwRead/sizeof(szName[0])] = _T('/0');
if(tbn.fsState&TBSTATE_HIDDEN)
{
_tcscat_s(szName, _T("[Hiden]"));
}
else
{
_tcscat_s(szName, _T("[Visible]"));
}
dwPId = -1;
HWND hWnd = NULL;
if(::ReadProcessMemory(hProcess, (void *)tbn.dwData, &hWnd, sizeof(hWnd), &dwRead))
{
::GetWindowThreadProcessId(hWnd, &dwPId);
if (-1 != dwPId)
{
m_treeview.InsertItem(TVIF_TEXT|TVIF_PARAM, szName, 0, 0, 0, 0, dwPId, hRoot, TVI_LAST);
}
}
}
}
}
::CloseHandle(hProcess);
m_treeview.Expand(hRoot);
}
}