全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:2316
推到 Plurk!
推到 Facebook!

如何抓取其他AP的物件欄位的值呢?

答題得分者是:hagar
gerojeng
一般會員


發表:23
回覆:25
積分:9
註冊:2004-06-19

發送簡訊給我
#1 引用回覆 回覆 發表時間:2010-07-08 16:23:52 IP:219.71.xxx.xxx 訂閱
公司裡有一個程式,因為原始碼也遺失了
但又需要把裡面的值撈出來處理

要撈的內容看起來是放在 TListView 或者 TStringGrid 裡面

我GOOGLE後已經可以用 FindWindow 去取的該程式的Handle , 但是取到該程式的 TListView 的 Handle 之後,該怎樣進一步的取出裡面特定欄位的內容
就不是很清楚了,網路上大多查到的只是SendMessage送一些事件給對象Handle,請高人指點,感謝

hagar
版主


發表:143
回覆:4056
積分:4445
註冊:2002-04-14

發送簡訊給我
#2 引用回覆 回覆 發表時間:2010-07-08 16:51:38 IP:210.242.xxx.xxx 未訂閱
參考這篇試試: http://www.experts-exchange.com/Programming/Languages/Pascal/Delphi/Q_20750630.html


unit PrcMemMgrTestForm;

{

author: Michael Winter, delphi.net@gmx.net
ver: 0.1, 2000-02-26
desc:
Simple test and demo program that should show how to use uProcessMemMgr.
Captures the content of a listview control, even from inside another process
(e. g. the Desktop window in Explorer).
For demonstration, the foreign listview content is written into a stream, after
that the stream is used to fill the MainForm's own listview.

notes:
Position the mouse over a listview window. You can see the window's class name
in the caption of the main form. To capture, press F12.
Please report any problems with this unit to the email address above.

}

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
ExtCtrls, ComCtrls, StdCtrls;

type
TMainForm = class(TForm)
Timer1: TTimer;
lvTestListView: TListView;
procedure Timer1Timer(Sender: TObject);
private
procedure FindCPUIdleLVHandle;
procedure GrabListView(W: HWND);
end;

var
MainForm: TMainForm;
CPUIdleLVHandle: THandle;

implementation

{$R *.DFM}

uses
CommCtrl, uProcessMemMgr;

procedure ForeignListViewToStream(Wnd: HWND; Writer: TWriter);
const
MaxTextLen = 1024;
var
MemMgr: TProcessMemMgr;
Column: TLVColumn;
Item: TLVItem;
c, i: Integer;
ColCount: Integer;
Ok: Boolean;
// these Pointers are Pointers into the possibly foreign process
PrItemText: PChar;
PrColumn: PLVColumn;
PrItem: PLVItem;
begin
MemMgr := CreateProcessMemMgrForWnd(Wnd);
try
PrItemText := MemMgr.AllocMem(MaxTextLen);
PrColumn := MemMgr.AllocMem(SizeOf(TLVColumn));
PrItem := MemMgr.AllocMem(SizeOf(TLVItem));

// write Colunms
c := 0;
repeat
Column.mask := LVCF_FMT or LVCF_WIDTH or LVCF_TEXT;
Column.pszText := PrItemText;
Column.cchTextMax := MaxTextLen;
MemMgr.Write(Column, PrColumn, SizeOf(TLVColumn));
Ok := ListView_GetColumn(Wnd, c, PrColumn^);
if Ok then begin
MemMgr.Read(PrColumn, Column, SizeOf(TLVColumn));
Writer.WriteBoolean(true);
Writer.WriteString(MemMgr.ReadStr(Column.pszText));
case Column.fmt of
LVCFMT_RIGHT: Writer.WriteInteger(ord(taRightJustify));
LVCFMT_CENTER: Writer.WriteInteger(ord(taCenter))
else Writer.WriteInteger(ord(taLeftJustify));
end;
Writer.WriteInteger(Column.cx);
inc(c);
end;
until not Ok;
ColCount := c;
if ColCount = 0 then ColCount := 1;
Writer.WriteBoolean(false);

// write items
i := ListView_GetNextItem(Wnd, -1, LVNI_ALL);
while i >= 0 do begin
Writer.WriteBoolean(true);
for c := 0 to ColCount - 1 do begin
Item.mask := LVIF_TEXT;
Item.iItem := i;
Item.iSubItem := c;
Item.pszText := PrItemText;
Item.cchTextMax := MaxTextLen;
MemMgr.Write(Item, PrItem, SizeOf(TLVItem));
ListView_GetItem(Wnd, PrItem^);
MemMgr.Read(PrItem, Item, SizeOf(TLVItem));
Writer.WriteString(MemMgr.ReadStr(Item.pszText));
end;
i := ListView_GetNextItem(Wnd, i, LVNI_ALL);
end;
Writer.WriteBoolean(false);
finally
MemMgr.Free;
end;
end;

