Solved

How To Find Out If A Scrollbar Is Visible

Posted on 2004-03-24
4
1,143 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
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 tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …

815 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

8 Experts available now in Live!

Get 1:1 Help Now