Win32 滚动示例

发布于 2024-08-31 01:21:12 字数 237 浏览 2 评论 0原文

谁能向我指出(或提供?)一些关于如何在 Win32 中实现滚动的漂亮、清晰的示例?显然,谷歌提出了很多东西,但大多数例子对我来说似乎要么太简单要么太复杂,无法确保它们展示了正确的做事方式。我在当前的项目中使用 LispWorks CAPI(跨平台 Common Lisp GUI 库),在 Windows 上我有一个与滚动相关的难以找出的错误;基本上我想直接通过 Win32 API 进行一些测试,看看是否可以阐明情况。

非常感谢, 克里斯托弗

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

凡尘雨 2024-09-07 01:21:12

我认为您正在谈论如何处理 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);

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);
迷离° 2024-09-07 01:21:12

这是一个 ScrollCall(从页面复制):。

ScrollCall 是一个演示程序,采用 Windows 标准示例
控件以及标准 GDI 图像,并将它们排列在
窗口中的设备上下文(或 DC)。取决于尺寸
图像,以及包含窗口的大小,水平和/或
系统滚动条变得可见,以启用图像滚动
和控制。因此 ScrollCall 至少同样关注大小调整
当它滚动时,两者都为玩家带来了独特的挑战
程序员。

ScrollCall 功能:

  • 系统滚动条
  • 可选组框
  • 用于在设备上下文 (DC) 上打开图像的按钮
  • 用于选择窗口滚动功能的单选选项
  • 用于拉伸而不是滚动图像的复选框
  • 带有 UpDown 和 Buddy 的 Label Paint Mult 以增加 WM_SIZE 期间的等待时间调整大小,从而减少 WM_PAINT 处理
  • 右键单击​​默认视图或连接到桌面的监视器的系统
  • 快照 双击将(大部分是空的)客户端窗口的可见部分打印到 DC,然后返回到客户端窗口(实验)
  • ScrollCall暂时打开 SPI_SETDRAGFULLWINDOWS 以测试拖动的视觉效果(如果曾经关闭过)
  • 与 AeroSnap 大小调整的兼容性

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文