老妖进来,你的spy4win里面怎么发送TB_GETBUTTONTEXT得到Caption的?

lbg 2005-12-13 08:23:09
我是用DELPHI写的,找到MSTaskSwWClass是用你的自动生成代码完成,不好意思,用delphi我自己加了些:
const TB_BUTTONCOUNT=WM_USER + 24;
const TB_GETBUTTONTEXT=WM_USER + 45;
const TB_HIDEBUTTON=WM_USER + 4;

var
hLastWin : THandle;
icount,i:integer;
strcaption: pchar;
begin
hLastWin := MyFindWindow();
for i:=0 to icount-1 do
begin
strCaption := StrAlloc(1000);
SendMessage(hLastWin,TB_GETBUTTONTEXT ,i,LPARAM( strCaption));
Memo1.Lines.Add(StrPas(strCaption));
end;
...全文
646 19 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
19 条回复
切换为时间正序
请发表友善的回复…
发表回复
constantine 2005-12-13
  • 打赏
  • 举报
回复
改了一点,你试试看
constantine 2005-12-13
  • 打赏
  • 举报
回复
procedure TForm1.GetTaskbarbuttonscaption(hWindow: hwnd;strlist: TStrings);
var
szBuf: array [0..nMaxLen+1] of pchar;
nLVItemCount, i: Integer;
dwProcessID: DWORD;
hProcess: HWND;
dwBytesRead, dwBytesWrite: DWORD;
bSuccess, bWriteOK: Boolean;
lpTextRemote, lpPTBButtonRemote: pointer;
ptbtn:PTBButton;
begin
GetWindowThreadProcessId(hWindow, dwProcessID);
hProcess := OpenProcess(PROCESS_ALL_ACCESS, FALSE, dwProcessID);
if hProcess = 0 Then exit;
lpTextRemote := VirtualAllocEx(hProcess, nil, nMaxLen+1, MEM_COMMIT, PAGE_READWRITE);
lpPTBButtonRemote := VirtualAllocEx(hProcess, nil, sizeof(PTBButton), MEM_COMMIT, PAGE_READWRITE);
if(lpTextRemote = nil) Or (lpPTBButtonRemote = nil) Then exit;
nLVItemCount := SendMessage(hWindow,TB_BUTTONCOUNT,0,0);
strlist.Add('Welcome to www.ccrun.com');
strlist.Add('toolbarµÄItem×ÜÊý: ' + IntToStr(nLVItemCount));
strlist.Add('---------------------------');
for i := 0 to nLVItemCount-1 Do
Begin
ZeroMemory(@szBuf, nMaxLen+1);
bWriteOK := WriteProcessMemory(hProcess, lpTextRemote, @szBuf, nMaxLen+1, dwBytesWrite);
if bWriteOK = false Then exit;
bWriteOK := WriteProcessMemory(hProcess, lpPTBButtonRemote, @ptbtn, sizeof(PTBButton), dwBytesWrite);
if bWriteOK=false Then exit;
SendMessage(hWindow, TB_GETBUTTON, WPARAM(i), LPARAM(lpPTBButtonRemote));
ReadProcessMemory(hProcess, lpPTBButtonRemote, ptbtn, SizeOf(_TBBUTTON), dwBytesRead);
SendMessage(hWindow, TB_GETBUTTONTEXT , WPARAM(ptbtn.idCommand), LPARAM(lpPTBButtonRemote));
bSuccess := ReadProcessMemory(hProcess, lpPTBButtonRemote, @szBuf, 256, dwBytesRead);
if bSuccess = false Then exit;
strlist.Add(StrPas(@szBuf));
end;
VirtualFreeEx(hProcess, lpPTBButtonRemote, 0, MEM_RELEASE);
VirtualFreeEx(hProcess, lpTextRemote, 0, MEM_RELEASE);
CloseHandle(hProcess);
End ;
ccrun.com 2005-12-13
  • 打赏
  • 举报
