- dc.GetTextExtent(i,str); // return the width of the text in the dc
- void CMyCombBox::RecalcDropWidth()
- {
- int nNumEntry = GetCount();
- int nWidth = 0;
- CString str;
- CClientDC dc(this);
- int nSave = dc.SaveDC();
- dc.SelectObject(GetFont());
- int nScrollWidth = GetSystemMetrics(SM_CXVSCROLL);
- for (int i = 0; i<nNumEntry;i++)
- {
- GetLBText(i,str);
- int nLength = dc.GetTextExtent(str).cx + nScrollWidth;
- nWidth = max(nWidth,nLength);
- }
- SetDroppedWidth(nWidth);
- }
VC控件学习:combox
最新推荐文章于 2016-06-28 19:23:10 发布