RECT rt; SCROLLINFO si;
// ********************************************************* // スクロールの最大値とページの最大値をセット // ********************************************************* void SetScrollRange( HWND hWnd, int nHeight ) { ZeroMemory(&si, sizeof( SCROLLINFO )); si.cbSize = sizeof( SCROLLINFO ); si.fMask = SIF_RANGE | SIF_PAGE; si.nMin = 0; GetClientRect( hWnd, &rt ); si.nMax = nHeight; si.nPage = rt.bottom; SetScrollInfo( hWnd, SB_VERT, &si, true ); RedrawWindow( hWnd, NULL, NULL, RDW_ERASE | RDW_INVALIDATE ); }
// このコード モジュールに含まれる関数の前宣言: ATOM MyRegisterClass( HINSTANCE hInstance ); BOOL InitInstance( HINSTANCE, int ); LRESULT CALLBACK WndProc( HWND, UINT, WPARAM, LPARAM ); LRESULT CALLBACK About( HWND, UINT, WPARAM, LPARAM ); void SetScrollRange( HWND hWnd, int nHeight );
case WM_PAINT: hdc = BeginPaint (hWnd, &ps); StretchBlt( hdc, 0, 0, nWidth, nHeight, hDCMem, 0, si.nPos, bmap.bmWidth, bmap.bmHeight, SRCCOPY ); EndPaint( hWnd, &ps ); break;
switch( LOWORD(wParam) ) { case SB_LINEDOWN: // 1 行下へスクロール。 si.nPos++; if ( si.nPos > bmap.bmHeight ) { si.nPos = bmap.bmHeight; } break; case SB_LINEUP: // 1 行上へスクロール。 si.nPos--; if ( si.nPos < 0 ) { si.nPos = 0; } break; case SB_PAGEDOWN: // 1 ページ下へスクロール。 GetClientRect( hWnd, &rt ); si.nPos += rt.bottom; if ( si.nPos + rt.bottom > bmap.bmHeight ) { si.nPos = bmap.bmHeight - rt.bottom + 1; } break; case SB_PAGEUP: // 1 ページ上へスクロール。 GetClientRect( hWnd, &rt ); si.nPos -= rt.bottom; if ( si.nPos < 0 ) { si.nPos = 0; } break; case SB_THUMBTRACK: // スクロール ボックスを指定位置へドラッグ。 si.cbSize = sizeof( SCROLLINFO ); si.fMask = SIF_TRACKPOS; GetScrollInfo( hWnd, SB_VERT, &si ); GetClientRect( hWnd, &rt ); si.nPos = si.nTrackPos; break; default: return 0; }