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.
Brian_HPAsked:
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:
Hi,

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);
m_ctrlHexList.EnableScrollBar(SB_HORZ,ESB_ENABLE_BOTH);
m_ctrlHexList.SetScrollRange(SB_HORZ,0,50,TRUE);
m_ctrlHexList.SetHorizontalExtent(500);

Here I have used some hardcoded values.

Hope it helps
0
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?
0
Brian_HPAuthor Commented:
Adjusted points to 100
0
ClausCommented:
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;
}
window->GetClientRect(&r);
if (r.Width() < max_width) {
 window->ShowScrollBar(SB_HORZ, TRUE);
 window->EnableScrollBar(SB_HORZ,ESB_ENABLE_BOTH);
 window->SetScrollRange(SB_HORZ,0,max_width-1,TRUE);
 window->SetHorizontalExtent(max_width);
}
delete dc;

0

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 ...

http://www.codeguru.com/controls/listbox_extent.shtml
0
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.