Main Page   Modules   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

CmnHdr.h

00001 /******************************************************************************
00002 Module:  CmnHdr.h
00003 Notices: Copyright (c) 2000 Jeffrey Richter
00004 Purpose: Common header file containing handy macros and definitions
00005          used throughout all the applications in the book.
00006          See Appendix A.
00007 ******************************************************************************/
00008 
00009 
00010 #pragma once   // Include this header file once per compilation unit
00011 
00012 /* James - comment out
00014 
00015 
00016 #define _WIN32_WINNT 0x0500
00017 //#define WINVER       0x0500
00018 
00019 
00021 
00022 
00023 // If we are not compiling for an x86 CPU, we always compile using Unicode.
00024 #ifndef _M_IX86
00025 #define UNICODE
00026 #endif
00027 
00028 // To compile using Unicode on the x86 CPU, uncomment the line below.
00029 //#define UNICODE
00030 
00031 // When using Unicode Windows functions, use Unicode C-Runtime functions too.
00032 #ifdef UNICODE
00033 #define _UNICODE
00034 #endif
00035 
00036 
00038 
00039 
00040 #pragma warning(push, 3)
00041 #include <Windows.h>
00042 #pragma warning(pop) 
00043 #pragma warning(push, 4)
00044 
00045 
00047 
00048 
00049 #ifndef WT_EXECUTEINPERSISTENTIOTHREAD
00050 #pragma message("You are not using the latest Platform SDK header/library ")
00051 #pragma message("files. This may prevent the project from building correctly.")
00052 #endif
00053 
00054 
00056 
00057 
00058 // nonstandard extension 'single line comment' was used
00059 #pragma warning(disable:4001)
00060 
00061 // unreferenced formal parameter
00062 #pragma warning(disable:4100)
00063 
00064 // Note: Creating precompiled header 
00065 #pragma warning(disable:4699)
00066 
00067 // function not inlined
00068 #pragma warning(disable:4710)
00069 
00070 // unreferenced inline function has been removed
00071 #pragma warning(disable:4514)
00072 
00073 // assignment operator could not be generated
00074 #pragma warning(disable:4512)
00075 //James - end of comment out */ 
00076 
00078 
00079 
00080 /* 
00081 When the compiler sees a line like this:
00082    #pragma chMSG(Fix this later)
00083 
00084 it outputs a line like this:
00085 
00086   c:\CD\CmnHdr.h(82):Fix this later
00087 
00088 You can easily jump directly to this line and examine the surrounding code.
00089 */
00090 
00091 #define chSTR2(x)      #x
00092 #define chSTR(x)    chSTR2(x)
00093 #define chMSG(desc) message(__FILE__ "(" chSTR(__LINE__) "):" #desc)
00094 
00095 
00097 
00098 
00099 // This macro returns TRUE if a number is between two others
00100 #define chINRANGE(low, Num, High) (((low) <= (Num)) && ((Num) <= (High)))
00101 
00102 
00104 
00105 
00106 // This macro evaluates to the number of elements in an array. 
00107 #define chDIMOF(Array) (sizeof(Array) / sizeof(Array[0]))
00108 
00109 
00111 
00112 
00113 // This macro function calls the C runtime's _beginthreadex function. 
00114 // The C runtime library doesn't want to have any reliance on Windows' data 
00115 // types such as HANDLE. This means that a Windows programmer needs to cast
00116 // values when using _beginthreadex. Since this is terribly inconvenient, 
00117 // I created this macro to perform the casting.
00118 typedef unsigned (__stdcall *PTHREAD_START) (void *);
00119 
00120 #define chBEGINTHREADEX(psa, cbStack, pfnStartAddr, \
00121    pvParam, fdwCreate, pdwThreadId)                 \
00122       ((HANDLE)_beginthreadex(                      \
00123          (void *)        (psa),                     \
00124          (unsigned)      (cbStack),                 \
00125          (PTHREAD_START) (pfnStartAddr),            \
00126          (void *)        (pvParam),                 \
00127          (unsigned)      (fdwCreate),               \
00128          (unsigned *)    (pdwThreadId)))
00129 
00130 
00132 
00133 
00134 #ifdef _X86_
00135 #define DebugBreak()    _asm { int 3 }
00136 #endif
00137 
00138 
00140 
00141 
00142 // Useful macro for creating your own software exception codes
00143 #define MAKESOFTWAREEXCEPTION(Severity, Facility, Exception) \
00144    ((DWORD) ( \
00145    /* Severity code    */  (Severity       ) |     \
00146    /* MS(0) or Cust(1) */  (1         << 29) |     \
00147    /* Reserved(0)      */  (0         << 28) |     \
00148    /* Facility code    */  (Facility  << 16) |     \
00149    /* Exception code   */  (Exception <<  0)))
00150 
00151 
00153 
00154 
00155 inline void chMB(PCSTR s) {
00156    char szTMP[128];
00157    GetModuleFileNameA(NULL, szTMP, chDIMOF(szTMP));
00158    MessageBoxA(GetActiveWindow(), s, szTMP, MB_OK);
00159 }
00160 
00161 
00163 
00164 
00165 inline void chFAIL(PSTR szMsg) {
00166    chMB(szMsg);
00167    DebugBreak();
00168 }
00169 
00170 
00171 // Put up an assertion failure message box.
00172 inline void chASSERTFAIL(LPCSTR file, int line, PCSTR expr) {
00173    char sz[128];
00174    wsprintfA(sz, "File %s, line %d : %s", file, line, expr);
00175    chFAIL(sz);
00176 }
00177 
00178 
00179 // Put up a message box if an assertion fails in a debug build.
00180 #ifdef _DEBUG
00181 #define chASSERT(x) if (!(x)) chASSERTFAIL(__FILE__, __LINE__, #x)
00182 #else
00183 #define chASSERT(x)
00184 #endif
00185 
00186 
00187 // Assert in debug builds, but don't remove the code in retail builds.
00188 #ifdef _DEBUG
00189 #define chVERIFY(x) chASSERT(x)
00190 #else
00191 #define chVERIFY(x) (x)
00192 #endif
00193 
00194 
00196 
00197 
00198 // The normal HANDLE_MSG macro in WindowsX.h does not work properly for dialog
00199 // boxes because DlgProc return a BOOL instead of an LRESULT (like
00200 // WndProcs). This chHANDLE_DLGMSG macro corrects the problem:
00201 #define chHANDLE_DLGMSG(hwnd, message, fn)                 \
00202    case (message): return (SetDlgMsgResult(hwnd, uMsg,     \
00203       HANDLE_##message((hwnd), (wParam), (lParam), (fn))))
00204 
00205 
00207 
00208 
00209 // Sets the dialog box icons
00210 inline void chSETDLGICONS(HWND hwnd, int idi) {
00211    SendMessage(hwnd, WM_SETICON, TRUE,  (LPARAM) 
00212       LoadIcon((HINSTANCE) GetWindowLongPtr(hwnd, GWLP_HINSTANCE), 
00213          MAKEINTRESOURCE(idi)));
00214    SendMessage(hwnd, WM_SETICON, FALSE, (LPARAM) 
00215       LoadIcon((HINSTANCE) GetWindowLongPtr(hwnd, GWLP_HINSTANCE), 
00216       MAKEINTRESOURCE(idi)));
00217 }
00218     
00219 
00221 
00222 
00223 inline void chWindows9xNotAllowed() {
00224    OSVERSIONINFO vi = { sizeof(vi) };
00225    GetVersionEx(&vi);
00226    if (vi.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS) {
00227       chMB("This application requires features not present in Windows 9x.");
00228       ExitProcess(0);
00229    }
00230 }
00231 
00232 
00233 inline void chWindows2000Required() {
00234    OSVERSIONINFO vi = { sizeof(vi) };
00235    GetVersionEx(&vi);
00236    if ((vi.dwPlatformId != VER_PLATFORM_WIN32_NT) && (vi.dwMajorVersion < 5)) {
00237       chMB("This application requires features present in Windows 2000.");
00238       ExitProcess(0);
00239    }
00240 }
00241 
00242 
00244 
00245 
00246 // Since Windows 98 does not support Unicode, issue an error and terminate
00247 // the process if this is a native Unicode build running on Windows 98
00248 
00249 // This is accomplished by creating a global C++ object. Its constructor is 
00250 // executed before WinMain.
00251 
00252 #ifdef UNICODE
00253 
00254 class CUnicodeSupported {
00255 public:
00256    CUnicodeSupported() {
00257       if (GetWindowsDirectoryW(NULL, 0) <= 0) {
00258          chMB("This application requires an OS that supports Unicode.");
00259          ExitProcess(0);
00260       }
00261    }
00262 };
00263 
00264 // "static" stops the linker from complaining that multiple instances of the
00265 // object exist when a single project contains multiple source files.
00266 static CUnicodeSupported g_UnicodeSupported;
00267 
00268 #endif
00269 
00270 
00272 
00273 
00274 #pragma comment(linker, "/subsystem:Windows")
00275 
00276 

Generated on Mon Mar 25 06:29:58 2002 for Window Dressing by doxygen1.2.13.1 written by Dimitri van Heesch, © 1997-2001