procedure StreamToListView(LV: TListView; Reader: TReader);
var
c: Integer;
begin
LV.Items.BeginUpdate;
try
LV.Items.Clear;
LV.Columns.Clear;

// read columns
while Reader.ReadBoolean do begin
with LV.Columns.Add do begin
Caption := Reader.ReadString;
Alignment := TAlignment(Reader.ReadInteger);
Width := Reader.ReadInteger;
end;
end;
if LV.Columns.Count = 0 then
LV.Columns.Add;

// read items
while Reader.ReadBoolean do begin
with LV.Items.Add do begin
Caption := Reader.ReadString;
for c := 1 to LV.Columns.Count - 1 do begin
SubItems.Add(Reader.ReadString);
end;
end;
end;
finally
LV.Items.EndUpdate;
end;
end;

function EnumChildProc(AHandle: hWnd; AnObject: TObject): BOOL; stdcall;
var
tmpS : string;
theClassName : string;
theWinText : string;
begin
Result := True;
SetLength(theClassName, 256);
GetClassName(AHandle, PChar(theClassName), 255);
SetLength(theWinText, 256);
GetWindowText(AHandle, PChar(theWinText), 255);
tmpS := StrPas(PChar(theClassName));
if theWinText <> EmptyStr then
tmpS := tmpS ' "'
StrPas(PChar(theWinText)) '"'
else
tmpS := tmpS '""';
if Pos(UpperCase('TListview'), UpperCase(tmpS)) > 0 then
begin
CPUIdleLVHandle := AHandle;
end;
end;

function CPUIdleWindowEnumProc(AHandle: hWnd; AnObject: TObject): BOOL; stdcall;
// callback for EnumWindows.
var
theClassName: string;
theWinText: string;
tmpS: string;
begin
Result := True;
SetLength(theClassName, 256);
GetClassName(AHandle, PChar(theClassName), 255);
SetLength(theWinText, 256);
GetWindowText(AHandle, PChar(theWinText), 255);
tmpS := StrPas(PChar(theClassName));
if theWinText <> EmptyStr then
tmpS := tmpS ' "'
StrPas(PChar(theWinText)) '"'
else
tmpS := tmpS '""';
if Pos(UpperCase('CpuIdle'), UpperCase(tmpS)) > 0 then
begin
EnumChildWindows(AHandle, @EnumChildProc, longInt(0));
end;
end;

procedure TMainForm.FindCPUIdleLVHandle;
begin
Screen.Cursor := crHourGlass;
try
EnumWindows(@CPUIdleWindowEnumProc, LongInt(0));
finally
Screen.Cursor := crDefault;
end;
end;

function GetWndClassName(Wnd: HWND): String;
var
S: Array[0..255] of Char;
begin
GetClassName(Wnd, S, 255);
Result := S;
end;

procedure TMainForm.GrabListView(W: HWND);
var
Stream: TStream;
Writer: TWriter;
Reader: TReader;
begin
Stream := TMemoryStream.Create;
try
Writer := TWriter.Create(Stream, 1024);
try
ForeignListViewToStream(W, Writer);
finally
Writer.Free;
end;
Stream.Position := 0;
Reader := TReader.Create(Stream, 1024);
try
StreamToListView(lvTestListView, Reader);
finally
Reader.Free;
end;
finally
Stream.Free;
end;
end;

procedure TMainForm.Timer1Timer(Sender: TObject);
var
W: HWND;
CName: String;
begin
// VERY IMPORTANT NOTE!!!!!
//
// CPUIdle MUST be open and focus on the Tab that contains the listview.
//
FindCPUIdleLVHandle;
if CPUIdleLVHandle > 0 then
begin
GrabListView(CPUIdleLVHandle);
end;
end;

end.
gerojeng
一般會員


發表:23
回覆:25
積分:9
註冊:2004-06-19

發送簡訊給我
#3 引用回覆 回覆 發表時間:2010-07-08 19:59:17 IP:219.71.xxx.xxx 訂閱
Wow...酷斃了

這就是我要的

Expert 上面好像有好多好東西呢,但是加入是要付月費的,猶豫中

系統時間:2024-05-09 1:47:54
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!