I have one enquiry. I am a novice in mfc. Using one listbox. In that sometimes I have less data, some times lot of data. Depending on that the scrollbar comes automatically. So my enquiry is that is there any way to know the presence of scrollbar in the listbox? If so how to do that ? Any suggession will be highly helpful.
Why do you need it?
I don't know any "direct" way to found out the "presence" (the visibility) of scrollbar if LBS_DISABLENOSCROLL was not set (if LBS_DISABLENOSCROLL is set then scrollbar is always visible - either enabled or disabled).
However, you could try to compare the height of the listbox client rect (CWnd::GetClientRect) with the item height (CListBox::GetItemHeight) multiplied by item count (CListBox::GetCount)
Last edited by VictorN; May 7th, 2007 at 05:18 AM.
I needed it for a scrollbar problem in a listbox drawn code. While there were less items, the items were flickering because of the scroll roller event. So in absence of scrollbar I disabled scroll event. I used the 2nd method you described. It works perfectly ok. Thanks a lot
memset(&sbi, 0, sizeof(SCROLLBARINFO));
sbi.cbSize = sizeof(SCROLLBARINFO);
// Use "OBJID_HSCROLL" above for the horizontal scroll bar.
if ( sbi.rgstate & STATE_SYSTEM_INVISIBLE )
// here you know that the vertical scroll bar is not shown.
// (i.e. all data fits on screen)
// here, the scroll bar is shown.
I put this in my "::OnSize()" routine. I use this to adjust the widths of my columns to fill the width of the CListCtrl. Good luck!