全部博文(788)
分类:
2009-04-08 09:22:44
什么现在还没有人回复我!!!
//测试如下代码
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;