Article ID: 170570 - Last Review: June 29, 2004 - Revision: 2.3 How To Build a Windows Message Handler with AddressOf in Visual Basic
This article was previously published under Q170570 On This PageSUMMARY
This article demonstrates how to build a Windows message handler in Visual Basic. It traps the right-click message and replaces the default context menu with a custom built one.
MORE INFORMATION
Prior to the release of Visual Basic 5.0, many developers used third-party
Windows message-handling tools or developed their own with tools such as
Microsoft Visual C++. With the addition of the AddressOf function to Visual
Basic 5.0 and higher, developers can now create their own Windows message
handling routines within their Visual Basic applications.
For example, when a user right-clicks on a textbox in Windows 95, Windows 98, Windows Me, Windows NT 4.0 or Windows 2000, the operating system automatically displays a default context menu. This default behavior occurs before the Visual Basic application fires the MouseUp event. Without the use of a Windows message handler, there is no way to replace the default context menu with a custom built context menu. The following code shows how to build a Windows message handler to trap and discard the right-click message and to replace the default context menu with a custom built one. WARNING: Using AddressOf may cause unpredictable results if you don't completely understand the concept of function callbacks. You must understand how the basic portion of the callback works, and also the code of the DLL into which you are passing your function address. Debugging such interactions is difficult because the program runs in the same process as the development environment. In some cases, systematic debugging may not be possible. See details in the REFERENCES section of this article for more information. Step-by-Step Example
REFERENCES
If you are not familiar with the use of callbacks, then the following references may help:
"Dan Appleman's Visual Basic Programmer's Guide to the Win32 API" by Dan Appleman Platform Software Development Kit (SDK) Online Help (http://www.microsoft.com/msdownload/platformsdk/sdkupdate/downlevel.htm) (c) Microsoft Corporation 1997, All Rights Reserved. Contributions by David Sceppa, Microsoft Corporation APPLIES TO
| Other Resources Other Support Sites
CommunityGet Help NowArticle Translations |






Windows Live
Facebook
Twitter
Linkedin
Digg it
Yahoo
Delicious
StumbleUpon
Yammer
Reddit
Technorati
FriendFeed
Email
Back to the top
