Solved

How To Find Out If A Scrollbar Is Visible

Posted on 2004-03-24
4
1,138 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Thank you both for your help.
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
ORA-01403: no data found 43 82
post4 challenge 28 81
canBalance challenge 34 64
unix example issues 18 43
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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 video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

728 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now