|
|
Title | List distinct messages received by a form in Visual Basic 2005 |
Description | This example shows how to list distinct messages received by a form in Visual Basic 2005. |
Keywords | WndProc, messages, list messages, VB2005 |
Categories | VB.NET, API |
|
|
In Visual Basic .NET it's not too hard to override a class's WndProc function to see what messages an object receives. Unfortunately many objects such as forms receive hundreds or thousands of messages so it's hard to find what you're interested in the flood.
This example overcomes this problem by making a static dictionary and keeping track of the distinct kinds of messages it has seen. When it encounters a message that it has not seen before, it adds the message to its dictionary and displays information about the message in the Immediate window.
|
|
Protected Overrides Sub WndProc(ByRef m As _
System.Windows.Forms.Message)
MyBase.WndProc(m)
' See if we've seen this message before.
Static messages As New Dictionary(Of Integer, Message)
If Not messages.ContainsKey(m.Msg) Then
messages.Add(m.Msg, m)
Debug.WriteLine(m.ToString)
End If
End Sub
|
|
|
|
|
|