image控件没有OnMouseWheelDown和OnMouseWheelup这事件,怎么加上 ( 积分: 100 )

  • 主题发起人 主题发起人 shuihan20e
  • 开始时间 开始时间
S

shuihan20e

Unregistered / Unconfirmed
GUEST, unregistred user!
image控件没有OnMouseWheelDown和OnMouseWheelup这事件,怎么加上
 
方案1,自己再写个控件:tmyimage=class(timage)然后拦截WM_MOUSEWHEEL消息,自己再添加这2个事件,对消息值进行处理后分别触发对应的事件
方案2,在自己的form里拦截WM_MOUSEWHEEL,判断消息值,再对image做相应处理

消息参数含义如下:

WM_MOUSEWHEEL
fwKeys = LOWORD(wParam); // key flags
zDelta = (short) HIWORD(wParam); // wheel rotation
xPos = (short) LOWORD(lParam); // horizontal position of pointer
yPos = (short) HIWORD(lParam); // vertical position of pointer


Parameters

fwKeys

Value of the low-order word of wParam. Indicates whether various virtual keys are down. This parameter can be any combination of the following values:

Value Description
MK_CONTROL Set if the CTRL key is down.
MK_LBUTTON Set if the left mouse button is down.
MK_MBUTTON Set if the middle mouse button is down.
MK_RBUTTON Set if the right mouse button is down.
MK_SHIFT Set if the SHIFT key is down.


zDelta

The value of the high-order word of wParam. Indicates the distance that the wheel is rotated, expressed in multiples or divisions of WHEEL_DELTA, which is 120. A positive value indicates that the wheel was rotated forward, away from the user; a negative value indicates that the wheel was rotated backward, toward the user.

xPos

Value of the low-order word of lParam. Specifies the x-coordinate of the pointer, relative to the upper-left corner of the screen.

yPos

Value of the high-order word of lParam. Specifies the y-coordinate of the pointer, relative to the upper-left corner of the screen.

从别处抄一段中文翻译:
1.fwKeys= LOWORD(wParam),表明各种虚拟键是否按下,有如下值:

说明
MK_CONTROL
按下CTRL键
MK_LBUTTON
按下鼠标左键
MK_MBUTTON
按下鼠标中键
MK_RBUTTON
按下鼠标右键
MK_SHIFT
按下Shift键

2.zDelta = (short) HIWORD(wParam)

鼠标轮滚动的距离,如果向前则为正,向后为负。

3. xPos =(short) LOWORD(lParam)

yPos=(short) HIWORD(lParam)

鼠标的位置。
 
我最近碰到了一个和Image有关的问题,插入Jpge时正常,插入一张Jpge后,所有插入记录均能正常显示,但如果试运行时,不插入记录(插入记录时必须插入图片,这是设定好了的),而是直接显示记录,程序就报错,access violation at address 怎么都查不出问题,借楼主地盘一用,呵呵,相关的问题,摆在一起,好讨论。
 
当滚轮滚动时(不管鼠标位置),当前窗体的ActiveControl将收到WM_MOUSEWHEEL消息,如果ActiveControl不处理此消息,那么会一直向其Parent传递,如果一直没处理,就由DefWindowProc消化了。
所以只有TWinControl及其子控件才会收到消息,而TImage(继承自TGraphicControl)将不会收到WM_MOUSEWHEEL消息。

所以如果窗体内没有控件处理过(Hanlde = True表示已处理)OnMouseWheel, OnMouseWheelDown, OnMouseWheelUp这些事件的话,最终会触发窗体的相应事件,因此,只要在Form的OnMouseWheel, OnMouseWheelDown, OnMouseWheelUp作相应处理判断MousePos是否在Image内,当作是Image的MouseWheel。
 
汗..........补充下,前面说错了

如果是自己封装image控件,不是拦截WM_MOUSEWHEEL消息,而应该拦截CM_MOUSEWHEEL消息
呵呵
 
后退
顶部