Solved

How To Find Out If A Scrollbar Is Visible

Posted on 2004-03-24
4
1,145 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 50 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 75 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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

Suggested Solutions

Title # Comments Views Activity
Separate into files by filename 12 87
deburging in oracle form 12 105
building a service to accessed via telnet client, want colors ? 4 94
Annoying "thing" blocks my view 4 117
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: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

828 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