#include <iostream> #include <windows.h> #include <string> #include <commctrl.h> #include <atlstr.h>
using namespace std;
BOOL Is64bitSystem() { SYSTEM_INFO si; GetNativeSystemInfo(&si); if (si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64 || si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_IA64) return TRUE; else return FALSE; }
HWND FindTrayWnd() { HWND hWnd = NULL;
hWnd = FindWindow(_T("Shell_TrayWnd"), NULL); hWnd = FindWindowEx(hWnd, NULL, _T("TrayNotifyWnd"), NULL); hWnd = FindWindowEx(hWnd, NULL, _T("SysPager"), NULL); hWnd = FindWindowEx(hWnd, NULL, _T("ToolbarWindow32"), NULL);
return hWnd; }
HWND FindNotifyIconOverflowWindow() { HWND hWnd = NULL;
hWnd = FindWindow(_T("NotifyIconOverflowWindow"), NULL); hWnd = FindWindowEx(hWnd, NULL, _T("ToolbarWindow32"), NULL);
return hWnd; }
BOOL EnumNotifyWindow(HWND hWnd) { DWORD dwProcessId = 0; GetWindowThreadProcessId(hWnd, &dwProcessId); if (dwProcessId == 0) { cout << "GetWindowThreadProcessId failed:" << GetLastError() << endl; return FALSE; }
HANDLE hProcess = OpenProcess( PROCESS_VM_OPERATION | PROCESS_VM_READ | PROCESS_VM_WRITE, FALSE, dwProcessId ); if (hProcess == NULL) { cout << "OpenProcess failed:" << GetLastError() << endl; return FALSE; }
LPVOID p_tbbutton = VirtualAllocEx( hProcess, 0, 4096, MEM_COMMIT, PAGE_EXECUTE_READWRITE ); if (p_tbbutton == NULL) { cout << "VirtualAllocEx failed:" << GetLastError() << endl; return FALSE; }
DWORD dw_addr_dwData = 0; BYTE buff[1024] = { 0 }; wstring ws_filePath = L""; wstring ws_tile = L""; HWND h_mainWnd = NULL; int i_data_offset = 12; int i_str_offset = 18; if (Is64bitSystem()) { i_data_offset += 4; i_str_offset += 6; }
int i_buttons = 0; i_buttons = SendMessage(hWnd, TB_BUTTONCOUNT, 0, 0); if (i_buttons == 0) { cout << "TB_BUTTONCOUNT message failed:" << GetLastError() << endl; return FALSE; }
for (int i = 0; i < i_buttons; i++) { if (!SendMessage(hWnd, TB_GETBUTTON, i, (LPARAM)p_tbbutton)) { cout << "TB_GETBUTTON message failed:" << GetLastError() << endl; return FALSE; }
if (!ReadProcessMemory(hProcess, (LPVOID)((DWORD)p_tbbutton + i_data_offset), &dw_addr_dwData, 4, 0)) { cout << "ReadProcessMemory failed:" << GetLastError() << endl; return FALSE; }
if (dw_addr_dwData) { if (!ReadProcessMemory(hProcess, (LPCVOID)dw_addr_dwData, buff, 1024, 0)) { cout << "ReadProcessMemory failed:" << GetLastError() << endl; return FALSE; } h_mainWnd = (HWND)(*((DWORD*)buff)); ws_filePath = (WCHAR*)buff + i_str_offset; ws_tile = (WCHAR*)buff + i_str_offset + MAX_PATH; cout << "hMainWnd = " << hex << h_mainWnd << endl; wcout << "strFilePath = " << ws_filePath << endl; wcout << "strTile = " << ws_tile << endl; }
dw_addr_dwData = 0; h_mainWnd = NULL; ws_filePath = L""; ws_tile = L""; cout << endl; } if (VirtualFreeEx(hProcess, p_tbbutton, 0, MEM_RELEASE) == 0) { cout << "VirtualFreeEx failed:" << GetLastError() << endl; return FALSE; } if (CloseHandle(hProcess) == 0) { cout << "CloseHandle failed:" << GetLastError() << endl; return FALSE; }
return TRUE; }
int main() { setlocale(LC_ALL, "chs");
HWND h_tray = FindTrayWnd(); HWND h_tray_fold = FindNotifyIconOverflowWindow();
if (EnumNotifyWindow(h_tray) == FALSE || EnumNotifyWindow(h_tray_fold) == FALSE) { cout << "EnumNotifyWindow false." << endl; }
cin.get(); return 0; }
|