Thread: Need some help with the search for list view controls

  1. #1
    Registered User
    Join Date
    Mar 2002
    Posts
    112

    Need some help with the search for list view controls

    Hey, im having some troubles with the search for list view controls. No matter what i use for text the search always comes back with some really wack number, like 42345151 or something. The code is below

    Code:
    	static LVFINDINFO searchInfo;
    	static int searchResult = 0;
    	switch(Message)
    	{
    		case WM_INITDIALOG:
    			searchInfo.flags = LVFI_STRING;
    			searchInfo.psz = "something";
    			InitListViewColumns(GetDlgItem(hwnd, IDC_MUSICLIST)); // This adds some stuff to the list view control
    			searchResult = SendMessage(GetDlgItem(hwnd, IDC_MUSICLIST), LVM_FINDITEM, -1, (LPARAM)&searchInfo);
    			SetDlgItemInt(hwnd, IDC_TOTAL_SONGS, searchResult, false);
    		break;

  2. #2
    Registered User
    Join Date
    Mar 2002
    Posts
    112
    ok, it works if i search for something in the first column. if i search for something another column or something thats not there it returns 4294967295.

  3. #3
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    Try casting the return (LRESULT) as an int

    iReturn = (int)SendMessage(

    and see if it is actually returning -1 (meaning that it has failed to match)
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  4. #4
    Registered User
    Join Date
    Mar 2002
    Posts
    112
    nope, it still says 4294967295. I think it is just becuase it is failing though. Does LVM_FINDITEM not work for text in columns other than the first one? If it doesn't than is there a way to have it search these columns?

  5. #5
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    If it matches it should return the zero based index, if failed it should return -1. (Try cast as a UINT as I am pretty sure the 4294967295 [== UINT_MAX or 0xffffffff] is -1)

    How do you ask it to search subitems? AFAIK you can only ask it to search items (1st column).
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  6. #6
    Registered User
    Join Date
    Mar 2002
    Posts
    112
    lol, i found the problem. i was sending the return value to a static text. when you send -1, it displays 4294967295.

    I wrote my own search that looks in subitems too. I just need to know what the list-view control equivalant of LB_SETCURSEL is. I can't find this on msdn, i tried LVM_SETHOTITEM but that turns the text blue, not highlights it.
    Last edited by pinkcheese; 07-05-2002 at 03:21 PM.

  7. #7
    Registered User
    Join Date
    Mar 2002
    Posts
    112
    one more thing, what is the list view equivalant of LB_SETCURSEL?

  8. #8
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    You get a LVN_ITEMCHANGED msg when changed
    Code:
    LView = (NM_LISTVIEW FAR *) lParam;
    if(LVN_ITEMCHANGED==LView->hdr.code)
       if((LView->uNewState==3))//lost the #define for this state
           iSelected=LView->iItem;
    or Listview_GetHotItem() macro

    or SendMessage() with LVM_GETHOTITEM
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Allowing my search function to search sub directories!
    By Queatrix in forum Windows Programming
    Replies: 10
    Last Post: 09-30-2005, 04:54 PM
  2. Search Engine - Binary Search Tree
    By Gecko2099 in forum C Programming
    Replies: 9
    Last Post: 04-17-2005, 02:56 PM
  3. Question 39: Quicksort vs Linear Search
    By Kleid-0 in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 04-17-2005, 11:03 AM
  4. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 09:44 AM
  5. Determining Active View :: MFC
    By kuphryn in forum Windows Programming
    Replies: 0
    Last Post: 04-25-2002, 07:34 PM