ToolBar上的ToolBotton按钮会没有句柄,怎样才能得到它的句柄呢? ( 积分: 50 )

  • 主题发起人 主题发起人 gzccjz
  • 开始时间 开始时间
G

gzccjz

Unregistered / Unconfirmed
GUEST, unregistred user!
ToolBar上的ToolBotton按钮会没有句柄,怎样才能得到它的句柄呢?
 
都有句柄,先找到TOOLBAR的句柄,再从它的子窗口句柄中找TOOLBOTTON句柄.
 
[red]解決了:[/red]
uses CommCtrl, Types;

procedure TForm1.Button1Click(Sender: TObject);
var
vHandle: THandle;
vIndex: Integer;
vRect: TRect;

vProcessId: DWORD;
vProcess: THandle;
vPointer: Pointer;
vNumberOfBytesRead: Cardinal;
begin
vHandle := ToolBar1.Handle; // 改写为其他进程ToolBar句柄
vIndex := 0; // 按钮序号

GetWindowThreadProcessId(vHandle, @vProcessId);
vProcess := OpenProcess(PROCESS_VM_OPERATION or PROCESS_VM_READ or
PROCESS_VM_WRITE, False, vProcessId);
vPointer := VirtualAllocEx(vProcess, nil, $1000, MEM_RESERVE or MEM_COMMIT,
PAGE_READWRITE);
try
SendMessage(vHandle, TB_GETITEMRECT, vIndex, Integer(vPointer));
ReadProcessMemory(vProcess, vPointer, @vRect, SizeOf(TRect),
vNumberOfBytesRead);
finally
VirtualFreeEx(vProcess, vPointer, 0, MEM_RELEASE);
CloseHandle(vProcess);
end;
SendMessage(vHandle, WM_LBUTTONDOWN, MK_LBUTTON,
Longint(PointToSmallPoint(CenterPoint(vRect))));
SendMessage(vHandle, WM_LBUTTONUP, MK_LBUTTON,
Longint(PointToSmallPoint(CenterPoint(vRect))));
end;
 
后退
顶部