OpenNetCF PreMessageFilter problem with VB.net

  • Thread starter Thread starter Enrico Pavesi
  • Start date Start date
E

Enrico Pavesi

I create a class like this
Public Class KeyFilter
Implements IMessageFilter
Overridable Function PreFilterMessage(ByRef m As
Microsoft.WindowsCE.Forms.Message) As Boolean Implements
IMessageFilter.PreFilterMessage
Dim tasto As Integer

Select Case m.Msg
Case 786
tasto = m.WParam.ToInt32()
Select Case (tasto)
Case 193 To 196
Return True
End Select
End Select
Return False
End Function

End Class

then in the main form
InitializeComponent()
Dim Filtro As KeyFilter = New KeyFilter
ApplicationEx.AddMessageFilter(Filtro)

But this code does not trap the virtual hardware key

The same in a test C# project works.

Do someone knows why it does not work?

Thanks
 
Haven't looked at your code but read your question at the end. It sounds
like you have some code in C# that works and a VB version that doesn't. If
you post *both* versions we might be able to help.

Cheers
Daniel
 
The C# version is:
class KeyFilter : IMessageFilter
{
public bool PreFilterMessage(ref Message m)
{
switch(m.Msg)
{
case 0x0312:
int tasto = m.WParam.ToInt32();
switch(tasto )
{
case 193:
case 196:
return true;
break;
}

break;
}
}
return false;
}
}

and after initialize component:
KeyFilter Filtro = new KeyFilter();
ApplicationEx.AddMessageFilter(Filtro);

In the VB version it never stop at message 786 (0x0312)

Thanks
 
Reading this in outlook I can't see anything obvious. I presume you are
using ApplicationEx etc from a C# library and not translated them to VB,
right? If you send the project with repro steps I can have a look at it.

A couple of general comments if you want them:
1. You don't have to translate the hex to int in VB. Just use &H0312
2. Not sure why you made the interface implementation Overridable. I would
replace that with Public.
3. Case 193 To 196. Replace To with ,

Cheers
Daniel
 
The problem is that is an existing project and i can't send it.

If you have time you can post a 10 lines working vb project that trap
virtual hardkey.

In any case thanks for your hints

Regards
 
Back
Top