killing me comboboxs

This is a discussion on killing me comboboxs within the Windows Programming forums, part of the Platform Specific Boards category; Ok, first I apologize for not being able to follow the multiple hits on the searches found on this site ...

  1. #1
    Registered User
    Join Date
    May 2004
    Posts
    164

    killing me comboboxs

    Ok, first I apologize for not being able to follow the multiple hits on the searches found on this site and the msdn example I found.

    I am having an issue trying to assign data to a combobox. I want to assign the data dynamically, not assign it before I compile it, specifically I want to assign via a text file. I figure if I can learn from this example from msdn:

    Code:
    	// The pointer to my combo box.
    	CComboBox* pIDC_COMBO1;
    
    	// Add 20 items to the combo box.
    	CString str;
    
    	for (int i=0;i < 20;i++)
    	{
    	   str.Format(_T("item string%d"), i);
    	   pIDC_COMBO1->AddString( str );
    	}
    I added my combobox name as the pointer and though it compiles fine it does not add anything? I am confused. Can anyone help explain this example?

  2. #2
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,856
    Nothing is added because the pointer to the combo box has not been set to 'point' at an ACTUAL combo box.

    (The MSDN example uses a pointer defined as external ie global)


    Try adding a member var to the dialogs class with the class wizard.

    Or send in the HWND of the dialog (or combo) to the function. Then use something like


    Code:
    //get the combos HWND using parent dlgs hwnd and its ID#
    HWND hCombo = GetDlgItem(hDialog,  IDC_YOUR_COMBO );
    //add the string
    SendMessage(hCombo, CB_ADDSTRING, (WPARAM) 0 , (LPARAM) sString);
    Last edited by novacain; 06-09-2005 at 11:44 PM.
    "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

  3. #3
    Registered User
    Join Date
    May 2004
    Posts
    164
    Thanks novacain, your right on the money. That fixed it. I apologize for the late response, but I really appreciate the help. thanks-

  4. #4
    Registered User
    Join Date
    May 2004
    Posts
    164
    Well, I thought I had it, I am successfully pointing to the variable, but now I get a memory violation error when it tries to assert the value to the variable I have assigned to the combobox.
    Code:
    // The pointer to variable assigned to my combo box.
    	CComboBox* pComboString;
    
    	// Add 20 items to the combo box.
    	CString str;
    
    	for (int i=0;i < 20;i++)
    	{
    	   str.Format(_T("item string%d"), i);
    	   pComboString->AddString( str );
    	} 
    
    	pComboString->AddString( str );

  5. #5
    uh oh
    Join Date
    Jan 2005
    Location
    Ontario, CA
    Posts
    66
    I would suggest trying novacain's suggestion and instead using your method. However, I still don't see any code that actually points to the combobox.

    CComboBox* pComboString; // still no value set

    This could be your problem. I don't program C++, but to me that seems to be your problem. I would still go with the SendMessage method, however.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Bush vs. Kerry
    By jlou in forum A Brief History of Cprogramming.com
    Replies: 178
    Last Post: 11-29-2004, 02:45 PM
  2. Killing someones grandparents
    By nickname_changed in forum A Brief History of Cprogramming.com
    Replies: 37
    Last Post: 09-07-2003, 07:56 AM
  3. Killing a process.
    By Brian in forum Windows Programming
    Replies: 7
    Last Post: 01-19-2003, 01:36 PM
  4. Functions are killing me
    By mike in forum C++ Programming
    Replies: 2
    Last Post: 03-06-2002, 01:35 PM
  5. My instructor is KILLING me
    By TheSki in forum C++ Programming
    Replies: 5
    Last Post: 11-10-2001, 04:30 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21