回复
好。你再等我一会。
constantine 2005-12-13
  • 打赏
  • 举报
回复
void __fastcall GetToolBarButtonText(HWND hWnd,TStrings *list)
{

int nItemCount;
char chBuffer[256];
DWORD dwProcessID;
HANDLE hProcess;
void * Pointer;
SIZE_T nNumberOfBytesRead;

nItemCount = SendMessage(hWnd, TB_BUTTONCOUNT, 0, 0);
GetWindowThreadProcessId(hWnd, &dwProcessID);
hProcess = OpenProcess(PROCESS_VM_OPERATION | PROCESS_VM_READ | PROCESS_VM_WRITE,
false,
dwProcessID);
Pointer = VirtualAllocEx(hProcess,
NULL,
4096,
MEM_RESERVE | MEM_COMMIT,
PAGE_READWRITE);
try{
//ShowMessage(nItemCount);
for(int Index= 0 ; Index < nItemCount ; Index++)
{
TBBUTTON bi;
SendMessage(hWnd, TB_GETBUTTON, Index, (LPARAM)Pointer);
ReadProcessMemory(hProcess,
(Pointer),
&bi,
sizeof(bi),
&nNumberOfBytesRead);
SendMessage(hWnd, TB_GETBUTTONTEXT , bi.idCommand, (LPARAM)(Pointer));
ReadProcessMemory(hProcess,
(void *)(Pointer),
chBuffer,
sizeof(chBuffer),
&nNumberOfBytesRead);
list->Add(chBuffer);
}
}
__finally
{
VirtualFreeEx(hProcess,
Pointer,
0,
MEM_RELEASE);
CloseHandle(hProcess);
}
}
lbg 2005-12-13
  • 打赏
  • 举报
回复
没有错误,但是,得到的都是空的字符串
lbg 2005-12-13
  • 打赏
  • 举报
回复
老妖,我改成了读TOOLBAR的,但是不成功,麻烦你帮忙看看:
procedure TForm1.GetTaskbarbuttonscaption(hWindow: hwnd;strlist: TStrings);
var
szBuf: array [0..nMaxLen+1] of pchar;
nLVItemCount, i: Integer;
dwProcessID: DWORD;
hProcess: HWND;
dwBytesRead, dwBytesWrite: DWORD;
bSuccess, bWriteOK: Boolean;
lpTextRemote, lpPTBButtonRemote: pointer;
ptbtn:PTBButton;
begin
GetWindowThreadProcessId(hWindow, dwProcessID);
hProcess := OpenProcess(PROCESS_ALL_ACCESS, FALSE, dwProcessID);
if hProcess = 0 Then exit;
lpTextRemote := VirtualAllocEx(hProcess, nil, nMaxLen+1, MEM_COMMIT, PAGE_READWRITE);
lpPTBButtonRemote := VirtualAllocEx(hProcess, nil, sizeof(PTBButton), MEM_COMMIT, PAGE_READWRITE);
if(lpTextRemote = nil) Or (lpPTBButtonRemote = nil) Then exit;
nLVItemCount := SendMessage(hWindow,TB_BUTTONCOUNT,0,0);
strlist.Add('Welcome to www.ccrun.com');
strlist.Add('ListView的Item总数: ' + IntToStr(nLVItemCount));
strlist.Add('---------------------------');
for i := 0 to nLVItemCount-1 Do
Begin
ZeroMemory(@szBuf, nMaxLen+1);
bWriteOK := WriteProcessMemory(hProcess, lpTextRemote, @szBuf, nMaxLen+1, dwBytesWrite);
if bWriteOK = false Then exit;
bWriteOK := WriteProcessMemory(hProcess, lpPTBButtonRemote, @ptbtn, sizeof(PTBButton), dwBytesWrite);
if bWriteOK=false Then exit;
SendMessage(hWindow, TB_GETBUTTON, WPARAM(i ), LPARAM(ptbtn));
SendMessage(hWindow, TB_GETBUTTONTEXT , WPARAM(ptbtn.idCommand ), LPARAM(@szBuf));
bSuccess := ReadProcessMemory(hProcess, lpTextRemote, @szBuf, nMaxLen+1, dwBytesRead);
if bSuccess = false Then exit;
strlist.Add(StrPas(@szBuf));
end;
VirtualFreeEx(hProcess, lpPTBButtonRemote, 0, MEM_RELEASE);
VirtualFreeEx(hProcess, lpTextRemote, 0, MEM_RELEASE);
CloseHandle(hProcess);
End ;
空中猎手 2005-12-13
  • 打赏
  • 举报
