Display Array in listbox

Discussion in 'C++' started by AdventGamer, Oct 4, 2010.

  1. AdventGamer

    AdventGamer New Member

    Oct 4, 2010
    Likes Received:
    Trophy Points:
    ok well i'm having issues sending a char array to a listbox. To do a little explanation on the code itself... The point of this part is to take a hexidecimal string and convert it to a alphabetical string (this part works and has been tested in a console application). I then have a vShowText function that i used to add items into my listbox. It has worked thus far and i have even added char arrays to the listbox using it. In this particular case i can't seem to make the char array show up into the listbox, it just inserts a line of D like characters. This is sorta difficult to explain so i hope i'm doing a good enough job of it. I will post code to help explain more below.

    here is my vShowText function that is being used to insert text into the listbox.
     void vShowText(HWND        hChildHandle, char *szText)
            int Line;
            // add string to the listbox
            // determine number of items in listbox
            Line = SendMessage(hChildHandle,LB_GETCOUNT,0,0);
            // flag last item as the selected item, to scroll listbox down
            // unflag all items to eliminate negative highlite
    below is where my problem is. This is the actual code to change the hex string into a alphabetical one. When the loop is done going through the hex string, ptrBuffer is reset to point to the first element in the char buffer[100] array. Then vShowText is called to display the contents of the buffer array into the listbox. I have also tried to just do vShowText(hlistbox, buffer). Both of these methods does the same thing and inserts a line of D like characters into the listbox... so it looks something like this DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD. Only they aren't actual D's.

    also i am able to just make a char array and then later call vShowText with the array as a parameter and it displays in the listbox fine. Example is below.
    //create a char array
    char myArray[100] = "Hello World!";
    //later in the program
    vShowText(hlistbox, myArray);
    the actual code snipplet:
     case MENU_FILE_TRANS:
            char *ptrBuffer = &buffer[0];
            for (int i = 0; i < RecvBytes; i+=2)
                    int firstvalue = RecvData[i] - '0';
                    int secondvalue;
                    //if RecvData[i+1] is a letter convert it to integer, otherwise use it.
                            case 'A':
                                    secondvalue = 10;
                            case 'B':
                                    secondvalue = 11;
                            case 'C':
                                    secondvalue = 12;
                            case 'D':
                                    secondvalue = 13;
                            case 'E':
                                    secondvalue = 14;
                            case 'F':
                                    secondvalue = 15;
                                    secondvalue = RecvData[i+1] - '0';
                    //convert the two values into decimal form
                    newval =  16 * firstvalue + secondvalue;
                    //change newval into a character
                    *ptrBuffer = char(newval);
                    //vShowText(hlistbox, ptrBuffer);
            ptrBuffer = &buffer[0];
            vShowText(hlistbox, ptrBuffer);

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice