Re: Long ex. but simple!
Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance
"Ross" <Ross@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:B2330C6D-9D4B-4DC4-BB03-DBBCB28B6554@xxxxxxxxxxxxx
Hello!
I am about to expose a long Windows example, however the question is
very simple and I might even add that the behaviour is odd. I could
sort of let it go and excuse the expression (the hell with it ! ) But
why!
When using code from a book (Petzold in this case), it helps if you tell us
the book.
[code snipped]
When I hit the UP and Down keys of my keyboard, the window pages up
and down without a problem. However, lets say I am at the top of the
page, and I hit the END key of my keyboard, shouldn't the window take
me down to the bottom of the document ?
-I mean, I press END right !
-So, windows sends a WM_KEYDOWN message with a VK_END virtual Key
code right !
-SendMessage, re-fetches WinProc, but this time sending the WM_VSCROLL
message and the SB_BOTTOM identifier for wParam, right !
As James Park has pointed out, you are missing a break statement in VK_END
processing, which causes case VK_PRIOR to also be processed.
-So, WM_VSCROLL gets executed and goes to SB_BOTTOM where si.nPos =
the maximum position stored in the SCROLLINFO srtucture which is
NUMLINE -1 which really is 74.
-Once thats done the following code fragment is executed:
si.fMask = SIF_POS;
SetScrollInfo(hwnd,SB_VERT,&si,TRUE);
GetScrollInfo(hwnd,SB_VERT,&si);
if(si.nPos != iVertPos)
{
ScrollWindow(hwnd,0,cyChar * (iVertPos - si.nPos),
NULL,NULL);
UpdateWindow(hwnd);
}
In WM_VSCROLL. why after the:
SetScrollInfo(hwnd,SB_VERT,&si,TRUE);
command, the value of si.nPos is no longer 74 (which would indicate
the bottom of document) after all didn't we set si.Pos to si.Max a
few lines before. Why wasn't this value kept in the SCROLLINFO
structure.
Adding the break statement will allow you to scroll to the end of the
document. However, even with this change, it will still be the case that
si.nPos is not equal to 74 after the SetScrollInfo call. This is explained
by Petzold on p.111 of the 5th ed. (and presumably at some other page in
earlier editions).
A value of 74 would mean that the last line of text was positioned as the
first line of the window, with the rest of the window below that line being
blank. This is a case of having scrolled too far since you miss out on
seeing earlier lines for no good reason. SetScrollInfo adjusts si.nPos so
that the last line of text is positioned as the last line of the window and
you do get to see earlier lines. This means si.nPos equals 51 in this case.
--
John Carson
.
Relevant Pages
- Re: Long ex. but simple!
... I will as soon as I get a chance to. ... >> page, and I hit the END key of my keyboard, shouldn't the window take ... Why wasn't this value kept in the SCROLLINFO ... SetScrollInfo adjusts si.nPos so ... (microsoft.public.vc.language) - Re: CScrollView: How to disable unused scrollbars (SIF_DISABLENOSCROLL)?
... SCROLLINFO that you are passing to SetScrollInfo for SIF_DISABLENOSCROLL to ... This will display a disabled scrollbar scroll bar. ... current view fits entirely into the window. ... both before and after my call to SetScrollSizes: ... (microsoft.public.vc.mfc) - Re: ActiveWindow.Width
... Returns the width of a window in points (point: ... the height of a printed character. ... A point equals 1/72 of an inch, ... (microsoft.public.excel.programming) - RE: Filter help needed
... The greater than or less than options also include- equals, contains, begins with, ends with, etc. ... The reason I accidently posted my original twice was I couldn't find it for a while after I posted it, ... in the window for you. ... I do appreciate your help :-) Jeff ... (microsoft.public.excel.worksheet.functions) - Re: Filter help needed
... The greater than or less than options also include- equals, contains, begins with, ends with, etc. ... The reason I accidently posted my original twice was I couldn't find it for a while after I posted it, ... in the window for you. ... I do appreciate your help :-) Jeff ... (microsoft.public.excel.worksheet.functions) |
|