WMMouseWheel不在Delphi中工作 [英] WMMouseWheel not working in Delphi
问题描述
我写了以下代码:
procedure MouseWheel(var Msg:TWMMouseWheel); message WM_MOUSEHWHEEL;
我用它为基于TPanel(TMyP = class(TPanel))
(注意,由于我自己的原因,我不想使用TCustomPanel)
I wrote the following code:
procedure MouseWheel(var Msg:TWMMouseWheel);message WM_MOUSEHWHEEL;
I used it for a component based on TPanel (TMyP=class(TPanel))
(Notice that I don't want to use TCustomPanel due to my own reasons)
但无论如何,事件是当我在面板上使用鼠标滚轮时不调用。
请帮助我!
But anyway the event is not called when I use mouse wheel on the panel. Please Help me!
推荐答案
鼠标滚轮消息以焦点发送到控件。而且面板通常是不能对焦的。
The mouse wheel messages are sent to the control with the focus. And panels usually aren't focusable.
我在应用程序中使用这个TApplicationEvents.OnMessage处理程序将鼠标滚轮消息发送到鼠标光标下的窗口而不是焦点控制。
I use this TApplicationEvents.OnMessage handler in my applications to send the mouse wheel message to the window under the mouse cursor instead of the focused control.
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;
这篇关于WMMouseWheel不在Delphi中工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!