Re: CScrollView: How to Tell If Scroll Bar Visbile



See below...
On Sun, 15 Feb 2009 15:22:37 -0800 (PST), PeterOut <MajorSetback@xxxxxxxxxx> wrote:

On Feb 12, 1:52 am, Joseph M. Newcomer <newco...@xxxxxxxxxxxx> wrote:
But I don't see why you need to know if the scroll bars are visible. If you are going to
adjust the frame area to be big enough to display the whole image, they *will* be
invisible.

Look at AdjustWindowRect. Take your image (the desired client area). Call
AdjustWindowRect on it. Make your window that large. Adjust the parent frame
(ResizeParentToFit) to hold this window.

This works fine until the window gets larger than the screen. Then your life becomes
miserable.

Note that showing the fMask as 23 is useless. The fMask is 0x17, which allows you to
determine which bits are set, and you can look in WinUser.h to find out what each of these
bits mean. They decode to SIF_ALL. Note that SIF_DISABLENOSCROLL is not set. This means
that the scrollbar will disappear if the necessary criteria for its appearance are not
met. But one of the criteria is a 0 scroll range, and you have a 0.999 range, so the
scrollbar should be visible. The documentation is actually unclear about what the
criteria are for scrollbar visibility.

So,
if( (ScrollInfo.fMask & SIF_DISABLENOSCROLL) == 0 &&
ScrollInfo.nMin == ScrollInfo.nMax)
{ /* scrollbar invisible */
...
} /* scrollbar invisible */

Note it is your responsibility to set the scroll range, so once you have resized the
window, if the scroll range is <= the window height, you want to explicitly set the scroll
range to 0 (such as specifying nMin = 0, nMax = 0).

It may also be the case that the scrollbar becomes invisible if abs(nMax - nMin) <=
clientRect.Height(), but this is not at all clear from the documentation of SetScrollInfo.
joe



On Wed, 11 Feb 2009 21:21:18 -0800 (PST), PeterOut <MajorSetb...@xxxxxxxxxx> wrote:
I am using MS Visual C++ 6.0 on Windows XP 5.1 SP 3.

I am using AppStudio to develop a program that displays images. The
view class is of typeCScrollView. I would like the program to be able
to tell whether the vertical and/or horizontal scroll bars are visible
so that I can adjust the frame area so as to be just large enough
(vertically and horizontally) to display the whole image. In order to
do this, I would like the program to be able to tell whether or not
the image window's scroll bar(s) are visibile. In order to do this, I
used
GetScrollInfo(SB_VERT, &ScrollInfo);
for the vertical window. It returns the following when no scroll bars
are visible.
- ScrollInfo {...}
cbSize 28
fMask 23
nMin 0
nMax 999
nPage 605
nPos 0
nTrackPos 0

Is there any way to tell from this that the scroll bar is not visible?

Many thanks in advance for any help,
Peter.

Joseph M. Newcomer [MVP]
email: newco...@xxxxxxxxxxxx
Web:http://www.flounder.com
MVP Tips:http://www.flounder.com/mvp_tips.htm

Thanks you very much for your reply. Here is the code I use for my
function.

void CMyProgramView::CalcWindowRect(LPRECT lpClientRect, UINT
nAdjustType)
{
if (!pDoc) pDoc = GetDocument();
CFrameWnd *pFrame = GetParentFrame();
CSize ParentSize;
int iMaxWidth=iColumns*iZoomFactor;
int iMaxHeight=iRows*iZoomFactor;
****
Put whitespace around all operators to make the code readable!

You haven't given any insight as to what iColumns, iRows, or iZoomFactor mean in this
algorithm...so I'm just guessing
***

if (fZoomFactor>1)
****
Do I see you comparing a floating point number to an integer? Why? And what will you do
if it turns out to be 99999999999999989 or 1.0000000000000002?
****
{
iMaxWidth-=iXCurrentScroll;
iMaxHeight-=iYCurrentScroll;
}
else
{
iXCurrentScroll=iYCurrentScroll=0;
}

if (lpClientRect->right>=iMaxWidth || lpClientRect->right==0)
lpClientRect->right=iMaxWidth-1;
if (lpClientRect->bottom>iMaxHeight || lpClientRect->bottom==0)
lpClientRect->bottom=iMaxHeight-1;

// Adjust frame size to be that of client area
if( pFrame != NULL )
{
ParentSize.cx=lpClientRect->right;
ParentSize.cy=lpClientRect->bottom;

// Change frame size
AdjustWindowRect(lpClientRect, WS_HSCROLL | WS_VSCROLL , FALSE);
pFrame->SetWindowPos( NULL, lpClientRect->left, lpClientRect-
top, lpClientRect->right, lpClientRect->bottom,
SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER );
ResizeParentToFit(FALSE);
SetScrolling(ParentSize.cx, ParentSize.cy);
}
}

When I call ResizeParentToFit(FALSE), I get the following assertion
error
ASSERT(m_nMapMode != MM_NONE); // mapping mode must be known

****
So after all this, we FINALLY get the description of the problem!!!!

Did you see the warning:

ResizeParentToFit assumes that the size of the view window has been set. If the view
window size has not been set when ResizeParentToFit is called, you will get an assertion.
To ensure that this does not happen, make the following call before calling
ResizeParentToFit:

Copy Code
GetParentFrame()->RecalcLayout();

Did you see the See Also reference to SetScrollSizes, which takes a mapping mode as its
parameter?
joe
****

Thanks,
Peter.
Joseph M. Newcomer [MVP]
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
.



Relevant Pages

  • Re: CScrollView: How to Tell If Scroll Bar Visbile
    ... adjust the frame area to be big enough to display the whole image, ... Adjust the parent frame ... Note it is your responsibility to set the scroll range, so once you have resized the ...
    (microsoft.public.vc.mfc)
  • RE: Excel 2000 VBA form questions
    ... Open 1 will work but it will make the form window smaller for all users ... But I do not get the 'slider' on smaller monitors. ... You can adjust the Zoom Property of the Userform in the Properties ... You can set the Scroll Bars Property of the Userform in the Properties ...
    (microsoft.public.excel.programming)
  • Re: Scrollable canvas with images - same result!
    ... unknown option "-padx" while executing "frame $w.scrolled ... Running it on Linux with KDE, the window just got garbled and couldn't ... So I guess my question remains the same - How to I scroll a large list ... ulis wrote: ...
    (comp.lang.tcl)
  • Re: Allow wheel mouse scrolling in Word
    ... > board, it is one "active" window whereas with the split windows, you have two ... > to scroll. ... >> other frame and scroll without clicking. ... >>>If you don't click in the pane, ...
    (microsoft.public.word.docmanagement)
  • Re: CScrollView: How to Tell If Scroll Bar Visbile
    ... But I don't see why you need to know if the scroll bars are visible. ... Make your window that large. ... Adjust the parent frame ...
    (microsoft.public.vc.mfc)