PC Review
Forums
Newsgroups
Microsoft DotNet
Microsoft Dot NET Framework Forms
PreFilterMessage + WM_ACTIVATE ??
Forums
Newsgroups
Microsoft DotNet
Microsoft Dot NET Framework Forms
PreFilterMessage + WM_ACTIVATE ??
![]() |
PreFilterMessage + WM_ACTIVATE ?? |
|
|
Thread Tools | Rate Thread |
|
|
#1 |
|
Guest
Posts: n/a
|
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 ------------------------------------------------------------------ |
|
|
|
#2 |
|
Guest
Posts: n/a
|
I wrote a simple app that logged all messages. Here is the result. It
seems there is quite a lot of messages not handled by PreFilterMessage. (0x00ae): WndProc, NOT PreFilterMessage (0x0118): PreFilterMessage, NOT WndProc (0xc136): WndProc, NOT PreFilterMessage WM_ACTIVATE: WndProc, NOT PreFilterMessage WM_ACTIVATEAPP: WndProc, NOT PreFilterMessage WM_CAPTURECHANGED: WndProc, NOT PreFilterMessage WM_CHANGEUISTATE: WndProc, NOT PreFilterMessage WM_CREATE: WndProc, NOT PreFilterMessage WM_CTLCOLORBTN: WndProc, NOT PreFilterMessage WM_CTLCOLORLISTBOX: WndProc, NOT PreFilterMessage WM_DRAWITEM: WndProc, NOT PreFilterMessage WM_ENTERSIZEMOVE: WndProc, NOT PreFilterMessage WM_ERASEBKGND: WndProc, NOT PreFilterMessage WM_EXITSIZEMOVE: WndProc, NOT PreFilterMessage WM_GETICON: WndProc, NOT PreFilterMessage WM_GETMINMAXINFO: WndProc, NOT PreFilterMessage WM_GETTEXT: WndProc, NOT PreFilterMessage WM_GETTEXTLENGTH: WndProc, NOT PreFilterMessage WM_MOUSEACTIVATE: WndProc, NOT PreFilterMessage WM_MOVE: WndProc, NOT PreFilterMessage WM_NCACTIVATE: WndProc, NOT PreFilterMessage WM_NCCALCSIZE: WndProc, NOT PreFilterMessage WM_NCCREATE: WndProc, NOT PreFilterMessage WM_NCHITTEST: WndProc, NOT PreFilterMessage WM_NCPAINT: WndProc, NOT PreFilterMessage WM_NOTIFYFORMAT: WndProc, NOT PreFilterMessage WM_PARENTNOTIFY: WndProc, NOT PreFilterMessage WM_PRINTCLIENT: WndProc, NOT PreFilterMessage WM_QUERYUISTATE: WndProc, NOT PreFilterMessage WM_SETCURSOR: WndProc, NOT PreFilterMessage WM_SETICON: WndProc, NOT PreFilterMessage WM_SETTEXT: WndProc, NOT PreFilterMessage WM_SHOWWINDOW: WndProc, NOT PreFilterMessage WM_SIZE: WndProc, NOT PreFilterMessage WM_SIZING: WndProc, NOT PreFilterMessage WM_STYLECHANGED: WndProc, NOT PreFilterMessage WM_STYLECHANGING: WndProc, NOT PreFilterMessage WM_SYNCPAINT: WndProc, NOT PreFilterMessage WM_SYSCOMMAND: WndProc, NOT PreFilterMessage WM_UPDATEUISTATE: WndProc, NOT PreFilterMessage WM_WINDOWPOSCHANGED: WndProc, NOT PreFilterMessage WM_WINDOWPOSCHANGING: WndProc, NOT PreFilterMessage |
|
|
|
#3 |
|
Guest
Posts: n/a
|
PreFilterMessage will only notify you of messages that are posted to the
message queue (after they are pulled from it but before they are dispatched). WM_ACTIVATE is sent directly to the window procedure, not posted in the message queue. Most (but not all) of the mouse messages are posted to the queue. The keywords here are "posted" and "sent" (see PostMessage and SendMessage resp.). Only posted messages will show up in your PreFilterMessage routine /claes "Rickard" <rniocskpaarmd@enfofsspyasm.se> wrote in message news:ufg34u6tGHA.4544@TK2MSFTNGP04.phx.gbl... > 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 > ------------------------------------------------------------------ |
|
|
|
#4 |
|
Guest
Posts: n/a
|
Rickard,
PreFilterMessage filters messages that comes through the application message queue in other words they are posted rather than sent. There are not a lot of messages like this. Besically these are messages from the mouse, keyboard and few others. On the other hand the WndProc is the target for all messages, so you are going to receive them all there. You can use the Spy++ tool to spy on all messages send or posted to an application. For all messages in the log there there is a mark if the message has been sent or posted. If I remember correctly posted messages are marked with P and sent send with S. Only messages marked with P can be filtered in PreFilterMessage. -- Stoitcho Goutsev (100) "Rickard" <rniocskpaarmd@enfofsspyasm.se> wrote in message news:eUEdZi7tGHA.4752@TK2MSFTNGP02.phx.gbl... >I wrote a simple app that logged all messages. Here is the result. It > seems there is quite a lot of messages not handled by PreFilterMessage. > > > (0x00ae): WndProc, NOT PreFilterMessage > (0x0118): PreFilterMessage, NOT WndProc > (0xc136): WndProc, NOT PreFilterMessage > WM_ACTIVATE: WndProc, NOT PreFilterMessage > WM_ACTIVATEAPP: WndProc, NOT PreFilterMessage > WM_CAPTURECHANGED: WndProc, NOT PreFilterMessage > WM_CHANGEUISTATE: WndProc, NOT PreFilterMessage > WM_CREATE: WndProc, NOT PreFilterMessage > WM_CTLCOLORBTN: WndProc, NOT PreFilterMessage > WM_CTLCOLORLISTBOX: WndProc, NOT PreFilterMessage > WM_DRAWITEM: WndProc, NOT PreFilterMessage > WM_ENTERSIZEMOVE: WndProc, NOT PreFilterMessage > WM_ERASEBKGND: WndProc, NOT PreFilterMessage > WM_EXITSIZEMOVE: WndProc, NOT PreFilterMessage > WM_GETICON: WndProc, NOT PreFilterMessage > WM_GETMINMAXINFO: WndProc, NOT PreFilterMessage > WM_GETTEXT: WndProc, NOT PreFilterMessage > WM_GETTEXTLENGTH: WndProc, NOT PreFilterMessage > WM_MOUSEACTIVATE: WndProc, NOT PreFilterMessage > WM_MOVE: WndProc, NOT PreFilterMessage > WM_NCACTIVATE: WndProc, NOT PreFilterMessage > WM_NCCALCSIZE: WndProc, NOT PreFilterMessage > WM_NCCREATE: WndProc, NOT PreFilterMessage > WM_NCHITTEST: WndProc, NOT PreFilterMessage > WM_NCPAINT: WndProc, NOT PreFilterMessage > WM_NOTIFYFORMAT: WndProc, NOT PreFilterMessage > WM_PARENTNOTIFY: WndProc, NOT PreFilterMessage > WM_PRINTCLIENT: WndProc, NOT PreFilterMessage > WM_QUERYUISTATE: WndProc, NOT PreFilterMessage > WM_SETCURSOR: WndProc, NOT PreFilterMessage > WM_SETICON: WndProc, NOT PreFilterMessage > WM_SETTEXT: WndProc, NOT PreFilterMessage > WM_SHOWWINDOW: WndProc, NOT PreFilterMessage > WM_SIZE: WndProc, NOT PreFilterMessage > WM_SIZING: WndProc, NOT PreFilterMessage > WM_STYLECHANGED: WndProc, NOT PreFilterMessage > WM_STYLECHANGING: WndProc, NOT PreFilterMessage > WM_SYNCPAINT: WndProc, NOT PreFilterMessage > WM_SYSCOMMAND: WndProc, NOT PreFilterMessage > WM_UPDATEUISTATE: WndProc, NOT PreFilterMessage > WM_WINDOWPOSCHANGED: WndProc, NOT PreFilterMessage > WM_WINDOWPOSCHANGING: WndProc, NOT PreFilterMessage |
|
![]() |
|
| Thread Tools | |
| Rate This Thread | |
|
|

Main Page 

