• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 208
  • Last Modified:

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
0
Shay050799
Asked:
Shay050799
  • 3
1 Solution
 
SadhuCommented:
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

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now