ScrollBar Presence in ListBox ?
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: ScrollBar Presence in ListBox ?

  1. #1
    Join Date
    May 2007
    Posts
    2

    Question 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

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,517

    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 06:18 AM.

  3. #3
    Join Date
    May 2007
    Posts
    2

    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

  4. #4
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,517

    Re: ScrollBar Presence in ListBox ?

    Glad to know your problem is solved!

    And you are welcome!

  5. #5
    Join Date
    Nov 2005
    Location
    NC, USA
    Posts
    96

    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
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center