MouseWheel
フォーム レベルで生成されたイベントを転送しWebBrowser
て、そのコントロールにフォーカスがない場合でも、埋め込みコントロールによって処理されるようにしたいと考えていました。
これが私がやったことです:
- 実装され
IMessageFilter.PreFilterMessage
ました。 - でフィルタを登録しました
Application.AddMessageFilter
。 - フィルターで、
WM_MOUSEWHEEL
メッセージをリッスンします。 SendMessage
を使用してメッセージをターゲット コントロールに転送します(私の場合はWebBrowser
)。
コードでは、これは次のようになります。
bool IMessageFilter.PreFilterMessage(ref Message m)
{
if (m.Msg == 0x20A) // WM_MOUSEWHEEL
{
if (this.target != null)
{
var handle = this.target.Handle;
Native.SendMessage (handle, m.Message, m.WParam, m.LParam);
return true;
}
}
return false;
}
// Registering the message filter:
System.Windows.Forms.Application.AddMessageFilter (this);
// Win32 code:
protected static class NativeMethods
{
[System.Runtime.InteropServices.DllImport ("user32.dll")]
public static extern System.IntPtr SendMessage(System.IntPtr hWnd, System.Int32 Msg, System.IntPtr wParam, System.IntPtr lParam);
}
これは動作しません。何も起こりません。
ただし、 a の代わりに aWebBrowser
をターゲットとして指定するPanel
と、これは非常にうまく機能します。