Thread: Visual C++ Problem, CComboBox

  1. #1
    ResurgentBarbecue UnclePunker's Avatar
    Join Date
    May 2002
    Posts
    128

    Visual C++ Problem, CComboBox

    I am having a problem getting my combo box to drop down in Visual C++ here is the code.

    Code:
    void CBensVisTestDlg::OnDropdownCombo1() 
    {
    	CRect pos;
    
    	pos.top = 0;
    	pos.left = 0;
    	pos.right = 100;
    	pos.bottom = 250;
    
    	CComboBox getFile;
    
    	CComboBox();
    
    	getFile.Create(CBS_DROPDOWNLIST | WS_VISIBLE | WS_CHILD, pos, this, IDC_COMBO1);
    
        getFile.Dir(DDL_DRIVES, "C:*.*");
    
    	// TODO: Add your control notification handler code here
    	
    }
    The program compiles with no errors or warnings and doesn't have any runtime errors once running, but when I click on the appropriate combo box basically nothing happens, could someone please tell me what I am doing wrong.

    Thanks in advance.

    Ben.
    Compiler == Visual C++ 6.0
    "Come Out Fighting."

  2. #2
    Master of the Universe! velius's Avatar
    Join Date
    Sep 2003
    Posts
    219
    You are creating a new CComboBox object in the handler for the object the event is happening for. You need to then call this->Dir(DDL_DRIVES, "C:*.*") otherwise your calling that for a newly created CComboBox object.

    You need to do this:
    Code:
    CComboBox* pCB = (CComboBox*)GetDlgItem(IDC_COMBO1);
    pCB->Dir(DDL_DRIVES, "C:*.*");
    
    // or
    
    this->Dir(DDL_DRIVES, "C:*.*");
    While you're breakin' down my back n'
    I been rackin' out my brain
    It don't matter how we make it
    'Cause it always ends the same
    You can push it for more mileage
    But your flaps r' wearin' thin
    And I could sleep on it 'til mornin'
    But this nightmare never ends
    Don't forget to call my lawyers
    With ridiculous demands
    An you can take the pity so far
    But it's more than I can stand
    'Cause this couchtrip's gettin' older
    Tell me how long has it been
    'Cause 5 years is forever
    An you haven't grown up yet
    -- You Could Be Mine - Guns N' Roses

  3. #3
    ResurgentBarbecue UnclePunker's Avatar
    Join Date
    May 2002
    Posts
    128
    I am pretty sure I understand you, and I have revised my code to look like this:
    Code:
    void CBensVisTestDlg::OnDropdownCombo1() 
    {
    	CRect pos;
    
    	pos.top = 0;
    	pos.left = 0;
    	pos.right = 100;
    	pos.bottom = 250;
    
    	CComboBox* getFile = new CComboBox;
    
        getFile->Dir(DDL_DRIVES, "C:\\*.*");
    
    	CComboBox();
    
    	getFile->Create(CBS_DROPDOWNLIST | WS_VISIBLE | WS_CHILD, pos, this, IDC_COMBO1);
    	
    }
    I get an assertion error while trying to drop doen the combo box, I realise I haven't copied your code directly but when I did copy your code directly I again got an assertion error, can anyone explain how this combo box is supposed to work? This is doing my head in.

    Thanks in advance.

    Ben.
    Compiler == Visual C++ 6.0
    "Come Out Fighting."

  4. #4
    Master of the Universe! velius's Avatar
    Join Date
    Sep 2003
    Posts
    219
    You're creating a new CComboBox object. You don't want to do that. You need to use the already in use one. Remember the event is triggered because you already have a CComboBox in existence. Just use this:
    Code:
    CComboBox* pCB = (CComboBox*)GetDlgItem(IDC_COMBO1);
    pCB->Dir(DDL_DRIVES, "C:\\*.*");
    That code will do what you want to do, because you have a combo box named IDC_COMBO1. The GetDlgItem() will get a CWnd pointer to the child window with the id passed to it. Then you type cast it back to the object type you need. In this case CComboBox*.
    While you're breakin' down my back n'
    I been rackin' out my brain
    It don't matter how we make it
    'Cause it always ends the same
    You can push it for more mileage
    But your flaps r' wearin' thin
    And I could sleep on it 'til mornin'
    But this nightmare never ends
    Don't forget to call my lawyers
    With ridiculous demands
    An you can take the pity so far
    But it's more than I can stand
    'Cause this couchtrip's gettin' older
    Tell me how long has it been
    'Cause 5 years is forever
    An you haven't grown up yet
    -- You Could Be Mine - Guns N' Roses

  5. #5
    ResurgentBarbecue UnclePunker's Avatar
    Join Date
    May 2002
    Posts
    128
    Sorry man, I get you now, you must have been getting well frustrated, right I was writing the code inside the handler for a combo box that was already created and then i was calling a constructor and create function for another combo box, it was bound to get ........ed off, when you showed me those lines of code I dint realise you dint mean just edit them it was JUST those lines of code I needed, right, you have really got me back on track now, again thanks a lot.

    No doubt I'll be back again, sorry about that.

    Ben.
    Compiler == Visual C++ 6.0
    "Come Out Fighting."

  6. #6
    Master of the Universe! velius's Avatar
    Join Date
    Sep 2003
    Posts
    219
    No problem. You know I'll help you again next time too.
    While you're breakin' down my back n'
    I been rackin' out my brain
    It don't matter how we make it
    'Cause it always ends the same
    You can push it for more mileage
    But your flaps r' wearin' thin
    And I could sleep on it 'til mornin'
    But this nightmare never ends
    Don't forget to call my lawyers
    With ridiculous demands
    An you can take the pity so far
    But it's more than I can stand
    'Cause this couchtrip's gettin' older
    Tell me how long has it been
    'Cause 5 years is forever
    An you haven't grown up yet
    -- You Could Be Mine - Guns N' Roses

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Visual studio.net C++ Problem
    By Dina in forum C Programming
    Replies: 5
    Last Post: 07-19-2008, 02:34 PM
  2. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM
  3. errors in my class....
    By o0obruceleeo0o in forum C++ Programming
    Replies: 9
    Last Post: 04-14-2003, 03:22 AM
  4. Visual Basic Adodc Problem
    By rahat in forum Windows Programming
    Replies: 1
    Last Post: 01-20-2002, 06:55 AM
  5. Microsoft Visual C++ compiler, cast problem?
    By jonnie75 in forum C Programming
    Replies: 5
    Last Post: 11-10-2001, 08:53 AM