-
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
-
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.
-
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);
}
}
???
-
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 );
-
Re: CComboBoxEx
If this still doesn't work, zip up a small sample project and attach it here.