Horizontal scroll bar in CListCtrl

Can someone tell me how to make a horizontal scrollbar in a CListCtrl, it should work like the vertical, ie. the horizontal scrollbar should only be shown if some line is too long to be shown entirely.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Vinayak KumbarSr Program ManagerCommented:

In Ur resourse for that ListCtrl uncheck the NoScroll option. It must work, If not try using the following functions whenever U want to display the Scrollbar

m_ctrlHexList.ShowScrollBar(SB_HORZ ,TRUE);

Here I have used some hardcoded values.

Hope it helps
Brian_HPAuthor Commented:
This solves the problem if the width of the longest string in the list box is 500 pixels (or at least known), but in my situation the widths changes from time to time, therefore I cannot just set it to 500 (or something else fixed).

Are there a way to find the longest pixel width of the string items (or just finding the width of a single string item in the list box?
Brian_HPAuthor Commented:
Adjusted points to 100
The following should solve the problem. If you use tabs in the string, you
should probably use GetTabbedTextExtent instead.

CPaintDC* dc = new CPaintDC(this); // device context for painting
CRect r;
int max_width = 0;
for (i = 0; i < window->GetCount(); i ++) {
 CString s;
 window->GetText(i, s);
 CSize w = dc->GetTextExtent(s);
 if (max_width < w.cx)
  max_width = w.cx;
if (r.Width() < max_width) {
 window->ShowScrollBar(SB_HORZ, TRUE);
delete dc;


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Brian_HPAuthor Commented:
The following fould at code guru is perhaps a better solution ...

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.