home *** CD-ROM | disk | FTP | other *** search
/ DOS/V Power Report 2000 June / VPR0006A.BIN / PROGRAM / OPENAPP / WIN95ADG.H < prev   
C/C++ Source or Header  |  1996-11-13  |  10KB  |  270 lines

  1. /******************************************************************************
  2. Module name: Win95ADG.h
  3. Written by: Jeffrey Richter and Jonathan Locke
  4. Notices: Copyright (c) 1995 Jeffrey Richter
  5. Purpose: Common header file for "Windows 95: A Developer's Guide"
  6.          Contains handy macros and definitions used throughout
  7.          the applications.
  8. ******************************************************************************/
  9.  
  10. #define _X86_
  11.  
  12. /* Disable ridiculous warnings so that the code */
  13. /* compiles cleanly using warning level 4.      */
  14.  
  15. /* nonstandard extension 'single line comment' was used */
  16. #pragma warning(disable: 4001)
  17.  
  18. // nonstandard extension used : nameless struct/union
  19. #pragma warning(disable: 4201)
  20.  
  21. // nonstandard extension used : bit field types other than int
  22. #pragma warning(disable: 4214)
  23.  
  24. // Note: Creating precompiled header 
  25. #pragma warning(disable: 4699)
  26.  
  27. // unreferenced inline function has been removed
  28. #pragma warning(disable: 4514)
  29.  
  30. // unreferenced formal parameter
  31. #pragma warning(disable: 4100)
  32.  
  33. // indirection to slightly different base types
  34. #pragma warning(disable: 4057)
  35.  
  36. // named type definition in parentheses
  37. #pragma warning(disable: 4115)
  38.  
  39. // nonstandard extension used : benign typedef redefinition
  40. #pragma warning(disable: 4209)
  41.  
  42.  
  43. //////////////////////// Windows Version Build Option /////////////////////////
  44.  
  45.  
  46. #define WINVER 0x0400
  47.  
  48.  
  49. ////////////////////////// Application Build Option ///////////////////////////
  50.  
  51.  
  52. // Force all EXEs/DLLs to be built for Windows 4.0. Comment out the following
  53. // #pragma line to create applications that run under Windows NT 3.1 or Win32s.
  54. // NOTE: Windows NT 3.5 and 3.51 run Win32 programs marked as 4.0.
  55. #pragma comment(lib, "kernel32 " "-subsystem:Windows,4.0 ")
  56.  
  57.  
  58. ///////////////////////////// STRICT Build Option /////////////////////////////
  59.  
  60.  
  61. // Force all EXEs/DLLs to use STRICT type checking.
  62. #define STRICT
  63.  
  64.  
  65. /////////////////////////// CPU Portability Macros ////////////////////////////
  66.  
  67.  
  68. // If no CPU platform was specified, default to the current platform.
  69. #if !defined(_PPC_) && !defined(_ALPHA_) && !defined(_MIPS_) && !defined(_X86_)
  70.    #if defined(_M_IX86)
  71.       #define _X86_
  72.    #endif
  73.    #if defined(_M_MRX000)
  74.       #define _MIPS_
  75.    #endif
  76.    #if defined(_M_ALPHA)
  77.       #define _ALPHA_
  78.    #endif
  79.    #if defined(_M_PPC)
  80.       #define _PPC_
  81.    #endif
  82. #endif
  83.  
  84. #if defined(_DEBUG)
  85.    #define adgLIBBUILDTYPE "Dbg_"
  86. #else
  87.    #define adgLIBBUILDTYPE "Rel_"
  88. #endif
  89.  
  90. #if defined(_X86_)
  91.    #define adgLIBCPUTYPE "x86"
  92. #elif defined(_MIPS_)
  93.    #define adgLIBCPUTYPE "MIPS"
  94. #elif defined(_ALPHA_)
  95.    #define adgLIBCPUTYPE "Alph"
  96. #elif defined(_PPC_)
  97.    #define adgLIBCPUTYPE "PPC"
  98. #else
  99.    #error Win95ADG.h : Unknown CPU platform.
  100. #endif
  101.  
  102.  
  103. //////////////////////////// Unicode Build Option /////////////////////////////
  104.  
  105.  
  106. // If we are not compiling for an x86 CPU, we always compile using Unicode.
  107. #ifndef _X86_
  108. #define UNICODE
  109. #endif
  110.  
  111.  
  112. // To compile using Unicode on the x86 CPU, uncomment the line below.
  113. //#define UNICODE
  114.  
  115. // When using Unicode Win32 functions, use Unicode C-Runtime functions too.
  116. #ifdef UNICODE
  117. #define _UNICODE
  118. #endif
  119.  
  120.  
  121. ///////////////////////////// adgARRAY_SIZE Macro /////////////////////////////
  122.  
  123.  
  124. // This macro evaluates to the number of elements in an array. 
  125. #define adgARRAY_SIZE(Array) (sizeof(Array) / sizeof((Array)[0]))
  126.  
  127.  
  128. /////////////////////////////// adgINRANGE Macro //////////////////////////////
  129.  
  130.  
  131. // This macro evaluates to TRUE if val is between lo and hi inclusive.
  132. #define adgINRANGE(lo, val, hi) (((lo) <= (val)) && ((val) <= (hi)))
  133.  
  134.  
  135. //////////////////////////// Assert/Verify Macros /////////////////////////////
  136.  
  137.  
  138. #define adgFAIL(szMSG) {                                                  \
  139.       MessageBox(GetActiveWindow(), szMSG,                                \
  140.          __TEXT("Assertion Failed"), MB_OK | MB_ICONERROR);               \
  141.       DebugBreak();                                                       \
  142.    }
  143.  
  144. // Put up an assertion failure message box
  145. #define adgASSERTFAIL(file,line,expr) {                                   \
  146.       TCHAR sz[128];                                                      \
  147.       wsprintf(sz, __TEXT("File %hs, line %d : %hs"), file, line, expr);  \
  148.       adgFAIL(sz);                                                        \
  149.    }
  150.  
  151. // Put up a message box if an assertion fails in a debug build
  152. #ifdef _DEBUG
  153. #define adgASSERT(x) if (!(x)) adgASSERTFAIL(__FILE__, __LINE__, #x)
  154. #else
  155. #define adgASSERT(x)
  156. #endif
  157.  
  158. // Assert in debug builds, but don't remove the code in retail builds
  159. #ifdef _DEBUG
  160. #define adgVERIFY(x) adgASSERT(x)
  161. #else
  162. #define adgVERIFY(x) (x)
  163. #endif
  164.  
  165.  
  166. /////////////////////////// adgHANDLE_DLGMSG Macro ////////////////////////////
  167.  
  168.  
  169. // The normal HANDLE_MSG macro in WINDOWSX.H does not work properly for dialog
  170. // boxes because DlgProc's return a BOOL instead of an LRESULT (like
  171. // WndProcs). This adgHANDLE_DLGMSG macro corrects the problem:
  172. #define adgHANDLE_DLGMSG(hwnd, message, fn)                          \
  173.    case (message): return (SetDlgMsgResult(hwnd, uMsg,               \
  174.       HANDLE_##message((hwnd), (wParam), (lParam), (fn))))
  175.  
  176.  
  177. ////////////////////////// Window Extra Byte Macros ///////////////////////////
  178.  
  179.  
  180. // Macros to compute the size and offset of structure members
  181. #define adgMEMBEROFFSET(structure, member) (int) (&(((structure *)0)->member))
  182.  
  183. // Macros to compute offsets and get/set window values based on the layout of
  184. // a structure.
  185. #define adgSETWINDOWWORD(hwnd, structure, member, value) \
  186.    SetWindowWord(hwnd, adgMEMBEROFFSET(structure, member), (WORD) (value))
  187. #define adgSETWINDOWLONG(hwnd, structure, member, value) \
  188.    SetWindowLong(hwnd, adgMEMBEROFFSET(structure, member), (LONG) (value))
  189. #define adgGETWINDOWWORD(hwnd, structure, member) \
  190.    GetWindowWord(hwnd, adgMEMBEROFFSET(structure, member))
  191. #define adgGETWINDOWLONG(hwnd, structure, member) \
  192.    GetWindowLong(hwnd, adgMEMBEROFFSET(structure, member))
  193.  
  194.  
  195. /////////////////////////// Quick MessageBox Macro ////////////////////////////
  196.  
  197.  
  198. #define adgMB(s) {                                                   \
  199.       TCHAR szTMP[128];                                              \
  200.       GetModuleFileName(NULL, szTMP, adgARRAY_SIZE(szTMP));          \
  201.       MessageBox(GetActiveWindow(), s, szTMP, MB_OK);                \
  202.    }
  203.  
  204.  
  205. ///////////////////////////// Zero Variable Macro /////////////////////////////
  206.  
  207.  
  208. // Zero out a structure. If fInitSize is TRUE then initialize the first int to
  209. // the size of the structure. Many structures like WNDCLASSEX and STARTUPINFO
  210. // require that their first member be set to the size of the structure itself.
  211. #define adgINITSTRUCT(structure, fInitSize)                          \
  212.    (ZeroMemory(&(structure), sizeof(structure)),                     \
  213.    fInitSize ? (*(int*) &(structure) = sizeof(structure)) : 0)
  214.  
  215.  
  216. //////////////////////// Dialog Box Icon Setting Macro ////////////////////////
  217.  
  218.  
  219. // The call to SetClassLong is for Windows NT 3.51 or less.  The WM_SETICON
  220. // messages are for Windows 95 and future versions of NT.
  221. #define adgSETDLGICONS(hwnd, idiLarge, idiSmall)                              \
  222.    {                                                                          \
  223.       OSVERSIONINFO VerInfo;                                                  \
  224.       adgINITSTRUCT(VerInfo, TRUE);                                           \
  225.       GetVersionEx(&VerInfo);                                                 \
  226.       if ((VerInfo.dwPlatformId == VER_PLATFORM_WIN32_NT) &&                  \
  227.           (VerInfo.dwMajorVersion <= 3 && VerInfo.dwMinorVersion <= 51)) {    \
  228.          SetClassLong(hwnd, GCL_HICON, (LONG)                                 \
  229.             LoadIcon(GetWindowInstance(hwnd), MAKEINTRESOURCE(idiLarge)));    \
  230.       } else {                                                                \
  231.          SendMessage(hwnd, WM_SETICON, TRUE,  (LPARAM)                        \
  232.             LoadIcon(GetWindowInstance(hwnd), MAKEINTRESOURCE(idiLarge)));    \
  233.          SendMessage(hwnd, WM_SETICON, FALSE, (LPARAM)                        \
  234.             LoadIcon(GetWindowInstance(hwnd), MAKEINTRESOURCE(idiSmall)));    \
  235.       }                                                                       \
  236.    }
  237.     
  238.  
  239. ///////////////////////////// UNICODE Check Macro /////////////////////////////
  240.  
  241.  
  242. #ifdef UNICODE
  243.  
  244. #define adgWARNIFUNICODEUNDERWIN95()                                       \
  245.    if (GetWindowsDirectoryW(NULL, 0) <= 0)                                 \
  246.       MessageBoxA(NULL, "This operating system doesn't support Unicode.",  \
  247.          NULL, MB_OK)
  248.  
  249. #else
  250.  
  251. #define adgWARNIFUNICODEUNDERWIN95()
  252.  
  253. #endif
  254.  
  255.  
  256. ////////////////// WM_CAPTURECHANGED Message Cracker Macros ///////////////////
  257.  
  258.  
  259. // I have defined message cracker macros for the WM_CAPTURECHANGED message
  260. // because Microsoft did not do this in the WINDOWSX.H header file.
  261.  
  262. /* void Cls_OnCaptureChanged(HWND hwnd, HWND hwndNewCapture) */
  263. #define HANDLE_WM_CAPTURECHANGED(hwnd, wParam, lParam, fn) \
  264.     ((fn)((hwnd), (HWND)(lParam)), 0L)
  265. #define FORWARD_WM_CAPTURECHANGED(hwnd, hwndNewCapture, fn) \
  266.     (void)(fn)((hwnd), WM_CAPTURECHANGED, (WPARAM)(HWND)(hwndNewCapture), 0L)
  267.  
  268.  
  269. ///////////////////////////////// End of File /////////////////////////////////
  270.