Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How To Find Out If A Scrollbar Is Visible

Posted on 2004-03-24
4
Medium Priority
?
1,151 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

Question has a verified solution.

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

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
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 course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Suggested Courses

715 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