Hi below is my code to
select all items on Another "Third Party Application" SysLisView items. It is not listview control within my application.
[DllImport("user32.dll", EntryPoint = "SendMessage", CharSet = CharSet.Auto)]
public static extern IntPtr SendMessageLVItem(HandleRef hWnd, int msg, int wParam, ref LVITEM lvi);
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public struct LVITEM
{
public int mask;
public int iItem;
public int iSubItem;
public int state;
public int stateMask;
[MarshalAs(UnmanagedType.LPTStr)]
public string pszText;
public int cchTextMax;
public int iImage;
public IntPtr lParam;
public int iIndent;
public int iGroupId;
public int cColumns;
public IntPtr puColumns;
}
IntPtr SysListView = getlistviewhandle();
LVITEM lvi = new LVITEM();
const int LVM_FIRST = 0x1000;
const int LVM_SETITEMSTATE = LVM_FIRST + 43;
const int LVIS_SELECTED = 0x0002;
const int LVIS_FOCUSED = 0x0002;
const int LVIF_STATE = 0x0008;
lvi.stateMask = LVIS_FOCUSED | LVIS_SELECTED;
lvi.state = LVIS_FOCUSED | LVIS_SELECTED;
lvi.mask = LVIF_STATE;
IntPtr dc = SendMessageLVItem(new HandleRef(SysListView, SysListView), LVM_SETITEMSTATE, -1, ref lvi);
This above code should work as per msdn documentation that I read. But it's not selecting any items in another process listview. Handle to listview is correct. I confirmed also that no wm_command seen in spy++. Only messages I saw in spy++ was setitemstate when I select manually all items using ctrl+a.
When i set lvi items structure to like below it deselect all selected rows.
lvi.stateMask = 2;
lvi.state = 0;
lvi.mask = LVIF_STATE;
but when I used it like this as per msdn documentation, it won't work.
lvi.stateMask = 2;
lvi.state = 2;
lvi.mask = LVIF_STATE;
Am I missing something in lvi structure? Please let me know if you know a solution.