5

Could anyone point me to (or provide?) some nice, clear examples of how to implement scrolling in Win32? Google brings up a lot of stuff, obviously, but most examples seem either too simple or too complicated for me to be sure that they demonstrate the right way of doing things. I use LispWorks CAPI (cross-platform Common Lisp GUI lib) in my current project, and on Windows I have a hard-to-figure-out bug relating to scrolling; basically I want to do some tests directly via the Win32 API to see if I can shed some light on the situation.

Many thanks, Christopher

tommybee
  • 2,409
  • 1
  • 20
  • 23
Christopher
  • 51
  • 1
  • 2
  • It's not clear what you mean. You tell a window to scroll by sending it a `WM_SCROLLWINDOW` message, and then it's up to the window to respond correctly. If you're seeing a problem, then either the window is not being sent the right messages, or it's handing the message improperly. So: what are you seeing? – egrunin May 02 '10 at 18:13
  • As egrunin points out, you need to be more specific. What is it you want to scroll and how? Is it text? Do you want to control a scrollbox? Is it old fashion bitmap scrolling? What kind of application is it? Game? – Max Kielland Dec 15 '10 at 14:42
  • 2
    This is all covered in Petzold's book, like so many Win32 questions here. – David Heffernan Jan 17 '11 at 12:04
  • @egrunin I cannot find reference to WM_SCROLLWINDOW. – user13947194 Aug 07 '21 at 14:20
  • @user13947194 Sorry, I meant "WM_VSCROLL or WM_HSCROLL message". – egrunin Aug 09 '21 at 02:01
  • @egrunin That is where I was confused as I dont know of WM_*SCROLL to be messages sent by the client window. I know of them to be messages sent by the system. I am very concerned because I was/am implementing a ListView. I use GDI to draw the data section, and wanted to use Windows header control for the header. One problem I faced was simply not knowing how to scroll the header control! Which is an easy task in Android. I tried ScrollWindow, but that was a disaster. Setting the window position moved the window to the scrolling offset, but my sizing code would place the header back to 0,0 – user13947194 Aug 09 '21 at 02:32

2 Answers2

-1

I think you are talking for an example how to handle WM_VSCROLL/WM_HSCROLL event. If so first step is to handle that event. You shouldn't use the HIWORD(wParam) value of that call but use GetScrollInfo, GetScrollPos, and GetScrollRange functions instead.

Following is an example code snipped by MSDN - Using Scroll Bars. xCurrentScroll is determined before by calling GetScrollPos() for example.

int xDelta;     // xDelta = new_pos - current_pos  
int xNewPos;    // new position 
int yDelta = 0; 

switch (LOWORD(wParam)) { 
    // User clicked the scroll bar shaft left of the scroll box. 
    case SB_PAGEUP: 
        xNewPos = xCurrentScroll - 50; 
        break; 

    // User clicked the scroll bar shaft right of the scroll box. 
    case SB_PAGEDOWN: 
        xNewPos = xCurrentScroll + 50; 
        break; 

    // User clicked the left arrow. 
    case SB_LINEUP: 
        xNewPos = xCurrentScroll - 5; 
        break; 

    // User clicked the right arrow. 
    case SB_LINEDOWN: 
        xNewPos = xCurrentScroll + 5; 
        break; 

    // User dragged the scroll box. 
    case SB_THUMBPOSITION: 
        xNewPos = HIWORD(wParam); 
        break; 

    default: 
        xNewPos = xCurrentScroll; 
} 

[...]

// New position must be between 0 and the screen width. 
xNewPos = max(0, xNewPos); 
xNewPos = min(xMaxScroll, xNewPos); 

[...]

// Reset the scroll bar. 
si.cbSize = sizeof(si); 
si.fMask  = SIF_POS; 
si.nPos   = xCurrentScroll; 
SetScrollInfo(hwnd, SB_HORZ, &si, TRUE);
bkausbk
  • 2,740
  • 1
  • 36
  • 52
-1

Here's one, ScrollCall, (copy from page):.

ScrollCall is a demo program that takes a sample of Windows standard controls, along with a standard GDI image, and arranges them on a Device Context (or DC), in a window. Depending on the dimensions of the image, and the size of the containing window, horizontal and/or system scrollbars become visible, to enable scrolling for the image and controls. Thus ScrollCall is as at least as much focused on sizing as it is scrolling, and both offer unique challenges for the programmer.

ScrollCall features:

  • System scroll bars
  • Optional groupbox
  • Button to open images on the Device Context (DC)
  • Radio options for choice of window scroll function
  • Checkbox to stretch rather than scroll the image
  • Label Paint Mult with UpDown and Buddy to increase the wait times of WM_SIZE during sizing, thus reduced WM_PAINT processing
  • Right click for system snapshot of view in default or monitor attached to desktop
  • Double-click to print the visible part of the (mostly empty) client window to the DC, and back to the client window (experimental)
  • ScrollCall temporarily turns on SPI_SETDRAGFULLWINDOWS for the testing of the visual effects of dragging, if ever it was toggled off
  • Compatibility with AeroSnap sizing
Laurie Stearn
  • 959
  • 1
  • 13
  • 34