yottaawesome / programming-windows-5th-edition

Unofficial source code repo for Charles Petzold's Programming Windows 5th Edition.
https://www.microsoftpressstore.com/store/programming-windows-9780735692633
84 stars 35 forks source link

Bugs in Chap06/SysMets4/SysMets4.c ? #1

Closed yanpeng closed 1 year ago

yanpeng commented 1 year ago

In the line 246

SendMessage(hwnd, WM_HSCROLL, SB_PAGEUP, 0);

and in the line 250

SendMessage(hwnd, WM_HSCROLL, SB_PAGEDOWN, 0);

in the LOWORD(wParam) of WM_HSCROLL, there are no corresponding SB_PAGEUP and SB_PAGEDOWN, I think the author made some errors by accident.

yottaawesome commented 1 year ago

I'll check the sample and the book's notes to see if it's an oversight. If it is, I'll update this issue and either fix the problem or add a comment to the sample.

yottaawesome commented 1 year ago

It's a bit confusing but this doesn't appear to be a bug or oversight. SB_PAGEUP and SB_PAGELEFT share the same ordinal value of 2, and SB_PAGEDOWN and SB_PAGERIGHT share the same ordinal value of 3. I've reproduced the relevant #defines from winuser.h below for reference.

/*
 * Scroll Bar Commands
 */
#define SB_LINEUP           0
#define SB_LINELEFT         0
#define SB_LINEDOWN         1
#define SB_LINERIGHT        1
#define SB_PAGEUP           2
#define SB_PAGELEFT         2
#define SB_PAGEDOWN         3
#define SB_PAGERIGHT        3
#define SB_THUMBPOSITION    4
#define SB_THUMBTRACK       5
#define SB_TOP              6
#define SB_LEFT             6
#define SB_BOTTOM           7
#define SB_RIGHT            7

So sending SB_PAGEUP or SB_PAGEDOWN will still get handled as part of the SB_PAGELEFT and SB_PAGERIGHT sections in the WM_HSCROLL message (lines 183 and 187 respectively), and the effect will be to scroll the window left or right (assuming the window is narrow enough for the horizontal scroll bar to appear). I confirmed this by stepping through the code in the debugger.

So like I said, it's a bit confusing, but it appears to be intentional. Since nothing appears to be amiss, I'll close this issue.

Thanks, Vasilios