回复
我当时怎么得不到BUTTON的TEXT的,郁闷~~~
ccrun.com 2005-12-13
  • 打赏
  • 举报
回复
搞定了。测试成功。

procedure TForm1.GetTaskbarbuttonscaption(hWindow: hwnd;strlist: TStrings);
var
szBuf: array [0..nMaxLen+1] of pchar;
nLVItemCount, i: Integer;
dwProcessID: DWORD;
hProcess: HWND;
lvItemLocal: TLVItem;
dwBytesRead, dwBytesWrite: DWORD;
bSuccess, bWriteOK: Boolean;
lpTextRemote, lpListItemRemote: pointer;
begin
GetWindowThreadProcessId(hWindow, dwProcessID);
hProcess := OpenProcess(PROCESS_ALL_ACCESS, FALSE, dwProcessID);
if hProcess = 0 Then
exit;
lpTextRemote := VirtualAllocEx(hProcess, nil, nMaxLen+1, MEM_COMMIT, PAGE_READWRITE);
lpListItemRemote := VirtualAllocEx(hProcess, nil, sizeof(pLVITEM), MEM_COMMIT, PAGE_READWRITE);
if(lpTextRemote = nil) Or (lpListItemRemote = nil) Then
exit;
nLVItemCount := ListView_GetItemCount(hWindow);
strlist.Add('Welcome to www.ccrun.com');
strlist.Add('ListView的Item总数: ' + IntToStr(nLVItemCount));
strlist.Add('---------------------------');

for i := 0 to nLVItemCount-1 Do
Begin
ZeroMemory(@szBuf, nMaxLen+1);
bWriteOK := WriteProcessMemory(hProcess, lpTextRemote, @szBuf, nMaxLen+1, dwBytesWrite);
if bWriteOK = false Then
exit;
lvItemLocal.iItem := i;
lvItemLocal.iSubItem := 0;
lvItemLocal.mask := LVIF_TEXT;
lvItemLocal.cchTextMax := nMaxLen;
lvItemLocal.pszText := pchar(lpTextRemote);
bWriteOK := WriteProcessMemory(hProcess, lpListItemRemote, @lvItemLocal, sizeof(TLVItem), dwBytesWrite);
if bWriteOK=false Then exit;
SendMessage(hWindow, LVM_GETITEMTEXT, WPARAM(i), LPARAM(lpListItemRemote));
bSuccess := ReadProcessMemory(hProcess, lpTextRemote, @szBuf, nMaxLen+1, dwBytesRead);
if bSuccess = false Then
exit;
strlist.Add(StrPas(@szBuf));
end;
VirtualFreeEx(hProcess, lpListItemRemote, 0, MEM_RELEASE);
VirtualFreeEx(hProcess, lpTextRemote, 0, MEM_RELEASE);
CloseHandle(hProcess);
end;
ccrun.com 2005-12-13
  • 打赏
  • 举报
回复
好,你等我,我帮你调试一下。
lbg 2005-12-13
  • 打赏
  • 举报
