// The pointer to my combo box. extern CComboBox* pmyComboBox; // Find the longest string in the combo box. CString str; CSize sz; int dx = 0; TEXTMETRIC tm; CDC* pDC = pmyComboBox->GetDC(); CFont* pFont = pmyComboBox->GetFont(); // Select the listbox font, save the old font CFont* pOldFont = pDC->SelectObject(pFont); // Get the text metrics for avg char width pDC->GetTextMetrics(&tm); for (int i = 0; i < pmyComboBox->GetCount(); i++) { pmyComboBox->GetLBText(i, str); sz = pDC->GetTextExtent(str); // Add the avg width to prevent clipping sz.cx += tm.tmAveCharWidth; if (sz.cx > dx) dx = sz.cx; } // Select the old font back into the DC pDC->SelectObject(pOldFont); pmyComboBox->ReleaseDC(pDC); // Set the horizontal extent so every character of all strings can // be scrolled to. pmyComboBox->SetHorizontalExtent(dx);
来自MSDN
本版积分规则 发表回复 回帖并转播 回帖后跳转到最后一页
QQ咨询|关于我们|Archiver|手机版|小黑屋|( 辽ICP备15012455号-4 ) Powered by 期权论坛 X3.2 © 2001-2016 期权工具网&期权论坛 Inc.
下载期权论坛手机APP