unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,CommCtrl, StdCtrls, ComCtrls;
function VirtualAllocEx(hProcess: Cardinal; lpAddress: Pointer;
dwSize, flAllocationType, flProtect: Cardinal): Pointer; stdcall;
external kernel32 name 'VirtualAllocEx';
function VirtualFreeEx(hProcess: Cardinal; lpAddress: Pointer;
dwSize, dwFreeType: Cardinal): Boolean; stdcall;
external kernel32 name 'VirtualFreeEx';type
TForm1 = class(TForm)
MemoText: TMemo;
EditCount: TEdit;
Button1: TButton;
ListView1: TListView;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private { Private declarations }
public procedure WMHOTKEY(var Msg: TWMHOTKEY);
{ Public declarations }
end; const cHotKeyWinF2 = 1;
var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.FormCreate(Sender: TObject);
begin
Application.Title := '获取ListView内容 1.0';
Caption := Application.Title;
RegisterHotKey(Handle, cHotKeyWinF2, MOD_WIN, VK_F2);end;procedure TForm1.WMHOTKEY(var Msg: TWMHOTKEY);
var
I, J: Integer;
S: string;
vItem: TLVItem;
vCount: Integer;
vHandle: THandle;
vBuffer: array[0..255] of Char;
pBuffer: PChar;
vProcess: THandle;
vProcessId: DWORD;
vPointer: Pointer;
vNumberOfBytesRead: Cardinal;
begin
case Msg.HotKey of
cHotKeyWinF2: begin
MemoText.Clear;
FillChar(vBuffer, 256, 0);
vHandle := WindowFromPoint(Point(Mouse.CursorPos.X, Mouse.CursorPos.Y));
vCount := ListView_GetItemCount(vHandle);
if vCount = 0 then Exit;
GetWindowThreadProcessId(vHandle, @vProcessId);
vProcess := OpenProcess(PROCESS_VM_OPERATION or PROCESS_VM_READ or
PROCESS_VM_WRITE, False, vProcessId);
vPointer := VirtualAllocEx(vProcess, nil, 4096, MEM_RESERVE or MEM_COMMIT,
PAGE_READWRITE);
try
for I := 0 to vCount - 1 do begin
S := '';
for J := 0 to StrToIntDef(EditCount.Text, 0) - 1 do begin
with vItem do begin
mask := LVIF_TEXT;
iItem := I;
iSubItem := J;
cchTextMax := 255;
pszText := Pointer(Cardinal(vPointer) + SizeOf(TLVItem));
end;
WriteProcessMemory(vProcess, vPointer, @vItem,
SizeOf(TLVItem), vNumberOfBytesRead);
SendMessage(vHandle, LVM_GETITEM, I, lparam(vPointer));
pBuffer := vBuffer;
ReadProcessMemory(vProcess, Pointer(Cardinal(vPointer) + SizeOf(TLVItem)),
pBuffer, DWORD(256), vNumberOfBytesRead);
S := S + #9 + vBuffer;
end;
Delete(S, 1, 1);
MemoText.Lines.Add(S);
end;
finally
VirtualFreeEx(vProcess, vPointer, 0, MEM_RELEASE);
CloseHandle(vProcess);
end;
end;
end;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
UnRegisterHotKey(Handle, cHotKeyWinF2);
end;end.想得到另一个程序listview里的记录的值, 显示在 memo里面,这段代码根本不起作用。 但可以运行
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,CommCtrl, StdCtrls, ComCtrls;
function VirtualAllocEx(hProcess: Cardinal; lpAddress: Pointer;
dwSize, flAllocationType, flProtect: Cardinal): Pointer; stdcall;
external kernel32 name 'VirtualAllocEx';
function VirtualFreeEx(hProcess: Cardinal; lpAddress: Pointer;
dwSize, dwFreeType: Cardinal): Boolean; stdcall;
external kernel32 name 'VirtualFreeEx';type
TForm1 = class(TForm)
MemoText: TMemo;
EditCount: TEdit;
Button1: TButton;
ListView1: TListView;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private { Private declarations }
public procedure WMHOTKEY(var Msg: TWMHOTKEY);
{ Public declarations }
end; const cHotKeyWinF2 = 1;
var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.FormCreate(Sender: TObject);
begin
Application.Title := '获取ListView内容 1.0';
Caption := Application.Title;
RegisterHotKey(Handle, cHotKeyWinF2, MOD_WIN, VK_F2);end;procedure TForm1.WMHOTKEY(var Msg: TWMHOTKEY);
var
I, J: Integer;
S: string;
vItem: TLVItem;
vCount: Integer;
vHandle: THandle;
vBuffer: array[0..255] of Char;
pBuffer: PChar;
vProcess: THandle;
vProcessId: DWORD;
vPointer: Pointer;
vNumberOfBytesRead: Cardinal;
begin
case Msg.HotKey of
cHotKeyWinF2: begin
MemoText.Clear;
FillChar(vBuffer, 256, 0);
vHandle := WindowFromPoint(Point(Mouse.CursorPos.X, Mouse.CursorPos.Y));
vCount := ListView_GetItemCount(vHandle);
if vCount = 0 then Exit;
GetWindowThreadProcessId(vHandle, @vProcessId);
vProcess := OpenProcess(PROCESS_VM_OPERATION or PROCESS_VM_READ or
PROCESS_VM_WRITE, False, vProcessId);
vPointer := VirtualAllocEx(vProcess, nil, 4096, MEM_RESERVE or MEM_COMMIT,
PAGE_READWRITE);
try
for I := 0 to vCount - 1 do begin
S := '';
for J := 0 to StrToIntDef(EditCount.Text, 0) - 1 do begin
with vItem do begin
mask := LVIF_TEXT;
iItem := I;
iSubItem := J;
cchTextMax := 255;
pszText := Pointer(Cardinal(vPointer) + SizeOf(TLVItem));
end;
WriteProcessMemory(vProcess, vPointer, @vItem,
SizeOf(TLVItem), vNumberOfBytesRead);
SendMessage(vHandle, LVM_GETITEM, I, lparam(vPointer));
pBuffer := vBuffer;
ReadProcessMemory(vProcess, Pointer(Cardinal(vPointer) + SizeOf(TLVItem)),
pBuffer, DWORD(256), vNumberOfBytesRead);
S := S + #9 + vBuffer;
end;
Delete(S, 1, 1);
MemoText.Lines.Add(S);
end;
finally
VirtualFreeEx(vProcess, vPointer, 0, MEM_RELEASE);
CloseHandle(vProcess);
end;
end;
end;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
UnRegisterHotKey(Handle, cHotKeyWinF2);
end;end.想得到另一个程序listview里的记录的值, 显示在 memo里面,这段代码根本不起作用。 但可以运行
解决方案 »
- 我现在想获取宽带连接列表
- 高手帮忙来解决下:为什么整个打包后拿到另外机子上就不能运行?
- *****************关于计划任务的设计**********************
- fastreport简单问题,急,各位高手请进,解决马上给分!!!!
- 求教,怎么在读记录的时候用数组形式分别读出每个厂家的单个信息和整体信息
- 要實現禁止或者允許網頁彈出窗口功能
- 急急:Panel控件问题 我想在Panel上定位输出文字应该怎么写啊???
- 如何全屏播放影片????????
- SOS,SOS请各位大侠帮忙!!!!!!!!!!
- 在DELPHI中如何将.db或.dbf的数据导入到.mdb(Access库)里?
- 苦命的哇啊...ACCESS压缩怎么老不行啊..
- 你说我象雨,忽远忽近,其实你不懂我的心。。。。。。。。。。。。。。
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,CommCtrl, StdCtrls, ComCtrls;
type
TForm1 = class(TForm)
MemoText: TMemo;
EditCount: TEdit;
ListView1: TListView;
Edit1: TEdit;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private { Private declarations }
public procedure WMHOTKEY(var Msg: TWMHOTKEY); message WM_HOTKEY;
{ Public declarations }
end; const cHotKeyWinF2 = 1;
var
Form1: TForm1;implementation
function VirtualAllocEx(hProcess: Cardinal; lpAddress: Pointer;
dwSize, flAllocationType, flProtect: Cardinal): Pointer; stdcall;
external kernel32 name 'VirtualAllocEx';
function VirtualFreeEx(hProcess: Cardinal; lpAddress: Pointer;
dwSize, dwFreeType: Cardinal): Boolean; stdcall;
external kernel32 name 'VirtualFreeEx';
{$R *.dfm}procedure TForm1.FormCreate(Sender: TObject);
begin
Application.Title := '获取ListView内容 1.0';
Caption := Application.Title;
RegisterHotKey(Handle, cHotKeyWinF2, MOD_WIN, VK_F2);end;procedure Tform1.WMHOTKEY(var Msg: TWMHOTKEY);
var
I, J: Integer;
S: string;
vItem: TLVItem;
vCount: Integer;
vHandle: THandle;
vBuffer: array[0..255] of Char;
pBuffer: PChar;
vProcess: THandle;
vProcessId: DWORD;
vPointer: Pointer;
vNumberOfBytesRead: Cardinal;
begin
case Msg.HotKey of
cHotKeyWinF2: begin
MemoText.Clear;
FillChar(vBuffer, 256, 0);
vHandle := WindowFromPoint(Point(Mouse.CursorPos.X, Mouse.CursorPos.Y));
vCount := ListView_GetItemCount(vHandle);
if vCount = 0 then Exit;
GetWindowThreadProcessId(vHandle, @vProcessId);
vProcess := OpenProcess(PROCESS_VM_OPERATION or PROCESS_VM_READ or
PROCESS_VM_WRITE, False, vProcessId);
vPointer := VirtualAllocEx(vProcess, nil, 4096, MEM_RESERVE or MEM_COMMIT,
PAGE_READWRITE);
try
EditCount.Text:=inttostr(Vcount);
for I := 0 to vCount - 1 do begin
S := '';
for J := 0 to StrToIntDef(EditCount.Text, 0) - 1 do begin
with vItem do begin
mask := LVIF_TEXT;
iItem := I;
iSubItem := J;
cchTextMax := 255;
pszText := Pointer(Cardinal(vPointer) + SizeOf(TLVItem));
end;
WriteProcessMemory(vProcess, vPointer, @vItem,
SizeOf(TLVItem), vNumberOfBytesRead);
SendMessage(vHandle, LVM_GETITEM, I, lparam(vPointer));
pBuffer := vBuffer;
ReadProcessMemory(vProcess, Pointer(Cardinal(vPointer) + SizeOf(TLVItem)),
pBuffer, DWORD(256), vNumberOfBytesRead);
edit1.text:=pchar(s);
S := S +#9+ vBuffer;
end;
Delete(S, 1, 1);
MemoText.Lines.Add(S);
end;
finally
VirtualFreeEx(vProcess, vPointer, 0, MEM_RELEASE);
CloseHandle(vProcess);
end;
end;
end;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
UnRegisterHotKey(Handle, cHotKeyWinF2);
end;end.在另一程序有一条记录
张三
为什么取出来的变成了
o?
{ Private declarations }
public
procedure WMHOTKEY(var Msg: TWMHOTKEY); <---如果是消息语句的话那应该是
----> procedure WMHOTKEY(var Msg: TWMHOTKEY); message WM_HOTKEY;
{ Public declarations }
end;当有WM_HOTKEY消息的时候将执行procedure WMHOTKEY(var Msg: TWMHOTKEY); 这个过程。