Thread: Combobox problem

  1. #1
    Registered User
    Join Date
    Apr 2005
    Posts
    11

    Question Combobox problem

    I'm trying to make a combo box in a dialog window. I create a dialog in VC++ editor, empty combo box in it and then add data to it with SendMessage(hwndcombo, CB_ADDSTRING, o, "Data1") during WM_INITDIALOG. Like this:

    Code:
    LRESULT res;
    
    res = SendMessage (hwndcombo, CB_ADDSTRING, 0, (LPARAM) TEXT("Data1")) ;
    sprintf(buffer, "SendMessage: %ld\n", res);
    writelog(buffer);
    		
    res = SendMessage (hwndcombo, CB_ADDSTRING, 1, (LPARAM) TEXT("Data2")) ;
    sprintf(buffer, "SendMessage: %ld\n", res);
    writelog(buffer);
    
    res = SendMessage (hwndcombo, CB_ADDSTRING, 2, (LPARAM) TEXT("Data3")) ;
    sprintf(buffer, "SendMessage: %ld\n", res);
    writelog(buffer);
    			
    res = SendMessage (hwndcombo, CB_ADDSTRING, 3, (LPARAM) TEXT("Data4")) ;
    sprintf(buffer, "SendMessage: %ld\n", res);
    writelog(buffer);
    				
    res = SendMessage (hwndcombo, CB_ADDSTRING, 4, (LPARAM) TEXT("Data5")) ;
    sprintf(buffer, "SendMessage: %ld\n", res);
    writelog(buffer);
    
    res = SendMessage (hwndcombo, CB_ADDSTRING, 4, (LPARAM) TEXT("Data6")) ;
    sprintf(buffer, "SendMessage: %ld\n", res);
    writelog(buffer);
    
    res = SendMessage (hwndcombo, CB_ADDSTRING, 4, (LPARAM) TEXT("Data7")) ;
    sprintf(buffer, "SendMessage: %ld\n", res);
    writelog(buffer);
    
    sprintf(buffer, "NoItems: %ld\n", SendMessage (hwndcombo, CB_GETCOUNT, 0, 0));
    writelog(buffer);
    Of course, first I get a handle to it. But, return codes from SendMessage are strange. First three SenMessage calls return 0, then next two return 1, next two return 2, and so on. When I check number of strings in combo box with CB_GETCOUNT it returns 7 which is OK. But when I try to read any of entries with

    strlength = SendMesssage(hwndcombo, LB_GETTEXT, i, (LPARAM) buffer);

    strlength equals zero and nothing is written to buffer. Also, when I run the program, combo box is empty.
    Last edited by gargamel; 05-06-2005 at 12:39 PM.

  2. #2
    Registered User
    Join Date
    Jan 2005
    Posts
    847
    The message to get a string from a combo box is CB_GETLBTEXT. Make sure you create the combo box with the CBS_HASSTRINGS so it will display the strings.

  3. #3
    Registered User
    Join Date
    Apr 2005
    Posts
    11
    OK, thanks. It's working now.
    Last edited by gargamel; 05-06-2005 at 02:39 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 11:22 AM
  2. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 08:38 AM
  3. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  4. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM
  5. Laptop Problem
    By Boomba in forum Tech Board
    Replies: 1
    Last Post: 03-07-2006, 06:24 PM