回复
我想把老妖网站的读取其它进程的ListView内容 的代码改成delphi,但是,delphi不熟,请帮忙改一下,(注释地方不知道怎么改)
procedure TForm1.GetTaskbarbuttonscaption(hWindow: hwnd;strlist: TStrings);
var
szBuf:array [0..nMaxLen+1] of pchar;
nLVItemCount,i:Integer;
dwProcessID:DWORD;
hProcess:HWND;
lvItemLocal:PLVItem ;
dwBytesRead, dwBytesWrite:DWORD;
bSuccess,bWriteOK:Boolean;
lpTextRemote,lpListItemRemote:pointer;
begin
GetWindowThreadProcessId(hWindow,dwProcessID);
hProcess:=OpenProcess(PROCESS_ALL_ACCESS,FALSE,dwProcessID);
if hProcess=hwnd(nil) Then exit;
lpTextRemote:=VirtualAllocEx(hProcess,nil,nMaxLen+1,MEM_COMMIT,PAGE_READWRITE);
lpListItemRemote:=VirtualAllocEx(hProcess,nil,sizeof(pLVITEM),MEM_COMMIT,PAGE_READWRITE);
if (lpTextRemote=nil) Or (lpListItemRemote=nil) Then exit;
nLVItemCount:=ListView_GetItemCount(hWindow);
strlist.Add('Welcome to www.ccrun.com');
strlist.Add('ListView的Item总数: ' + String(nLVItemCount));
strlist.Add('---------------------------');
for i:=0 to nLVItemCount-1 Do
Begin
ZeroMemory(@szBuf,nMaxLen+1);
// bWriteOK:= WriteProcessMemory(hProcess,lpTextRemote,pointer(szBuf),nMaxLen+1,(LPDWORD)&dwBytesWrite);
if bWriteOK=false Then exit;
lvItemLocal.iItem:=i;
lvItemLocal.iSubItem:=0;
lvItemLocal.mask:=LVIF_TEXT;
lvItemLocal.cchTextMax:=nMaxLen;
lvItemLocal.pszText:=pchar(lpTextRemote);
dwBytesWrite:=0;
// bWriteOK:=WriteProcessMemory(hProcess,lpListItemRemote,(LPVOID)&lvItemLocal,sizeof(LVITEM),(LPDWORD)&dwBytesWrite);
if bWriteOK=false Then exit;
SendMessage(hWindow,LVM_GETITEMTEXT,WPARAM(i),LPARAM(lpListItemRemote));
// bSuccess:=ReadProcessMemory(hProcess,lpTextRemote,szBuf,nMaxLen+1,&dwBytesRead);
if bSuccess=false Then exit;
//strlist.Add(StrPas(szBuf));
End;
VirtualFreeEx(hProcess,lpListItemRemote,0,MEM_RELEASE);
VirtualFreeEx(hProcess,lpTextRemote,0,MEM_RELEASE);
CloseHandle(hProcess);
End ;
ccrun.com 2005-12-13
  • 打赏
  • 举报
回复
不好意思来晚了。
读取其他进程中ToolBar按钮标题,在WinNT以上系统中,必须在目标进程中开辟一个内存空间,然后使用TB_GETBUTTONTEXT消息,再从目标进程中读取相应的字符串才可以。我的站上有篇读取其他进程中ListView内容的,可以修改成读取ToolBar的。

TB_GETBUTTONTEXT 这些消息在Delphi中需要uses CommCtrl;
lbg 2005-12-13
  • 打赏
  • 举报
回复
constantine(飘遥的安吉儿),我以前在delphi看到你,我是最开始学BCB的,喜欢BCB,但是DELPHI打起代码来比较爽,所以,有些要快速完成的东西就用delphi来做
constantine 2005-12-13
  • 打赏
  • 举报
回复
不是没有,要use CommCtrl
兄弟怎么会跑bcb问?奇怪,delphi区起码比bcb人气好很多
lbg 2005-12-13
  • 打赏
  • 举报
回复
delphi里面怎么没有TB这些消息的定义,包含TBBUTTON,到底要use什么?
lbg 2005-12-13
  • 打赏
  • 举报
回复
谢谢,我先试试,我是用i代替idcommand,一发消息,就explorer就出问题
constantine 2005-12-13
  • 打赏
  • 举报
回复
hWnd是toolbar的句柄
TBBUTTON bi;
void * Pointer;
SIZE_T nNumberOfBytesRead;
SendMessage(hWnd, TB_GETBUTTON, i, (LPARAM)Pointer);
ReadProcessMemory(hProcess,
(Pointer),
&bi,
sizeof(bi),
&nNumberOfBytesRead);
SendMessage(hWnd, TB_GETBUTTONTEXT , bi.idCommand, (LPARAM)(Pointer));
ReadProcessMemory(hProcess,
(void *)(Pointer),
chBuffer,
sizeof(chBuffer),
&nNumberOfBytesRead);

这样是用sendmessage,然后在用ReadProcessMemory 读出来的,不然我试过有问题
bi.idCommand 这个也是你要注意的,建议是不要简单用i代替,msdn里面说的是button的id
我就不知道大家怎么理解这个id,开始我也是以为i,后来觉得不对,应该是对应的idCommand
实际上也处理了一个小问题
另外你以可以用bi.iString代替Pointer,这样就不用Sendmessage了
但是chBuffer就不要用char数组了,用wchar_t 数组就可以了
lbg 2005-12-13
  • 打赏
  • 举报
回复
另外,我的http://community.csdn.net/Expert/topic/4449/4449476.xml?temp=.2104303这个问题不能回复了,我连续超过三次回复了,目的只有一个,隐藏任务栏上对应的按钮,季版主的方法我试过,好象没有办法隐藏任务栏的
lbg 2005-12-13
  • 打赏
  • 举报
回复
谢谢 constantine(飘遥的安吉儿) ,谢谢老妖
ccrun.com 2005-12-13
  • 打赏
  • 举报
回复
调了半天烦燥,将我原来的C++代码转换成Delphi的给你:

function TForm1.MyGetToolBar(hWin: HWND; pList: TStrings): Integer;
var
hProc: HWND;
dwPID: DWORD;
lpCommon: Pointer;
btnInfo: TTBBUTTON;
dwBytes: DWORD;
szBuf: array[0..512] of char;
i, nBtnCount: Integer;
begin
GetWindowThreadProcessId(hWin, @dwPID);
hProc := OpenProcess(PROCESS_VM_OPERATION or
PROCESS_VM_READ or PROCESS_VM_WRITE, false, dwPID);
lpCommon := VirtualAllocEx(hProc, nil, 4096,
MEM_RESERVE or MEM_COMMIT, PAGE_READWRITE);

nBtnCount := SendMessage(hWin, TB_BUTTONCOUNT, 0, 0);
for i := 0 to nBtnCount do
begin
ZeroMemory(@btnInfo, sizeof(btnInfo));
WriteProcessMemory(hProc, lpCommon, @btnInfo, sizeof(btnInfo), dwBytes);

SendMessage(hWin, TB_GETBUTTON, i, LPARAM(lpCommon));
ReadProcessMemory(hProc, lpCommon, @btnInfo, sizeof(btnInfo), dwBytes);

SendMessage(hWin, TB_GETBUTTONTEXT, btnInfo.idCommand,
LPARAM(LPARAM(lpCommon) + sizeof(btnInfo)));
ReadProcessMemory(hProc, Pointer(LPARAM(lpCommon) + sizeof(btnInfo)),
@szBuf, 512, dwBytes);
pList.Add(szBuf);
end;
VirtualFreeEx(hProc, lpCommon, 0, MEM_RELEASE);
CloseHandle(hProc);
result := nBtnCount;
end;

13,869

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder相关内容讨论区
社区管理员
  • 基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