Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CListBox 1

Status
Not open for further replies.

shetlandbob

Programmer
Mar 9, 2004
528
GB
Hi,

I have a listbox in a dialog control which I dynamically add items to. Initially the vertical scrollbar is not enabled, but once the list exceeds the size of the box then the scrollbar appears.

How can I detect when this occurs in the code and resize the width of the listbox to add in the size of the scroll bar?? (i was planning on using .movewindow to resize the window).

Note: my dialog can be resized so simply counting the number of items and working it out that way is a bit tedious, and well a bit primitive!!

Any ideas much appreaciated.
 
Hmmm...how about you just give it that extra width from the start?

Or is that perhaps a too simple solution?

/Per
[sub]
"It was a work of art, flawless, sublime. A triumph equaled only by its monumental failure."[/sub]
 
well yes that is a simple answer (and I had thought about it), but I was hoping to dynamically alter the box. I want to use as much of the dialog as possible for the main tasks (which is displaying graphs for info) and only on the few occasions that the list box is full have it expand to include the scroll bar
 
Haven't tested it myself but I would assume that when
Code:
theBox.GetCount() * theBox.GetItemHeight(0) > height
is true the vertical scrollbar is shown, where height is computed as
Code:
  CRect cr;
  theBox.GetClientRect(cr);
  height = cr.bottom;

/Per
[sub]
"It was a work of art, flawless, sublime. A triumph equaled only by its monumental failure."[/sub]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top