Problem differentiating IMessageFilter messages between forms

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello,

I've had great success in this forum finding out how to use the
IMessageFilter. I have it working well on a test form I've built.

The next challenge I face is this:

I need to be able to intercept a key (F1 in this example) on two different
forms. An F1 keypress on one form would close the form, and an F1 keypress
on another form (called modally from the main form) is launching an RDA.push.

So I have two forms up at once using the same keycode. I've tried adding
one message filter per form with no success.

Is there a way to implement the IMessageFilter and distinguish what form the
messages are getting passed back to?

Thank you,

Tobin
 
I jumped ahead a little... I actually cannot get the IMessageFilter
implementation to recognize any key events beyond the first form I load.

I initialize the IMessageFilter using a Sub Main and attach the filter to
the application, but keypress events only occur within frmMain and do not
occur in any subsequent form launched.

Any suggestions????

Thanks again.

&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
CODE
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&



Public Shared Sub Main()
Init()
ApplicationEx.Run(New frmMain)
End Sub

Public Shared Sub Init()
Dim MyFilter As New FormMessageFilter
ApplicationEx.AddMessageFilter(MyFilter)
End Sub


Imports Microsoft.WindowsCE.Forms
Imports OpenNETCF.Windows.Forms

Public Class FormMessageFilter
Implements IMessageFilter

'Method for filtering the message
Public Function PreFilterMessage(ByRef m As Message) As Boolean
Implements _
IMessageFilter.PreFilterMessage

Dim WM_KEYUP As Integer = &H101
Dim keyCode As Keys = CType(m.WParam.ToInt32, Keys) And Keys.KeyCode

If m.Msg = WM_KEYUP And keyCode = Keys.F1 Then
MsgBox("F1 Key Pressed", MsgBoxStyle.OKOnly)
Return True
End If

Return False

End Function

End Class


&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
END CODE
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
 
I'm not using the form.ShowDialog.... the ApplicationEX.Run(New frmMain) in
the Sub Main is what appears to be launching the initial forms load.

Am I missing something?

Thank you,

Tobin

Sergey Bogdanov said:
Instead of form.ShowDialog use ApplicationEx.ShowDialog(form).

--
Sergey Bogdanov [.NET CF MVP, MCSD]
http://www.sergeybogdanov.com

I jumped ahead a little... I actually cannot get the IMessageFilter
implementation to recognize any key events beyond the first form I load.

I initialize the IMessageFilter using a Sub Main and attach the filter to
the application, but keypress events only occur within frmMain and do not
occur in any subsequent form launched.

Any suggestions????

Thanks again.

&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
CODE
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&



Public Shared Sub Main()
Init()
ApplicationEx.Run(New frmMain)
End Sub

Public Shared Sub Init()
Dim MyFilter As New FormMessageFilter
ApplicationEx.AddMessageFilter(MyFilter)
End Sub


Imports Microsoft.WindowsCE.Forms
Imports OpenNETCF.Windows.Forms

Public Class FormMessageFilter
Implements IMessageFilter

'Method for filtering the message
Public Function PreFilterMessage(ByRef m As Message) As Boolean
Implements _
IMessageFilter.PreFilterMessage

Dim WM_KEYUP As Integer = &H101
Dim keyCode As Keys = CType(m.WParam.ToInt32, Keys) And Keys.KeyCode

If m.Msg = WM_KEYUP And keyCode = Keys.F1 Then
MsgBox("F1 Key Pressed", MsgBoxStyle.OKOnly)
Return True
End If

Return False

End Function

End Class


&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
END CODE
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&



:
 
You said that your didn't receive messages from your second dialog
window, did you? Due to specific implementation of ShowDialog method you
have to open all your dialog window with ApplicationEx.ShowDialog.
But ApplicationEx.Run(new frmMain) stays as is.

--
Sergey Bogdanov [.NET CF MVP, MCSD]
http://www.sergeybogdanov.com

I'm not using the form.ShowDialog.... the ApplicationEX.Run(New frmMain) in
the Sub Main is what appears to be launching the initial forms load.

Am I missing something?

Thank you,

Tobin

:

Instead of form.ShowDialog use ApplicationEx.ShowDialog(form).

--
Sergey Bogdanov [.NET CF MVP, MCSD]
http://www.sergeybogdanov.com

I jumped ahead a little... I actually cannot get the IMessageFilter
implementation to recognize any key events beyond the first form I load.

I initialize the IMessageFilter using a Sub Main and attach the filter to
the application, but keypress events only occur within frmMain and do not
occur in any subsequent form launched.

Any suggestions????

Thanks again.

