Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleList distinct messages received by a form in Visual Basic 2005
DescriptionThis example shows how to list distinct messages received by a form in Visual Basic 2005.
KeywordsWndProc, messages, list messages, VB2005
CategoriesVB.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
 
 
Copyright © 1997-2006 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated