Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to detect scrollbar visibility?

Status
Not open for further replies.

Hexonx

Programmer
Jan 10, 2001
102
US
Does anyone know how to tell if the scrollbars of a given window are currently visible? I've tried GetScrollInfo, but the SCROLLINFO struct doesn't include visibility. I figure that I could get info about the scrollbar windows themselves, but don't know how to obtain that from the given window either.
 
The scroll bars are a property of the window style. I'm not sure if there is an api to tell if they are visible or not. Here is a solution (although may not be the most elegant).

Get the window rectangle for both the frame and client windows. You know that the difference in width will be larger for windows that have a vertical scroll bar. So you could implement code like the following:

bool bIsVertScroll = false;
if( (rectFrame.Width() - rectClient.Width()) > 10 )
bIsVerScroll = true;

The number 10 would have to be imperically derived but should serve as a reasonable starting point.

Hope this helps.
 

wndStyle = GetWindowLong(myhwnd, GWL_STYLE)

if (wndStyle & WS_HSCROLL)
//horizontal scroll bar is visible

if (wndStyle & WS_VSCROLL)
//Vertical scroll bar is visible

 
Thanks for the replies. They solved my problem.

Checking the style with GetWindowLong looks like the way to go. I'm actually doing this in a .NET Windows application. The Control class raises a StyleChanged event whenever the style of the control changes. I made the call here for efficiency.

Thanks again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top