selecting item in listview

Here you can talk about C++ And C# And Other languages programming.

selecting item in listview

Postby nooob » Sat Sep 02, 2006 10:12 am


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
Water can make holes in rocks!
nooob
imFiles Junior
imFiles Junior
 
Posts: 52
Joined: Sun Jul 23, 2006 10:23 am

Postby BattleStar-Galactica » Sat Sep 02, 2006 5:51 pm

here is I adapted the last code you posted to do select item by position


Code: Select all

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.
User avatar
BattleStar-Galactica
imFiles Master
imFiles Master
 
Posts: 565
Joined: Tue Sep 20, 2005 12:19 am
Location: safest place to hide

Postby nooob » Sat Sep 02, 2006 9:06 pm

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
Water can make holes in rocks!
nooob
imFiles Junior
imFiles Junior
 
Posts: 52
Joined: Sun Jul 23, 2006 10:23 am

Postby BattleStar-Galactica » Sat Sep 02, 2006 10:48 pm

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 :o 8) ,see document for that function after my explanation, I think you will get it :D


child1= FindWindowEx(parent,0,"winclasss here",null) << start seach at beginning
User avatar
BattleStar-Galactica
imFiles Master
imFiles Master
 
Posts: 565
Joined: Tue Sep 20, 2005 12:19 am
Location: safest place to hide

Postby BattleStar-Galactica » Sat Sep 02, 2006 10:56 pm

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 :lol:

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

that work for c++, I will convert to c# soon :lol:
User avatar
BattleStar-Galactica
imFiles Master
imFiles Master
 
Posts: 565
Joined: Tue Sep 20, 2005 12:19 am
Location: safest place to hide

Postby BattleStar-Galactica » Sat Sep 02, 2006 11:33 pm

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 :)
User avatar
BattleStar-Galactica
imFiles Master
imFiles Master
 
Posts: 565
Joined: Tue Sep 20, 2005 12:19 am
Location: safest place to hide

Postby nooob » Sun Sep 03, 2006 11:10 am

awesome...dude
very nice....thxxxxxx nano

i have come so far through your help... :P ......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
Water can make holes in rocks!
nooob
imFiles Junior
imFiles Junior
 
Posts: 52
Joined: Sun Jul 23, 2006 10:23 am


Return to C++, C# And Others Programming

 


  • Related topics
    Replies
    Views
    Last post

Who is online

Users browsing this forum: No registered users and 0 guests