Link to home
Start Free TrialLog in
Avatar of henry3
henry3

asked on

GetTextExtent( ) returns inaccurate pixels

If you try the code, you'll find it.

extentName=pCDC->GetTextExtent(LongName,strlen(LongName));
if(strlen(LongName)>30){
  m_listCtrl.SetHorizontalExtent(extentName.cx);
      }
Note:30 is the characters listbox can hold.

The more long string is, the more obvious inaccuracy is.

Any idea?  
Avatar of cyberfrank
cyberfrank

Hi!

The main problem is, that fonts can be different in CDC (through the pCDC pointer) and in the listbox.
Try to synchronize fonts and the problem will be solved.
Or You can try:
CListBox::SetColumnWidth(int cxWidth );
Also, maybe you have problem with scrollbar himself. Try to set scroll range. Use the CListBox's
void SetScrollRange( int nBar, int nMinPos, int nMaxPos, BOOL bRedraw = TRUE );
function where the nBar is:
SB_HORZ  

CF
Hi!
Try sync DC ascyberfranc said and also try DrawText with DT_CALCRECT param
ASKER CERTIFIED SOLUTION
Avatar of SteveGTR
SteveGTR
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of henry3

ASKER

Thanks Everybody, and Happy New Year!