Alright. I have a dialog box. With a list. I want to get the text of one of the entries in the list. The list is IDC_LIST. The handle to IDC_LIST is hList. What function can get a string of a certain entry in that list?
This is a discussion on Dialog Boxes within the Windows Programming forums, part of the Platform Specific Boards category; Alright. I have a dialog box. With a list. I want to get the text of one of the entries ...
Alright. I have a dialog box. With a list. I want to get the text of one of the entries in the list. The list is IDC_LIST. The handle to IDC_LIST is hList. What function can get a string of a certain entry in that list?
No function, you need to send messages to the window.
This will get line 0 from the listbox:
Code:// Want item 0 (the first item): unsigned int listItem = 0; //First we find out how big it will be: unsigned int charCount = ::SendMessage(hList,LB_GETTEXTLEN, (WPARAM) listItem, (LPARAM) 0); // Then allocate enough space for the text plus terminating character: TCHAR * buffer = new TCHAR[charCount + 1]; // Now, try to get the text itself: if (::SendMessage(hList,LB_GETTEXT,(WPARAM)listItem, (LPARAM)buffer) == LB_ERR){ // an error occured. Handle it here. } else { // We know no error occured. Do stuff with buffer. } // We allocated string space, so we must free it once we don't need it anymore: delete[] buffer;
Last edited by Cat; 05-22-2003 at 10:10 PM.