HScroll in list box

hey guys,
i have CListBox on a dialog, i want it to has HScroll bar so i can see the rest of the string in the box...

what should i do ???

Shay
LVL 3
Shay050799Asked:
Who is Participating?
 
SadhuConnect With a Mentor Commented:
use SetHorizontalExtent( int cxExtent )

to set extent



0
 
SadhuCommented:
you could write function similar to following to calcualte extent for string.
LONG YourClass::GetExtentForString(LPCTSTR lpszItem)
{
    CDC* cdc=this->GetDC();
    CFont* font = this->GetFont();
    CFont* pOldFont;

    if (font)
     {
        pOldFont = cdc->SelectObject(font);

          TEXTMETRIC tm;
          cdc->GetTextMetrics(&tm);

          CSize size = cdc->GetTextExtent(lpszItem, lstrlen(lpszItem) );
          size.cx += tm.tmAveCharWidth;

          cdc->SelectObject(pOldFont);
          this->ReleaseDC(cdc);

          return (LONG) size.cx;
     }

     this->ReleaseDC(cdc);

     return 0L;
}

0
 
SadhuCommented:
Also do not forget to check box for auto horizontal scroll bar in your list box properties.

0
 
Shay050799Author Commented:
Sadhu  answer was excelent,thanks a lot
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.