-
May 7th, 2007, 04:42 AM
#1
ScrollBar Presence in ListBox ?
Hi
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.
Regardly
Sayed
-
May 7th, 2007, 05:15 AM
#2
Re: ScrollBar Presence in ListBox ?
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.
-
May 8th, 2007, 07:05 AM
#3
Re: ScrollBar Presence in ListBox ?
Hi VictorN,
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
Regardly
Sayed
-
May 8th, 2007, 07:17 AM
#4
Re: ScrollBar Presence in ListBox ?
Glad to know your problem is solved!
And you are welcome!
-
July 16th, 2009, 01:19 PM
#5
Re: ScrollBar Presence in ListBox ?
Sayed,
Here's some code that I use:
Code:
SCROLLBARINFO sbi;
memset(&sbi, 0, sizeof(SCROLLBARINFO));
sbi.cbSize = sizeof(SCROLLBARINFO);
m_cListCtrl.GetScrollBarInfo(OBJID_VSCROLL, &sbi);
// Use "OBJID_HSCROLL" above for the horizontal scroll bar.
if ( sbi.rgstate[0] & STATE_SYSTEM_INVISIBLE )
{
// here you know that the vertical scroll bar is not shown.
// (i.e. all data fits on screen)
}
else
{
// 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!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|