API Macros

[Previous] [Next]

The API macros simplify certain common operations, such as creating a new font, selecting the font into a device context, and saving the handle of the original font. The code looks something like this:

 HFONT hfontOrig = (HFONT) SelectObject(hdc, (HGDIOBJ) hfontNew); 

This statement requires two casts to get a warning-free compilation. One of the macros in WindowsX.h was designed for exactly this purpose:

 #define SelectFont(hdc, hfont) \ ((HFONT) SelectObject( (hdc), (HGDIOBJ) (HFONT) (hfont))) 

If you use this macro, the line of code in your program becomes the following:

 HFONT hfontOrig = SelectFont(hdc, hfontNew); 

This code is easier to read and is much less error-prone.

Several other API macros in WindowsX.h help with common Windows tasks. I urge you to examine them and use them.



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