(独帅请进!)取得外部程序控件(syslistview32)的文本问题(100分)

  • 主题发起人 主题发起人 semsy
  • 开始时间 开始时间
S

semsy

Unregistered / Unconfirmed
GUEST, unregistred user!
有一个外部程序,它拥有一个SysListView32的控件,我想取得或修改其中一列的文字该怎么办?
下面为什么不行??
function GetTreeSelectText(const TreeHand: HWND): String;
var
hCurItem: HTREEITEM;
lNodeText: String;
ltvItem: TTVItem;
h: HWND;
C, i: integer;
Buff: PChar;
S: array[0..1024] of char;
PID: THandle;
PRC: THandle;
R: Cardinal;
begin
Result := '';

hCurItem := HTREEITEM(SendMessage( TreeHand, TVM_GETNEXTITEM, TVGN_CARET, 0 ));

if (hCurItem = nil) then Exit;

GetWindowThreadProcessId(TreeHand, @PID);
PRC := OpenProcess(PROCESS_VM_OPERATION or PROCESS_VM_READ or PROCESS_VM_WRITE, False, PID);
Buff := VirtualAllocEx(PRC, nil, 4096, MEM_RESERVE or MEM_COMMIT, PAGE_READWRITE);

FillChar(ltvItem, SizeOf(ltvItem), 0);
with ltvItem do
begin
mask := TVIF_TEXT;
hItem := hCurItem;
cchTextMax := 2048;
pszText := PChar(integer(Buff) + SizeOf(ltvItem) * 4);
end;

WriteProcessMemory(PRC, Buff, @ltvItem, Sizeof(ltvItem), R);
SendMessage(TreeHand, TVM_GETITEM, 0, LongInt(Buff));

ReadProcessMemory(PRC, Buff, @ltvItem, Sizeof(ltvItem), R);
ReadProcessMemory(PRC, PChar(integer(Buff) + SizeOf(ltvItem) * 4), @S[0], SizeOf(S), R);
Result := Trim(S);

VirtualFreeEx(PRC, Buff, 0, MEM_RELEASE);
CloseHandle(PRC);
end;

procedure TForm1.Button1Click(Sender: TObject);
var
s:string;
hwnd1,hwnd2:longint;
begin
hwnd1:=findwindow(nil,'convert');
hwnd2:=FindWindowEx(HWnd1,0, PChar('SysListView32'),nil);
label1.caption:=GetTreeSelectText(hwnd2);
//showmessage(GetTreeSelectText(hwnd2))
end;
 
谁能伸出您的援助之手,帮帮小弟吧!
 
后退
顶部