Thread: CComboBoxEx Error, Visual C++

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

    CComboBoxEx Error, Visual C++

    Hi I am trying to create a combo box but am getting an error when passing the parameters to the CComboBoxEx::Create() function, wondering if anyone could help, here is code:
    Code:
    typedef struct tagRECT {
                               LONG left;
                               LONG top;
                               LONG right;
                               LONG bottom;
    	} RECT;
    
    	RECT pos;
    
    	pos.left = 0;
    	pos.top = 0;
    	pos.right = 20;
    	pos.bottom = 20;
    		
    	CComboBoxEx getFile;
    
    	CComboBoxEx();
    	
    	getFile.Create(CBS_DROPDOWNLIST, pos, IDD_BENSVISTTEST_DIALOG, 1);
    Here is error message:
    error C2664: 'Create' : cannot convert parameter 2 from 'struct CBensVistTestDlg::OnEditchangeCombo1::tagRECT' to 'const struct tagRECT &'

    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
    It looks like your are redefining the RECT struct. Why?
    It is defined like this:
    Code:
    typedef struct _RECT { 
      LONG left; 
      LONG top; 
      LONG right; 
      LONG bottom; 
    } RECT, *PRECT;
    So you can see you need a type cast then.
    Next your using MFC so you should use CRect instead.
    Finally if you don't OR CBS_DROPDOWNLIST with WS_VISIBLE you will have to call ShowWindow().
    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
    Thanks mate I get you now, hopefully this next bit of code won't offend you, I have altered it as suggested nd I understand that now, this is my first time using VC++. It is having an error with my CWnd * pParent pointer, I don't know what the pointer is to the parent window and Create says it must not be Null, here is code:
    Code:
    void CBensVistTestDlg::OnEditchangeCombo1() 
    {
    	CComboBoxEx getFile;
    
    	CComboBoxEx();
    
    	CRect pos(0,0,20,20);
    	
    	getFile.Create(CBS_DROPDOWNLIST||WS_VISIBLE , pos, CBensVistTestDlg, 1);
    
    	// TODO: Add your control notification handler code here
    	
    }
    could you tell me if possible where I can find this efing pointer?

    Here is error message:
    error C2275: 'CBensVistTestDlg' : illegal use of this type as an expression

    Thanks.

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

  4. #4
    ResurgentBarbecue UnclePunker's Avatar
    Join Date
    May 2002
    Posts
    128
    Someone could just tell me if I am asking a stupid question?
    Compiler == Visual C++ 6.0
    "Come Out Fighting."

  5. #5
    Master of the Universe! velius's Avatar
    Join Date
    Sep 2003
    Posts
    219
    I got your message and answered you there. I happed to be working when you posted these questions. I'm in the USA in the Eastern Time Zone.
    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

  6. #6
    Programming is fun, mkay?
    Join Date
    Oct 2001
    Posts
    490

    Post Possible Solution? ...

    I think this is possibly the solution. Since the function 'OnEditchangeCombo1' is defined in the dialog window's class, you should just do this:

    Code:
    getFile.Create(CBS_DROPDOWNLIST | WS_VISIBLE , &pos, this, 1);
    When 'OR'ing something in functions such as 'Create()' you should only use one '|' symbol. Also, I think you have to pass a reference to the rectangle, since the function asks for a pointer to a 'RECT' object, and 'CRect' objects are basically 'RECT' objects. Or you could just do this:

    Code:
    CRect *pos = new CRect(0, 0, 20, 20);   // New 'CRect' pointer
    And change the '&pos' to just 'pos'. I believe this is the answer. If not, at least I put in some effort and ATTEMPTED to help.

  7. #7
    Master of the Universe! velius's Avatar
    Join Date
    Sep 2003
    Posts
    219
    SyntaxBubble the function Create does not take a pointer to a RECT or CRect it takes a reference. So if you create a new CRect on the heap then you must dereference it in the call to Create().
    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

  8. #8
    Programming is fun, mkay?
    Join Date
    Oct 2001
    Posts
    490

    Oops ... :)

    Oops. Sorry for the incorrect information. I haven't used the Create() function A LOT, just a little bit.

  9. #9
    Master of the Universe! velius's Avatar
    Join Date
    Sep 2003
    Posts
    219
    Don't worry about it. People make mistakes. Animals make mistakes. Hell even my people make mistakes.
    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