16,548
社区成员




HANDLE hProcess;
LPVOID lpAddress;
int nButtonCount;
DWORD dwProcessId;
TBBUTTON tb;
GetWindowThreadProcessId(hwndTB, &dwProcessId);
hProcess = OpenProcess(PROCESS_ALL_ACCESS | PROCESS_VM_OPERATION | PROCESS_VM_READ | PROCESS_VM_WRITE, 0, dwProcessId);
lpAddress = VirtualAllocEx(hProcess, 0, 0x4096, MEM_COMMIT, PAGE_READWRITE);
nButtonCount = SendMessage(hwndTB, TB_BUTTONCOUNT, 0, 0);
for (int i = 0; i < nButtonCount - 1; i++)
{
SendMessage(hwndTB, TB_GETBUTTON, i, (LPARAM)lpAddress);
ReadProcessMemory(hProcess, lpAddress, &tb, sizeof(TBBUTTON), 0);
if (tb.iString != -1)
{
WCHAR szBuff[MAX_PATH];
ReadProcessMemory(hProcess, (LPVOID)tb.iString, wszBuff, MAX_PATH, 0);
//可能不是Unicode的,自己视情况而定
if (lstrcmpW(wszBuff, L"按钮上的文本") == 0)
{
PostMessage(GetParent(hwndTB), WM_COMMAND, tb.idCommand, (LPARAM)hwndTB);
}
}
}
VirtualFreeEx(hProcess, lpAddress, 0x4096, MEM_RELEASE);
CloseHandle(hProcess);
HANDLE hProcess;
LPVOID lpAddress;
int nButtonCount;
DWORD dwProcessId;
TBBUTTON tb;
//hwndTB 为Toolbar控件句柄
GetWindowThreadProcessId(hwndTB, &dwProcessId);
hProcess = OpenProcess(PROCESS_ALL_ACCESS | PROCESS_VM_OPERATION | PROCESS_VM_READ | PROCESS_VM_WRITE, 0, dwProcessId);
lpAddress = VirtualAllocEx(hProcess, 0, 0x4096, MEM_COMMIT, PAGE_READWRITE);
nButtonCount = SendMessage(hwndTB, TB_BUTTONCOUNT, 0, 0);
for (int i = 0; i < nButtonCount - 1; i++)
{
SendMessage(hwndTB, TB_GETBUTTON, i, (LPARAM)lpAddress);
ReadProcessMemory(hProcess, lpAddress, &tb, sizeof(TBBUTTON), 0);
if (tb.iString != -1)
{
WCHAR szBuff[MAX_PATH];
ReadProcessMemory(hProcess, (LPVOID)tb.iString, wszBuff, MAX_PATH, 0);
//可能不是Unicode的,自己视情况而定
if (lstrcmpW(wszBuff, L"按钮上的文本") == 0)
{
int idCommand;
ReadProcessMemory(hProcess, (LPVOID)tb.idCommand, &idCommand, sizeof(int), 0);
PostMessage(GetParent(hwndTB), WM_COMMAND, idCommand, (LPARAM)hwndTB);
}
}
}
VirtualFreeEx(hProcess, lpAddress, 0x4096, MEM_RELEASE);
CloseHandle(hProcess);