首页
社区
课程
招聘
请看看这段处理滚动消息的代码
发表于: 2005-11-4 19:53 5042

请看看这段处理滚动消息的代码

2005-11-4 19:53
5042
下载了一个控件的源代码,注释很少
有些地方没有完全看懂,请帮忙看看

//处理滚动条消息
//返回:  滚动条的Position
function
TCustomHexEdit.DoScroll(
   AScrollKind: TScrollKind; Msg: TWMScroll): Integer;
var
  BarFlag: Integer;
  MaxPos: Integer;
  ScrInfo: TScrollInfo;
begin
  if AScrollKind = skHorizontal then
    BarFlag := SB_HORZ
  else
    BarFlag := SB_VERT;

  FillChar(ScrInfo, SizeOf(ScrInfo), 0);
  ScrInfo.cbSize := SizeOf(ScrInfo);
  ScrInfo.fMask := SIF_ALL;
  GetScrollInfo(Handle, BarFlag, ScrInfo);

  MaxPos := ScrInfo.nMax - Integer(ScrInfo.nPage) + 1;
  case Msg.ScrollCode of
    SB_LINEUP:
      if ScrInfo.nPos > ScrInfo.nMin then
      begin
        Dec(ScrInfo.nPos);
      end;
    SB_LINEDOWN:
      if ScrInfo.nPos < MaxPos then
      begin
        Inc(ScrInfo.nPos);
      end;
    SB_PAGEUP:
      if ScrInfo.nPos > ScrInfo.nMin then
      begin
        Dec(ScrInfo.nPos, ScrInfo.nPage);
      end;
    SB_PAGEDOWN:
      if ScrInfo.nPos < MaxPos then
      begin
        Inc(ScrInfo.nPos, ScrInfo.nPage);
      end;
    SB_THUMBPOSITION,
    SB_THUMBTRACK:
      begin
  // ScrInfo.nPos := Msg.Pos;
  // Msg.Pos是16-bits的, 行数太多时会溢出
        ScrInfo.nPos := ScrInfo.nTrackPos;
      end;
    SB_LEFT:
      if ScrInfo.nPos <> ScrInfo.nMin then
      begin
        ScrInfo.nPos := ScrInfo.nMin;
      end;
    SB_RIGHT:
      if ScrInfo.nPos < MaxPos then
      begin
        ScrInfo.nPos := MaxPos;
      end;
    SB_ENDSCROLL:
      begin
        ScrInfo.nPos := ScrInfo.nPos;
      end;
  end;

  if ScrInfo.nPos < ScrInfo.nMin then
     ScrInfo.nPos := ScrInfo.nMin;
  if ScrInfo.nPos > MaxPos then
     ScrInfo.nPos := MaxPos;
  UpdateScrollPos(AScrollKind, ScrInfo.nPos);
  Result := ScrInfo.nPos;
end;

[课程]FART 脱壳王!加量不加价!FART作者讲授!

收藏
免费 0
支持
分享
最新回复 (5)
雪    币: 214
活跃值: (70)
能力值: ( LV3,RANK:20 )
在线值:
发帖
回帖
粉丝
2
DELPHI看不懂
2005-11-4 21:15
0
雪    币: 288
活跃值: (112)
能力值: ( LV12,RANK:290 )
在线值:
发帖
回帖
粉丝
3
看完了。。。。。
2005-11-5 14:10
0
雪    币: 212
活跃值: (40)
能力值: ( LV4,RANK:50 )
在线值:
发帖
回帖
粉丝
4
没有什么问题啊!那里看不懂,说出来才好答啊
2005-11-5 18:11
0
雪    币: 1540
活跃值: (2807)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
5
这段程序的是获取滚动条的位置的,是不是共用一个
ScrInfo: TScrollInfo;来得到滚动条的位置
比如水平滚动和垂直滚动。

还有这两个参数的意思不大明白
SB_THUMBPOSITION
SB_THUMBTRACK:

最初由 limee 发布
下载了一个控件的源代码,注释很少
有些地方没有完全看懂,请帮忙看看

//处理滚动条消息
//返回: 滚动条的Position
........
2005-11-5 23:56
0
雪    币: 212
活跃值: (40)
能力值: ( LV4,RANK:50 )
在线值:
发帖
回帖
粉丝
6
SB_THUMBPOSITION The user has dragged the scroll box (thumb) and released the mouse button. The nPos parameter indicates the position of the scroll box at the end of the drag operation.

SB_THUMBTRACK The user is dragging the scroll box. This message is sent repeatedly until the user releases the mouse button. The nPos parameter indicates the position that the scroll box has been dragged to.

这是CSDN上的解释,相信你看了就会明白了;

死了没机会了。今天发了三贴了。唉
2005-11-7 12:05
0
游客
登录 | 注册 方可回帖
返回
//