Win32滚动示例

Chr*_*her 5 winapi scroll win32gui

任何人都可以指出(或提供?)一些很好的,明确的如何在Win32中实现滚动的例子?显然,谷歌提出了很多东西,但大多数例子对我来说似乎太简单或太复杂,无法确保他们能够证明正确的做事方式.我在当前项目中使用LispWorks CAPI(跨平台Common Lisp GUI库),在Windows上我有一个难以弄清楚的与滚动相关的错误; 基本上我想通过Win32 API直接做一些测试,看看我是否可以对这种情况有所了解.

非常感谢,克里斯托弗

bka*_*sbk -1

我认为您正在谈论如何处理 WM_VSCROLL/WM_HSCROLL 事件的示例。如果是这样,第一步是处理该事件。您不应使用该调用的 HIWORD(wParam) 值,而应使用 GetScrollInfo、GetScrollPos 和 GetScrollRange 函数。

以下是MSDN - 使用滚动条截取的示例代码。例如,xCurrentScroll 是通过调用 GetScrollPos() 之前确定的。

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);
Run Code Online (Sandbox Code Playgroud)