00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #pragma once // Include this header file once per compilation unit
00011
00012
00014
00015
00016
00017
00018
00019
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00038
00039
00040
00041
00042
00043
00044
00045
00047
00048
00049
00050
00051
00052
00053
00054
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
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
00100 #define chINRANGE(low, Num, High) (((low) <= (Num)) && ((Num) <= (High)))
00101
00102
00104
00105
00106
00107 #define chDIMOF(Array) (sizeof(Array) / sizeof(Array[0]))
00108
00109
00111
00112
00113
00114
00115
00116
00117
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
00143 #define MAKESOFTWAREEXCEPTION(Severity, Facility, Exception) \
00144 ((DWORD) ( \
00145 (Severity ) | \
00146 (1 << 29) | \
00147 (0 << 28) | \
00148 (Facility << 16) | \
00149 (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
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
00180 #ifdef _DEBUG
00181 #define chASSERT(x) if (!(x)) chASSERTFAIL(__FILE__, __LINE__, #x)
00182 #else
00183 #define chASSERT(x)
00184 #endif
00185
00186
00187
00188 #ifdef _DEBUG
00189 #define chVERIFY(x) chASSERT(x)
00190 #else
00191 #define chVERIFY(x) (x)
00192 #endif
00193
00194
00196
00197
00198
00199
00200
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
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
00247
00248
00249
00250
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
00265
00266 static CUnicodeSupported g_UnicodeSupported;
00267
00268 #endif
00269
00270
00272
00273
00274 #pragma comment(linker, "/subsystem:Windows")
00275
00276