CComboBoxEx
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: CComboBoxEx

  1. #1
    Join Date
    Jun 2010
    Posts
    72

    CComboBoxEx

    Code:
    void CMirrorSize::InitComboHelper(CComboBoxEx& cb, const TCHAR* lpTxt, int nItem, int nImage)
    {
    	COMBOBOXEXITEM cbi={0};
    	cbi.mask=CBEIF_IMAGE | CBEIF_INDENT | CBEIF_TEXT;
    	cbi.iItem=nItem;
    	cbi.iImage=nImage;
    	cbi.iIndent=(0&0x05);
    	cbi.pszText=(LPWSTR)lpTxt;
    	ASSERT(0==cb.InsertItem(&cbi));
    }
    
    void CMirrorSize::OnInitCombo(CComboBoxEx& cb, int nComboSize, CImageList*pImgLst)
    {
    	if(pImgLst!=NULL)
    		cb.SetImageList(pImgLst);
    	for(int i=0; i<5; i++)
    	{
    		InitComboHelper(cb,lpTemp[i],i,i);
    	}	
    }
    lpTemp[i] contains const string i
    Why does the cb's size after I call OnInitCombo become zero ?

    Thank you

  2. #2
    Arjay's Avatar
    Arjay is online now Moderator / MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    11,281

    Re: CComboBoxEx

    I have no idea, but I can tell you this....

    The ASSERT macro should not be used the way you are using it because it will do nothing in a released build.

  3. #3
    Join Date
    Jun 2010
    Posts
    72

    Re: CComboBoxEx

    OK thanks
    Code:
    void CMirrorSize::InitComboHelper(CComboBoxEx& cb, const TCHAR* lpTxt, int nItem, int nImage)
    {
    	COMBOBOXEXITEM cbi={0};
    	cbi.mask=CBEIF_IMAGE | CBEIF_INDENT | CBEIF_TEXT;
    	cbi.iItem=nItem;
    	cbi.iImage=nImage;
    	cbi.iIndent=(0&0x05);
    	cbi.pszText=(LPWSTR)lpTxt;
    	cb.InsertItem(&cbi);
    }
    
    void CMirrorSize::OnInitCombo(CComboBoxEx& cb, int nComboSize, CImageList*pImgLst)
    {
    	if(pImgLst!=NULL)
    		cb.SetImageList(pImgLst);
    	for(int i=0; i<5; i++)
    	{
    		InitComboHelper(cb,lpTemp[i],i,i);
    	}	
    }
    ???

  4. #4
    Arjay's Avatar
    Arjay is online now Moderator / MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    11,281

    Re: CComboBoxEx

    What happens when you step through the code?

    What happens if you make the lpTemp array into a class member rather than a stack variable?

    A couple of further comments:

    Don't, Windows has predefined string types. Don't use const TCHAR* lpTxt; use LPCTSTR szTxt instead.

    You don't need to cast the string when assigning it:
    Code:
    cbi.pszText = ( LPWSTR ) lpTxt;
    If you have to cast it to get it to work, it's an indication that something is wrong. If you are casting to remove the const, then cast with LPTSTR, not LPWSTR.

    Now that I think about it, you need to copy the string into cbi.pszText rather than assign the pointer.

    _tcscpy_s( cbi.pszText, lpTxt );
    Last edited by Arjay; July 31st, 2010 at 01:31 PM.

  5. #5
    Arjay's Avatar
    Arjay is online now Moderator / MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    11,281

    Re: CComboBoxEx

    If this still doesn't work, zip up a small sample project and attach it here.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center