-
July 30th, 2010, 08:53 PM
#1
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
-
July 30th, 2010, 09:07 PM
#2
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.
-
July 30th, 2010, 09:10 PM
#3
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);
}
}
???
-
July 31st, 2010, 01:24 PM
#4
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.
-
July 31st, 2010, 01:33 PM
#5
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|