Skip to content

selecting item in listview

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #191416
    nooob
    Member

    i am trying to select (highlight) an item in pal nicklist…and also to get the selected item’s index

    i got tired from searching the net…so got back to you nanomachine eventhough you are doing your own project….

    i couldn’t find any lvm messages like LVM_GETSELECTEDINDEX …etc

    plz help me dude

    nooob

    #191422
    public static void SelectListViewItem(IntPtr hWnd, int item)
    {
    
    
    int dwProcessID;
    LV_ITEM lvItem ;
    string retval;
    bool bSuccess;
    IntPtr hProcess = IntPtr.Zero;
    IntPtr lpRemoteBuffer = IntPtr.Zero;
    IntPtr lpLocalBuffer = IntPtr.Zero;
    IntPtr threadId = IntPtr.Zero;
    
    try
    {
    lvItem = new LV_ITEM();
    
    // Get the process id owning the window
    threadId = GetWindowThreadProcessId(hWnd, out dwProcessID);
    if ((threadId == IntPtr.Zero) || (dwProcessID == 0))
    throw new ArgumentException("hWnd");
    
    // Open the process with all access
    hProcess = OpenProcess(PROCESS_ALL_ACCESS, false, dwProcessID);
    if (hProcess == IntPtr.Zero)
    throw new ApplicationException("Failed to access process");
    
    // Allocate a buffer in the remote process
    lpRemoteBuffer = VirtualAllocEx(hProcess, IntPtr.Zero, Marshal.SizeOf(typeof(LV_ITEM)), MEM_COMMIT,
    PAGE_READWRITE);
    if (lpRemoteBuffer == IntPtr.Zero)
    throw new SystemException("Failed to allocate memory in remote process");
    
    // Fill in the LVITEM struct, this is in your own process
    // Set the pszText member to somewhere in the remote buffer,
    // For the example I used the address imediately following the LVITEM stuct
    lvItem.mask = LVIF_STATE;
    
    lvItem.state = 15;
    lvItem.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
    
    // Copy the local LVITEM to the remote buffer
    bSuccess = WriteProcessMemory(hProcess, lpRemoteBuffer, ref lvItem,
    Marshal.SizeOf(typeof(LV_ITEM)), IntPtr.Zero);
    if (!bSuccess)
    throw new SystemException("Failed to write to process memory");
    
    // Send the message to the remote window with the address of the remote buffer
    SendMessage(hWnd, LVM_SETITEMSTATE, item, lpRemoteBuffer);
    
    
    }
    finally
    {
    
    if (lpRemoteBuffer != IntPtr.Zero)
    VirtualFreeEx(hProcess, lpRemoteBuffer, 0, MEM_RELEASE);
    if (hProcess != IntPtr.Zero)
    CloseHandle(hProcess);
    }
    
    }
    use this function like this
    int pos=0;
    SelectListViewItem(syslistview, pos);

    pos is the position of the item you want to select

    you need the constants bellow for that function

    const int LVIF_STATE = 0x0008;
    const int LVIS_SELECTED = 0x0002;
    const int LVIS_FOCUSED = 0x0001;
    const int LVM_SETITEMSTATE = LVM_FIRST + 43;

    and get the select item I dont have time to try and never try to do that too if you have solution for that, post here to share with me. maybe some day I will need to do that. i’m really busy at this time but select item by position is the code i already have had. I just adapted this to your code posted for u, I think it should help you understand it better if the code is semilar your code.

    #191421
    nooob
    Member

    great …dude…ty …it works perfectly

    and sure..if i somehow get to be able to find out how to get the selected item…i will post it


    i got another question…
    how do you differentiate between two child windows that have the same class name??

    in the paltalk room…the textarea(where you see text from other ppl) and the textfield (where you type your text) have the same class which is RichEdit20A…i want to send text to the textfield…but instead it gets posted to the textarea…because i think the textarea is before the textfield…? any tip

    thx for your time nanomachine

    nooob

    #191420

    the hint is in the FindWindowEx parameter

    see microsoft document for that. you find the first rich text class like this >>child1= FindWindowEx(parent,0,”winclasss here”,null)

    that will find the first child of parent has that class and you want find the next child in the same level and has same winclass do like this>>child2= FindWindowEx(parent,child1,”winclass here”,null)

    that you tell the function FindWindowEx find second child has same winclass beginning search at first child found.
    “winclass here” can be whatever window class 😮 8) ,see document for that function after my explanation, I think you will get it 😀

    child1= FindWindowEx(parent,0,”winclasss here”,null) << start seach at beginning

    #191419

    get item selected for a list view use LVM_GETNEXTITEM, search on that message on google I think you can find many examples. if I have time I will try to do that, cuz I never try to get selected item of external list view.

    EDIT:
    ah I can get position of item selected 😆

    int userpos = (int)::SendMessage(listview, LVM_GETNEXTITEM, -1, LVNI_FOCUSED);

    that work for c++, I will convert to c# soon 😆

    #191418

    c# code:

    int userpos = SendMessage(syslistview, LVM_GETNEXTITEM, -1,(IntPtr) LVIS_FOCUSED);

    define constant value:
    const int LVM_GETNEXTITEM = LVM_FIRST + 12;

    now you can get position of item selected use the code get item by position to get item text 🙂

    #191417
    nooob
    Member

    awesome…dude
    very nice….thxxxxxx nano

    i have come so far through your help… 😛 ……ty alot

    i got all that you said….it works
    i will stick to learning it…and will post any questions that i get

    ty once again

    nooob

Viewing 7 posts - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.