R
Rickard
Does IMessageFilter.PreFilterMessage not work with all messages?
Consider the VB app at the bottom of this posting.
The WM_ACTIVATE in the overrided WndProc gets printed, but not the one
in the message filter (the message filter works for other messages like
WM_MOUSEDOWN). Is this behavior by design? There is not mention of which
messaged gets filtered in the documentation for IMessageFilter.
Is there some way to catch WM_ACTIVATE for all windows in my app without
overriding all WndProcs?
------------------------------------------------------------------
Public Class Form1
Implements IMessageFilter
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
Dim f As New Form2
f.Show()
End Sub
Public Function PreFilterMessage( _
ByRef m As System.Windows.Forms.Message) As Boolean _
Implements System.Windows.Forms.IMessageFilter.PreFilterMessage
Static i As Integer = 0
If m.Msg = 6 Then
i += 1
Debug.Print("Activate " & i)
End If
End Function
Private Sub Button2_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button2.Click
Application.AddMessageFilter(Me)
End Sub
Protected Overrides Sub WndProc( _
ByRef m As System.Windows.Forms.Message)
Static i As Integer = 0
If m.Msg = 6 Then
i += 1
Debug.Print("WM_ACTIVATE " & i)
End If
MyBase.WndProc(m)
End Sub
End Class
------------------------------------------------------------------
Consider the VB app at the bottom of this posting.
The WM_ACTIVATE in the overrided WndProc gets printed, but not the one
in the message filter (the message filter works for other messages like
WM_MOUSEDOWN). Is this behavior by design? There is not mention of which
messaged gets filtered in the documentation for IMessageFilter.
Is there some way to catch WM_ACTIVATE for all windows in my app without
overriding all WndProcs?
------------------------------------------------------------------
Public Class Form1
Implements IMessageFilter
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
Dim f As New Form2
f.Show()
End Sub
Public Function PreFilterMessage( _
ByRef m As System.Windows.Forms.Message) As Boolean _
Implements System.Windows.Forms.IMessageFilter.PreFilterMessage
Static i As Integer = 0
If m.Msg = 6 Then
i += 1
Debug.Print("Activate " & i)
End If
End Function
Private Sub Button2_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button2.Click
Application.AddMessageFilter(Me)
End Sub
Protected Overrides Sub WndProc( _
ByRef m As System.Windows.Forms.Message)
Static i As Integer = 0
If m.Msg = 6 Then
i += 1
Debug.Print("WM_ACTIVATE " & i)
End If
MyBase.WndProc(m)
End Sub
End Class
------------------------------------------------------------------