Answered by:
How to conditionally check whether a window's scroll bar is currently visible or not?

Question
-
I am working on an mfc application that draws two buttons on the screen relative to the dimensions of the CListBox that sits directly to the left of it. Their positions are determined by coordinates retrieved from the GetClientRect() function. However, when the CListBox contains enough data, a scroll bar will become visible, and GetClientRect() will not take the scroll bar's size into account. Therefore, my buttons end up being shifted over to the wrong place.
I am aware there is an rgstate in the SCROLLBARINFO that has information regarding the current state of the scrollbar. I haven't been successful thus far in checking this state to determine if the scroll bar is currently visible or not. My understanding of this is pretty shallow so it's likely an error on my part.
My conditional part of my code looks something like:
bool visible = true; int info = scrollbarinfo.rgstate[0]; if (info == ((STATE_SYSTEM_INVISIBLE || STATE_SYSTEM_UNAVAILABLE)) { visible = false; }
My understanding on how this works must be way off. Any guidance would be much appreciated!
Answers
-
Try (info & (STATE_SYSTEM_INVISIBLE | STATE_SYSTEM_OFFSCREEN) ) != 0
- Edited by RLWA32 Tuesday, June 18, 2019 3:13 PM
- Marked as answer by Jimmy Blundell Tuesday, June 18, 2019 7:16 PM
All replies
-
Try (info & (STATE_SYSTEM_INVISIBLE | STATE_SYSTEM_OFFSCREEN) ) != 0
- Edited by RLWA32 Tuesday, June 18, 2019 3:13 PM
- Marked as answer by Jimmy Blundell Tuesday, June 18, 2019 7:16 PM
-
-
-
-
-
I see, my bad. That being said, maybe it would better help me if I know what in particular is wrong with my original attempt? Unless my approach is wrong altogether, I assumed that checking that scrollbarinfo.rgstate[0] was STATE_SYSTEM_INVISIBLE or UNAVAILABLE or OFFSCREEN would be enough, but so far no combination of those works. Am I not understanding how this works correctly?
SCROLLBARINFO scrollbarinfo; bool visible = true; scrollbarinfo.cbSize = sizeof(scrollbarinfo); if (m_lstFT.GetScrollBarInfo(OBJID_VSCROLL, &scrollbarinfo)) { if (scrollbarinfo.rgstate[0] == (STATE_SYSTEM_INVISIBLE | STATE_SYSTEM_OFFSCREEN)) { visible = false; } }
I tried updating it like above, but am I still missing the point here?
-
I see, my bad. That being said, maybe it would better help me if I know what in particular is wrong with my original attempt? Unless my approach is wrong altogether, I assumed that checking that scrollbarinfo.rgstate[0] was STATE_SYSTEM_INVISIBLE or UNAVAILABLE or OFFSCREEN would be enough, but so far no combination of those works. Am I not understanding how this works correctly?
SCROLLBARINFO scrollbarinfo; bool visible = true; scrollbarinfo.cbSize = sizeof(scrollbarinfo); if (m_lstFT.GetScrollBarInfo(OBJID_VSCROLL, &scrollbarinfo)) { if (scrollbarinfo.rgstate[0] == (STATE_SYSTEM_INVISIBLE | STATE_SYSTEM_OFFSCREEN)) { visible = false; } }
I tried updating it like above, but am I still missing the point here?
- Edited by RLWA32 Tuesday, June 18, 2019 4:24 PM
-
-
That does work, thank you. Last question if you don't mind: why not just check if rgstate[0] != 0 instead of checking INVISIBLE and OFFSCREEN as well?
Because rgstate[0] != 0 would return true if any of the other bit flags unrelated to visibility were set. -