当前位置:主页>仓库管理软件> 列表

200分求助!如何让我的程序选中其他程序中listview 找最好的进销存软件

记账软件版1楼: 如题,假设B程序里有一个syslistview32控件,启动后没有焦点.我的程序要选中这个syslistview32控件中的某一行,该如何实现?

2楼: 补充一下,最好能有一定的源码 如最好的进销存软件

3楼: 已经得到了那个程序的ListView的句柄吗?

如果该Listview句柄已经得到了,最好办
ListView_SetSelectionMark(Listview的句柄, 需要选定的行[0为起始])

4楼: 已经抓到那个控件的句柄了,我试试你的方法,能用的话马上给分

5楼: ListView_SetSelectionMark是哪个库里面的函数??

6楼: 是一个宏
在CommCtrl.pas中定义

也可以发消息:SendMessage(ListView_Handle, LVM_SETSELECTIONMARK, 0, i);

记账软件版7楼: to smithcouple:你的函数仍在熟悉中,我自己找到一个别人写好的过程,我试过了确实能用,给大家分享下
//参考如下代码~~
//原理:可以通过消息LVM_SETITEMSTATE设置各项的状态,lparam参数是一个局部指针,所以需要把数据填写在该进程空间里~~
uses CommCtrl;

procedure SetListViewIndex(mHandle: THandle; mIndex: Integer);
var
vProcessId: DWORD;


vProcess: THandle;
vPointer: Pointer;
vNumberOfBytesRead: Cardinal;
vItem: TLVItem;
begin
GetWindowThreadProcessId(mHandle, @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
vItem.stateMask := LVIS_FOCUSED;
vItem.state := LVIS_FOCUSED;
WriteProcessMemory(vProcess, vPointer, @vItem,
SizeOf(TLVItem), vNumberOfBytesRead);
SendMessage(mHandle, LVM_SETITEMSTATE, mIndex, lparam(vPointer));

vItem.stateMask := LVIS_SELECTED;
vItem.state := LVIS_SELECTED;
WriteProcessMemory(vProcess, vPointer, @vItem,
SizeOf(TLVItem), vNumberOfBytesRead);
SendMessage(mHandle, LVM_SETITEMSTATE, mIndex, lparam(vPointer));
finally
VirtualFreeEx(vProcess, vPointer, 0, MEM_RELEASE);
CloseHandle(vProcess);
end;
end; { SetListViewIndex }

procedure TForm1.SpeedButton1Click(Sender: TObject);
begin

SetListViewIndex(ListView1.Handle, 0);
end;

8楼: 恩,也可以通过LVM_SETITEMSTATE消息设置,或者用ListView_SetItemState

Changes the state of an item in a list-view control. You can use this macro or send the LVM_SETITEMSTATE message explicitly.

Syntax

ListView_SetItemState(
HWND hwnd,
int i,
UINT state,
UINT mask
);

Parameters

hwnd
Handle to the list-view control.
i
Index of the list-view item. If this parameter is -1, then the state change is applied to all items.
state
New state bits for the item. The mask parameter indicates the valid bits of the state parameter. The macro ignores bits in the state parameter if the corresponding bit is not set in the mask parameter. The low-order byte contains a set of bit flags that indicate the item''s state. This byte can be a combination of the following values:
LVIS_CUT
The item is marked for a cut-and-paste operation.
LVIS_DROPHILITED
The item is highlighted as a drag-and-drop target.
LVIS_FOCUSED
The item has the focus, so it is surrounded by a standard focus rectangle. Although more than one item may be selected, only one item can have the focus.
LVIS_SELECTED
The item is selected. The appearance of a selected item depends on whether it has the focus and also on the system colors used for selection. Items will only show as selected if the list-view control has focus or the LVS_SHOWSELALWAYS style is used.
mask
Bits of the state parameter that you want to set or clear. You can use ListView_SetItemState both to set and to clear bits. To set an item''s overlay image index, set the LVIS_OVERLAYMASK bits. To set an item''s state image index, set the LVIS_STATEIMAGEMASK bits.
Return Value

No return value.

9楼: 感谢