200分求助!如何让我的程序选中其他程序中listview控件的某一行(200分)

  • 主题发起人 主题发起人 kunian
  • 开始时间 开始时间
K

kunian

Unregistered / Unconfirmed
GUEST, unregistred user!
如题,假设B程序里有一个syslistview32控件,启动后没有焦点.我的程序要选中这个syslistview32控件中的某一行,该如何实现?
 
补充一下,最好能有一定的源码
 
已经得到了那个程序的ListView的句柄吗?<br><br>如果该Listview句柄已经得到了,最好办<br>ListView_SetSelectionMark(Listview的句柄, 需要选定的行[0为起始])
 
已经抓到那个控件的句柄了,我试试你的方法,能用的话马上给分
 
ListView_SetSelectionMark是哪个库里面的函数??
 
是一个宏<br>在CommCtrl.pas中定义<br><br>也可以发消息:SendMessage(ListView_Handle, LVM_SETSELECTIONMARK, 0, i);
 
to smithcouple:你的函数仍在熟悉中,我自己找到一个别人写好的过程,我试过了确实能用,给大家分享下<br>//参考如下代码~~<br>//原理:可以通过消息LVM_SETITEMSTATE设置各项的状态,lparam参数是一个局部指针,所以需要把数据填写在该进程空间里~~<br>uses CommCtrl;<br><br>procedure SetListViewIndex(mHandle: THandle; mIndex: Integer);<br>var<br>vProcessId: DWORD;<br>vProcess: THandle;<br>vPointer: Pointer;<br>vNumberOfBytesRead: Cardinal;<br>vItem: TLVItem;<br>begin<br>GetWindowThreadProcessId(mHandle, @vProcessId);<br>vProcess := OpenProcess(PROCESS_VM_OPERATION or PROCESS_VM_READ or<br>PROCESS_VM_WRITE, False, vProcessId);<br>vPointer := VirtualAllocEx(vProcess, nil, 4096, MEM_RESERVE or MEM_COMMIT,<br>PAGE_READWRITE);<br>try<br>vItem.stateMask := LVIS_FOCUSED;<br>vItem.state := LVIS_FOCUSED;<br>WriteProcessMemory(vProcess, vPointer, @vItem,<br>SizeOf(TLVItem), vNumberOfBytesRead);<br>SendMessage(mHandle, LVM_SETITEMSTATE, mIndex, lparam(vPointer));<br><br>vItem.stateMask := LVIS_SELECTED;<br>vItem.state := LVIS_SELECTED;<br>WriteProcessMemory(vProcess, vPointer, @vItem,<br>SizeOf(TLVItem), vNumberOfBytesRead);<br>SendMessage(mHandle, LVM_SETITEMSTATE, mIndex, lparam(vPointer));<br>finally<br>VirtualFreeEx(vProcess, vPointer, 0, MEM_RELEASE);<br>CloseHandle(vProcess);<br>end;<br>end; { SetListViewIndex }<br><br>procedure TForm1.SpeedButton1Click(Sender: TObject);<br>begin<br>SetListViewIndex(ListView1.Handle, 0);<br>end;
 
恩,也可以通过LVM_SETITEMSTATE消息设置,或者用ListView_SetItemState<br><br>Changes the state of an item in a list-view control. You can use this macro or send the LVM_SETITEMSTATE message explicitly. <br><br>Syntax<br><br>ListView_SetItemState(<br> &nbsp; &nbsp;HWND hwnd,<br> &nbsp; &nbsp;int i,<br> &nbsp; &nbsp;UINT state,<br> &nbsp; &nbsp;UINT mask<br>);<br><br>Parameters<br><br>hwnd<br>Handle to the list-view control. <br>i<br>Index of the list-view item. If this parameter is -1, then the state change is applied to all items. <br>state<br>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: <br>LVIS_CUT<br>The item is marked for a cut-and-paste operation.<br>LVIS_DROPHILITED<br>The item is highlighted as a drag-and-drop target.<br>LVIS_FOCUSED<br>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.<br>LVIS_SELECTED<br>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.<br>mask<br>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. <br>Return Value<br><br>No return value.
 
后退
顶部