Home > Back-end >  Send the external program Listview selected lines of commands
Send the external program Listview selected lines of commands

Time:10-12

As title, online have take Listview content of c + + code, can take to, but want to external application sends a message, make the Listview first record your choice

CodePudding user response:

USES CommCtrl;

Var
Item: TLVItem;
The begin
P:=VirtualAllocEx...//in the target process allocates memory
Item. StateMask:=LVIS_SELECTED;
Item. The state:=LVIS_SELECTED;
WriteProcessMemory...//will copy to the target Item data in this process the position p
SendMessage (hwndLV ListView handle} {goals, LVM_SETITEMSTATE, 0 {} article 1 records, Integer (p))
end;

CodePudding user response:

Refer to the
http://blog.csdn.net/xuplus/article/details/2294362

CodePudding user response:

The composite modified, http://blog.csdn.net/xuplus/article/details/2294362
Use the task manager test by

 
USES Commctrl;

//search window SysListView32

The function MyFindWindow: THandle;
Const
//parent window class name array
A_szClassName: array [0.. 2] of PChar=(
'# 32770,
'# 32770,
'SysListView32'
);
//parent window title array
A_szWinName: array [0.. 2] of PChar=(
'Windows task manager,
"',
'task'
);
Var
I: Integer;
HLastWin: THandle;
The begin
//top first obtained parent window
HLastWin:=FindWindow (A_szClassName [0], A_szWinName [0]).
//successive FindWindowEx function to find the child window at all levels
For I:=1 to 2 do
The begin
HLastWin:=FindWindowEx (hLastWin THandle (nil),
A_szWinName A_szClassName [I], [I]);
end;
Result:=hLastWin;
end;

Procedure TForm1. SetItemSelected (nItemIndex: Integer);
Var
LVI_1: TLVItemA;
PLVI_2: PLVItemA;
NRet: LongBool;
TagPId: DWORD;
TagPHandle: THandle;
TagHwnd: THandle;
LpNumOfBytesW: Cardinal;
The begin
TagPId:=0;
TagPHandle:=0;
TagHwnd:=0;
LpNumOfBytesW:=0;

TagHwnd:=FindWindow (' # 32770 ', 'Windows task manager).
If tagHwnd & lt; 1 then
The Exit;

Try
GetWindowThreadProcessId (tagHwnd, @ tagPId);//get the process ID
TagPHandle:=OpenProcess (
PROCESS_ALL_ACCESS, False, tagPId);//handle to obtain process
Except,
The CloseHandle (tagPHandle);
end;

Try
//apply to the process of target remote memory space
PLVI_2:=VirtualAllocEx (
TagPHandle, nil, SizeOf (TLVItemA), MEM_COMMIT, PAGE_READWRITE);
Assert ((pLVI_2 & lt;> Nil), 'remote memory application failure);

LVI_1. Mask:=LVIF_STATE;
LVI_1. ISubItem:=0;
LVI_1. State:=LVIS_SELECTED or LVIS_FOCUSED;
LVI_1. StateMask:=LVIS_SELECTED or LVIS_FOCUSED;

NRet:=WriteProcessMemory (//will be written to the target process in the process of the local structure
TagPHandle pLVI_2, @ LVI_1, SizeOf (TLVItemA), lpNumOfBytesW);
Assert ((nRet), 'target process writing failure);

TagHwnd:=MyFindWindow;
If tagHwnd & lt; 1 then
The Exit;
SendMessage (tagHwnd LVM_SETITEMSTATE, Integer (nItemIndex),
Integer (pLVI_2));
Except,
VirtualFreeEx (tagPHandle, nil, SizeOf (PLVItem), MEM_FREE);
end;

The CloseHandle (tagPHandle);
VirtualFreeEx (tagPHandle, nil, SizeOf (PLVItem), MEM_FREE);
end;



//do test with XP's task manager
Procedure TForm1. Btn1Click (Sender: TObject);
The begin
//select the task manager - & gt; Under the application of item 2,
SetItemSelected (1);
end;

CodePudding user response:

reference 1st floor s11ss response:
USES CommCtrl;

Var
Item: TLVItem;
The begin
P:=VirtualAllocEx...//in the target process allocates memory
Item. StateMask:=LVIS_SELECTED;
Item. The state:=LVIS_SELECTED;
WriteProcessMemory...//will copy to the target Item data in this process the position p
SendMessage (hwndLV ListView handle} {goals, LVM_SETITEMSTATE, 0 {} article 1 records, Integer (p))
end;

You say I can realize it is grey selected, rather than a normal we write their own kind of blue light, I do not want to heightening selected when clicking there could be an edit box shows its value, but I use Sendmessage send selected just gray tone and edit no reaction,

CodePudding user response:

Q296361388
reference 4 floor response:
Quote: refer to 1st floor s11ss response:

USES CommCtrl;

Var
Item: TLVItem;
The begin
P:=VirtualAllocEx...//in the target process allocates memory
Item. StateMask:=LVIS_SELECTED;
Item. The state:=LVIS_SELECTED;
WriteProcessMemory...//will copy to the target Item data in this process the position p
SendMessage (hwndLV ListView handle} {goals, LVM_SETITEMSTATE, 0 {} article 1 records, Integer (p))
end;

You say I can realize now is selected, gray rather than a normal we write their own kind of blue light, I do not want to heightening selected when clicking there could be an edit box shows its value, but I use Sendmessage send selected just gray tone and edit no reaction,
LVM_EDITLABEL
  • Related