&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
CODE
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&



Public Shared Sub Main()
Init()
ApplicationEx.Run(New frmMain)
End Sub

Public Shared Sub Init()
Dim MyFilter As New FormMessageFilter
ApplicationEx.AddMessageFilter(MyFilter)
End Sub


Imports Microsoft.WindowsCE.Forms
Imports OpenNETCF.Windows.Forms

Public Class FormMessageFilter
Implements IMessageFilter

'Method for filtering the message
Public Function PreFilterMessage(ByRef m As Message) As Boolean
Implements _
IMessageFilter.PreFilterMessage

Dim WM_KEYUP As Integer = &H101
Dim keyCode As Keys = CType(m.WParam.ToInt32, Keys) And Keys.KeyCode

If m.Msg = WM_KEYUP And keyCode = Keys.F1 Then
MsgBox("F1 Key Pressed", MsgBoxStyle.OKOnly)
Return True
End If

Return False

End Function

End Class


&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
END CODE
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&



:



You can distingish forms by their Hwnd that is passed in the Msg parameter

--
Alex Yakhnin, .NET CF MVP
www.intelliprog.com | www.opennetcf.org


:



Hello,

I've had great success in this forum finding out how to use the
IMessageFilter. I have it working well on a test form I've built.

The next challenge I face is this:

I need to be able to intercept a key (F1 in this example) on two different
forms. An F1 keypress on one form would close the form, and an F1 keypress
on another form (called modally from the main form) is launching an RDA.push.

So I have two forms up at once using the same keycode. I've tried adding
one message filter per form with no success.

Is there a way to implement the IMessageFilter and distinguish what form the
messages are getting passed back to?

Thank you,

Tobin
 
Your are correct. I used the ApplicationEX.ShowDialog when opening
subsequent forms and am now interception messages applicaiton wide.

Thank you.

Sergey Bogdanov said:
You said that your didn't receive messages from your second dialog
window, did you? Due to specific implementation of ShowDialog method you
have to open all your dialog window with ApplicationEx.ShowDialog.
But ApplicationEx.Run(new frmMain) stays as is.

--
Sergey Bogdanov [.NET CF MVP, MCSD]
http://www.sergeybogdanov.com

I'm not using the form.ShowDialog.... the ApplicationEX.Run(New frmMain) in
the Sub Main is what appears to be launching the initial forms load.

Am I missing something?

Thank you,

Tobin

:

Instead of form.ShowDialog use ApplicationEx.ShowDialog(form).

--
Sergey Bogdanov [.NET CF MVP, MCSD]
http://www.sergeybogdanov.com


Tobin wrote:

I jumped ahead a little... I actually cannot get the IMessageFilter
implementation to recognize any key events beyond the first form I load.

I initialize the IMessageFilter using a Sub Main and attach the filter to
the application, but keypress events only occur within frmMain and do not
occur in any subsequent form launched.

Any suggestions????

Thanks again.

&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
CODE
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&



Public Shared Sub Main()
Init()
ApplicationEx.Run(New frmMain)
End Sub

Public Shared Sub Init()
Dim MyFilter As New FormMessageFilter
ApplicationEx.AddMessageFilter(MyFilter)
End Sub


Imports Microsoft.WindowsCE.Forms
Imports OpenNETCF.Windows.Forms

Public Class FormMessageFilter
Implements IMessageFilter

'Method for filtering the message
Public Function PreFilterMessage(ByRef m As Message) As Boolean
Implements _
IMessageFilter.PreFilterMessage

Dim WM_KEYUP As Integer = &H101
Dim keyCode As Keys = CType(m.WParam.ToInt32, Keys) And Keys.KeyCode

If m.Msg = WM_KEYUP And keyCode = Keys.F1 Then
MsgBox("F1 Key Pressed", MsgBoxStyle.OKOnly)
Return True
End If

Return False

End Function

End Class


&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
END CODE
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&



:



You can distingish forms by their Hwnd that is passed in the Msg parameter

--
Alex Yakhnin, .NET CF MVP
www.intelliprog.com | www.opennetcf.org


:



Hello,

I've had great success in this forum finding out how to use the
IMessageFilter. I have it working well on a test form I've built.

The next challenge I face is this:

I need to be able to intercept a key (F1 in this example) on two different
forms. An F1 keypress on one form would close the form, and an F1 keypress
on another form (called modally from the main form) is launching an RDA.push.

So I have two forms up at once using the same keycode. I've tried adding
one message filter per form with no success.

Is there a way to implement the IMessageFilter and distinguish what form the
messages are getting passed back to?

Thank you,

Tobin
 
Back
Top