Message Window filtering

U

usunto_bryjamus

Hi,

I need to filter some messages in my form (in some situation I need to
avoid mouse messages) so I create derivedd class:

public class MyMessageWnd : MessageWindow
{
// When true mouse messages are avoided.
private bool enableFiltering;
public bool EnableFiltering
{
set
{
this.enableFiltering = value;
}
}

public MyMessageWnd(IntPtr wndHandle)
{
this.wndHandle = wndHandle;
this.enableFiltering = false;
}

// Only for this window avoid messages.
private IntPtr wndHandle;

const int WM_MOUSEACTIVATE = 0x21;
const int WM_MOUSEFIRST = 0x200;
const int WM_MOUSEHOVER = 0x2A1;
const int WM_MOUSELAST = 0x20A;
const int WM_MOUSELEAVE = 0x2A3;
const int WM_MOUSEMOVE = 0x200;
const int WM_MOUSEWHEEL = 0x20A;

protected override void WndProc(ref Message m)
{
if (!(this.enableFiltering && this.wndHandle != IntPtr.Zero
&& m.HWnd == this.wndHandle && (m.Msg == WM_MOUSEACTIVATE || m.Msg ==
WM_MOUSEFIRST || m.Msg == WM_MOUSEHOVER || m.Msg == WM_MOUSELAST ||
m.Msg == WM_MOUSELEAVE || m.Msg == WM_MOUSEMOVE || m.Msg == WM_MOUSEWHEEL)))
{
base.WndProc(ref m);
}
}
}

In my form class I declare like this:

....
MyMessageWnd mmw;

/// <summary>
/// Construktor.
/// </summary>
public FormCtor()
{
mmw = new MyMessageWnd(this.Handle);
mmw.EnableFiltering = false;

InitializeComponent();
...
}
....

Problem is that WndProc is called only when I close application. When I
click on form or press key nothing is happend. What is it? Meybe there
is some easier way to avoid mouse messages? I look in google but I found
only MessageWindow for this purpose.

I use netcf 2.0 with SP on WinCE 5.0 Symbol MC3090 device.
 
P

Peter Foot [MVP]

The MessageWindow creates a separate native window separate from your main
form and so it wont receive any messages sent to your form. In order to
intercept these you would need to intercept the messages sent to your form.
You can do this in .NETCF v2.0 with a little P/Invoke. Alex Yakhnin showed
how to do this here:-
http://blog.opennetcf.org/ayakhnin/PermaLink,guid,eacd2a5f-a7fb-4bce-9336-f974ea2d2e29.aspx
With a practical example here:-
http://blog.opennetcf.org/ayakhnin/PermaLink,guid,4069b90f-f53f-4726-8790-36a9d3830aed.aspx

Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top