Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How To Find Out If A Scrollbar Is Visible

Posted on 2004-03-24
4
Medium Priority
?
1,154 Views
Last Modified: 2013-11-20
I have a CListCtrl, and I need to find out if it's vertical scrollbar is visible and what the scrollbar's width is so that I can resize the columns and remove the need to scroll horizontally.  I've tried the GetScrollBarCtrl(SB_VERT);, but I always get NULL.  I'm sure it's something stupid, but I haven't found the right function(s) for this.  Thanks in advance.
0
Comment
Question by:mnashadka
  • 2
4 Comments
 
LVL 2

Assisted Solution

by:abesoft
abesoft earned 200 total points
ID: 10672231
I've used something like this before:
    SCROLLINFO info = {sizeof( SCROLLINFO)};
    info.fMask = SIF_RANGE;
    if (m_StatementsList.GetScrollInfo( SB_HORZ, &info, SIF_RANGE) &&
        ((info.nMax - info.nMin) > windowRect.Height()))
        OutputDebugString( "No horizontal scroll bar detected\r\n");
    else
    {
        OutputDebugString( "Horizontal scroll bar detected\r\n");
        width += GetSystemMetrics( SM_CXHSCROLL);
    }

Obviously, you would want to wrap this up into a function....
0
 
LVL 2

Expert Comment

by:abesoft
ID: 10672251
Oh, that chunk of code should be preceded by:
      CRect windowRect;
      m_StatementsList.GetWindowRect( &windowRect);
And this code assumes you are testing for a scrollbar in a control called m_StatementsList.
0
 
LVL 48

Accepted Solution

by:
AlexFM earned 300 total points
ID: 10674933
I always use the following code to resize list control columns so that they don't depend on vertical scrollbar. Suppose I need 3 columns with equal size:

    CRect rect;
    m_list_ctrl.GetClientRect(&rect);
    int nWidth = rect.Width() - GetSystemMetrics(SM_CXVSCROLL) - 5;   // vertical scrollbar width correction
    int nWidth1 = nWidth / 3;
    int nWidth2 = nWidth / 3;
    int nWidth3 = nWidth - nWidth1 - nWidth2;

    // insert columns with width nWidth1, nWidth2 and nWidth3

0
 
LVL 8

Author Comment

by:mnashadka
ID: 10678089
Thank you both for your help.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

926 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question