Thread: Listbox and IDs

  1. #1
    Registered User
    Join Date
    Nov 2004
    Location
    Slovenia, Europe
    Posts
    115

    Listbox and IDs

    Is there any way to add a string with ID in listbox??

    ID shouldn't be visible but it has to be readable again (e.g. on double click).

    Thanks for all answers!
    [C++]
    IDE: DevC++ 4.9.9.2 (GCC 3.4.2)
    2nd compiler: g++ (GCC 3.4.3/4.0.0)
    3rd compiler: Borland 5.5
    [C#]
    IDE: Microsoft Visual C# Express 2005
    2nd IDE: SharpDevelop
    2nd compiler: csc in Command Prompt
    .NET Framework: 2.0
    [PHP]
    Core: 5.1.0 beta 3
    IDE: PHPEdit
    2nd IDE: Notepad
    Favourite extensions: exif,gd2,mysql
    Favourite PEAR packages: DB, XML_RSS, ID3
    Favourite databases: SQLite, MySQL

  2. #2
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  3. #3
    Registered User
    Join Date
    Nov 2004
    Location
    Slovenia, Europe
    Posts
    115
    Thanks, but the same thing stopped me when I try to read this ID from listbox. On double click I send message LB_GETITEMDATA, but I don't know how to determine wParam upon the item that was double clicked...
    [C++]
    IDE: DevC++ 4.9.9.2 (GCC 3.4.2)
    2nd compiler: g++ (GCC 3.4.3/4.0.0)
    3rd compiler: Borland 5.5
    [C#]
    IDE: Microsoft Visual C# Express 2005
    2nd IDE: SharpDevelop
    2nd compiler: csc in Command Prompt
    .NET Framework: 2.0
    [PHP]
    Core: 5.1.0 beta 3
    IDE: PHPEdit
    2nd IDE: Notepad
    Favourite extensions: exif,gd2,mysql
    Favourite PEAR packages: DB, XML_RSS, ID3
    Favourite databases: SQLite, MySQL

  4. #4
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    >>how to determine wParam upon the item that was double clicked<<

    LB_GETCURSEL.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  5. #5
    Registered User
    Join Date
    Nov 2004
    Location
    Slovenia, Europe
    Posts
    115
    OK, everything works, but the problem is, I don't get the value I assigned with LB_SETITEMDATA, but some strange characters...

    Code on double click:

    Code:
     
    LRESULT index = SendDlgItemMessage(hwnd, IDLB_UPORABNIKI_PREGLED_SEZNAM, LB_GETCURSEL, 0, 0);
    	   if(index == LB_ERR)
    	   {
    		MessageBox(hwnd, "Error1!", "Error", MB_OK | MB_ICONERROR);
    	   }
    	   else
    	   {
    		LRESULT id = SendDlgItemMessage(hwnd, IDLB_UPORABNIKI_PREGLED_SEZNAM, LB_GETITEMDATA, (WPARAM)index, 0);
    		if(id == LB_ERR)
    		{
    		 MessageBox(hwnd, "Error2!", "Error", MB_OK | MB_ICONERROR);
    		}
    		else
    		{
    		 MessageBox(hwnd, (char*)id, "OK", MB_OK);
    		}
    	   }
    PS: It doesn't help if I change types of id and index to int or long int.
    [C++]
    IDE: DevC++ 4.9.9.2 (GCC 3.4.2)
    2nd compiler: g++ (GCC 3.4.3/4.0.0)
    3rd compiler: Borland 5.5
    [C#]
    IDE: Microsoft Visual C# Express 2005
    2nd IDE: SharpDevelop
    2nd compiler: csc in Command Prompt
    .NET Framework: 2.0
    [PHP]
    Core: 5.1.0 beta 3
    IDE: PHPEdit
    2nd IDE: Notepad
    Favourite extensions: exif,gd2,mysql
    Favourite PEAR packages: DB, XML_RSS, ID3
    Favourite databases: SQLite, MySQL

  6. #6
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    Looks like you're storing and retrieving a pointer to a string (char*) with each listbox item. If that's the case then you'll need to store those strings somewhere else with proper scope otherwise those list item pointers will be invalid and point to garbage - presumably the 'strange characters' you are referring to.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  7. #7
    Registered User
    Join Date
    Nov 2004
    Location
    Slovenia, Europe
    Posts
    115
    Thanks - i used array of strings (string not char*) and I made it work!
    [C++]
    IDE: DevC++ 4.9.9.2 (GCC 3.4.2)
    2nd compiler: g++ (GCC 3.4.3/4.0.0)
    3rd compiler: Borland 5.5
    [C#]
    IDE: Microsoft Visual C# Express 2005
    2nd IDE: SharpDevelop
    2nd compiler: csc in Command Prompt
    .NET Framework: 2.0
    [PHP]
    Core: 5.1.0 beta 3
    IDE: PHPEdit
    2nd IDE: Notepad
    Favourite extensions: exif,gd2,mysql
    Favourite PEAR packages: DB, XML_RSS, ID3
    Favourite databases: SQLite, MySQL

Popular pages Recent additions subscribe to a feed