Appendix B -- Message Crackers, Child Control Macros, and API Macros

[Previous] [Next]

When I go to conferences, I frequently ask people if they're using message crackers, and the response is usually "no." When I probe further, I discover that they don't know what message crackers do or even what they are. By using C/C++ with message crackers to present the sample code in this book, I get to introduce these little-known but useful macros to many people who might not know about them.

Message crackers are in the WindowsX.h file supplied with Microsoft Visual C++. You usually include this file immediately after the Windows.h file. The WindowsX.h file is nothing more than a bunch of #define directives that create a set of macros for you to use. The macros in WindowsX.h are actually divided into three groups: message crackers, child control macros, and API macros. These macros help you in the following ways:

  • They reduce the amount of casting you need to do in an application and make the casting that is required error-free. One of the big problems with programming for Windows in C/C++ has been the amount of casting required. You hardly ever see a call to a Windows function that doesn't require some sort of cast. You should avoid casts because they prevent the compiler from catching potential errors in your code. A cast tells the compiler, "I know I'm passing the wrong type here, but that's OK; I know what I'm doing." When you do a lot of casting, it's easy to make a mistake. The compiler should do as much work as possible to help out.
  • They make your code more readable.
  • They simplify porting between 16-bit Windows, 32-bit Windows, and 64-bit Windows.
  • They're easy to understand. (They're just macros, after all.)
  • They're easy to incorporate into existing code. You can leave old code alone and immediately use the macros in new code. You don't have to retrofit an entire application.
  • You can use them in C and C++ code, although they're not necessary if you're using a C++ class library.
  • If you need a feature that the macros don't support, you can easily write your own macros based on the ones in the header file.
  • You don't need to reference or remember obscure Windows constructs. For example, many functions in Windows expect a long parameter where the value in the long's high-word means one thing and the value in its low-word means something else. Before calling these functions, you must construct a long value out of the two individual values. You usually do this by using the MAKELONG macro from WinDef.h. But I can't tell you how many times I've accidentally reversed the two values, causing an incorrect value to be passed to a function. The macros in WindowsX.h come to the rescue.


Programming Applications for Microsoft Windows
Programming Applications for Microsoft Windows (Microsoft Programming Series)
ISBN: 1572319968
EAN: 2147483647
Year: 1999
Pages: 193

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net