【发布时间】:2010-11-13 11:32:43
【问题描述】:
我写了以下代码:
procedure MouseWheel(var Msg:TWMMouseWheel);message WM_MOUSEHWHEEL;
我将它用于基于 TPanel (TMyP=class(TPanel)) 的组件
(请注意,由于我自己的原因,我不想使用 TCustomPanel)
但无论如何,当我在面板上使用鼠标滚轮时,不会调用该事件。 请帮帮我!
【问题讨论】:
标签: delphi
我写了以下代码:
procedure MouseWheel(var Msg:TWMMouseWheel);message WM_MOUSEHWHEEL;
我将它用于基于 TPanel (TMyP=class(TPanel)) 的组件
(请注意,由于我自己的原因,我不想使用 TCustomPanel)
但无论如何,当我在面板上使用鼠标滚轮时,不会调用该事件。 请帮帮我!
【问题讨论】:
标签: delphi
鼠标滚轮消息发送到具有焦点的控件。而且面板通常不可聚焦。
我在我的应用程序中使用这个 TApplicationEvents.OnMessage 处理程序将鼠标滚轮消息发送到鼠标光标下的窗口而不是焦点控件。
procedure TMainDataModule.ApplicationEventsMessage(var Msg: tagMSG; var Handled: Boolean);
var
Wnd: HWND;
begin
if Msg.message = WM_MOUSEWHEEL then
begin
Wnd := WindowFromPoint(Msg.pt);
// It must be a VCL control otherwise we could get access violations
if IsVCLControl(Wnd) then
Msg.hwnd := Wnd; // change the message receiver to the control under the cursor
end;
end;
【讨论】:
除了 Andreas Hausladen 的回答之外,您还需要知道,一些鼠标驱动程序不发送 WM_MOUSEWHEEL 而是发送几个 WM_VSCROLL 消息。您还需要检查这一点。
更新:请注意,也存在 WM_HSCROLL 消息,这些消息也可以由一些具有两个轮子或倾斜轮的鼠标发送。这就是我最初写 WM_SCROLL 的原因。
【讨论】: