如何抓取其他AP的物件欄位的值呢? |
答題得分者是:hagar
|
gerojeng
一般會員 發表:23 回覆:25 積分:9 註冊:2004-06-19 發送簡訊給我 |
|
hagar
版主 發表:143 回覆:4056 積分:4445 註冊:2002-04-14 發送簡訊給我 |
參考這篇試試: 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(Wn 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( try PrItemText := MemMgr.AllocMem(MaxTextLen PrColumn := MemMgr.AllocMem(SizeOf(TLV PrItem := MemMgr.AllocMem(SizeOf(TLV // 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. case Column.fmt of LVCFMT_RIGHT: Writer.WriteInteger(ord(ta LVCFMT_CENTER: Writer.WriteInteger(ord(ta else Writer.WriteInteger(ord(ta end; Writer.WriteInteger(Column 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. 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.ReadInte 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.ReadSt 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') begin CPUIdleLVHandle := AHandle; end; end; function CPUIdleWindowEnumProc(AHan // 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.FindCPUIdleLVHan begin Screen.Cursor := crHourGlass; try EnumWindows(@CPUIdleWindow 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, finally Writer.Free; end; Stream.Position := 0; Reader := TReader.Create(Stream, 1024); try StreamToListView(lvTestLis finally Reader.Free; end; finally Stream.Free; end; end; procedure TMainForm.Timer1Timer(Send 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(CPUIdleLVHand end; end; end. |
gerojeng
一般會員 發表:23 回覆:25 積分:9 註冊:2004-06-19 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |