WMMouseWheel不在Delphi中工作

Jav*_*vid 4 delphi

我编写了以下代码: procedure MouseWheel(var Msg:TWMMouseWheel);message WM_MOUSEHWHEEL; 我将它用于基于TPanel的组件(TMyP = class(TPanel))(请注意,由于我自己的原因,我不想使用TCustomPanel)

但无论如何,当我在面板上使用鼠标滚轮时,不会调用该事件.请帮我!

And*_*den 12

鼠标滚轮消息将通过焦点发送到控件.面板通常不可调焦.

我在我的应用程序中使用此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;
Run Code Online (Sandbox Code Playgroud)