00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #pragma once
00014
00015 #include "utilexp.h"
00016 #include "strbasic.h"
00017 #include "BuildWarnings.h"
00018 #include <wtypes.h>
00019 #include <cmath>
00020 #include <cstdlib>
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052 template<typename DataPtr> DataPtr DLGetWindowLongPtr(HWND hWnd, int n = GWLP_USERDATA, DataPtr = NULL)
00053 {
00054 return (DataPtr)(static_cast<LONG_PTR>(::GetWindowLongPtr(hWnd, n)));
00055 }
00056
00057 template<typename DataPtr> DataPtr DLGetWindowLongPtr(HWND hWnd, DataPtr* pPtr, int n = GWLP_USERDATA)
00058 {
00059 *pPtr = DLGetWindowLongPtr<DataPtr>(hWnd, n);
00060
00061 return *pPtr;
00062 }
00063
00064 template<> inline bool DLGetWindowLongPtr(HWND hWnd, int n, bool)
00065 {
00066
00067
00068 return ::GetWindowLongPtr(hWnd, n) != 0;
00069 }
00070
00071 inline WNDPROC DLGetWindowProc(HWND hWnd)
00072 {
00073 return DLGetWindowLongPtr<WNDPROC>(hWnd, GWLP_WNDPROC);
00074 }
00075
00076 inline HINSTANCE DLGetWindowInstance(HWND hWnd)
00077 {
00078 return DLGetWindowLongPtr<HINSTANCE>(hWnd, GWLP_HINSTANCE);
00079 }
00080
00081
00082
00083
00084
00085 template<typename Type> inline Type DLSetWindowLongPtr(HWND hWnd, Type ptr, int n = GWLP_USERDATA)
00086 {
00087 #if !defined( _WIN64 )
00088
00089
00090 return (Type)(static_cast<LONG_PTR>(::SetWindowLongPtr(hWnd, n, (LONG)((LONG_PTR)(ptr)))));
00091 #else
00092 return (Type)(static_cast<LONG_PTR>(::SetWindowLongPtr(hWnd, n, (LONG_PTR)(ptr))));
00093 #endif
00094 }
00095
00096 template<> inline bool DLSetWindowLongPtr(HWND hWnd, bool bo, int n)
00097 {
00098
00099
00100 return ::SetWindowLongPtr(hWnd, n, bo) != 0;
00101 }
00102
00103 inline WNDPROC DLSetWindowLongPtr(HWND hWnd, WNDPROC pfn)
00104 {
00105 return DLSetWindowLongPtr<WNDPROC>(hWnd, pfn, GWLP_WNDPROC);
00106 }
00107
00108 inline WNDPROC DLSetWindowProc(HWND hWnd, WNDPROC pfn)
00109 {
00110 return DLSetWindowLongPtr<WNDPROC>(hWnd, pfn, GWLP_WNDPROC);
00111 }
00112
00113 #if !defined( _WIN64 )
00114 typedef INT_PTR (CALLBACK* DL_NOTQUITE_WNDPROC)(HWND, UINT, WPARAM, LPARAM);
00115 #endif
00116
00117
00118
00119
00120
00121 template<typename DataPtr> DataPtr DLGetClassLongPtr(HWND hWnd, int n, DataPtr = NULL)
00122 {
00123 return (DataPtr)(static_cast<LONG_PTR>(::GetClassLongPtr(hWnd, n)));
00124 }
00125
00126 template<typename DataPtr> DataPtr DLGetClassLongPtr(HWND hWnd, DataPtr* pPtr, int n)
00127 {
00128 *pPtr = DLGetClassLongPtr<DataPtr>(hWnd, n);
00129
00130 return *pPtr;
00131 }
00132
00133 template<> inline bool DLGetClassLongPtr(HWND hWnd, int n, bool)
00134 {
00135 return ::GetClassLongPtr(hWnd, n) != 0;
00136 }
00137
00138 inline WNDPROC DLGetClassWindowProc(HWND hWnd)
00139 {
00140 return DLGetClassLongPtr<WNDPROC>(hWnd, GCLP_WNDPROC);
00141 }
00142
00143 template<typename Type> inline Type DLSetClassLongPtr(HWND hWnd, Type ptr, int n)
00144 {
00145 #if !defined( _WIN64 )
00146
00147
00148 return (Type)(static_cast<LONG_PTR>(::SetClassLongPtr(hWnd, n, (LONG)((LONG_PTR)(ptr)))));
00149 #else
00150 return (Type)(static_cast<LONG_PTR>(::SetClassLongPtr(hWnd, n, (LONG_PTR)(ptr))));
00151 #endif
00152 }
00153
00154 template<> inline bool DLSetClassLongPtr(HWND hWnd, bool bo, int n)
00155 {
00156
00157
00158 return ::SetClassLongPtr(hWnd, n, bo) != 0;
00159 }
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190 UtilExport LONG DLRegSetString(HKEY key, const MCHAR* lpValue, const MCHAR* lpValueName = NULL);
00191 UtilExport LONG DLRegSetDWord(HKEY key, DWORD dw, const MCHAR* lpValueName = NULL);
00192
00193 template <typename BlobType> inline LONG DLRegSetBlob(HKEY key, const BlobType* lpbValue, DWORD n,
00194 LPCMSTR lpValueName = NULL)
00195 {
00196 return ::RegSetValueEx(key, lpValueName, 0, REG_BINARY,
00197 reinterpret_cast<LPBYTE>(const_cast<BlobType*>(lpbValue)),
00198 n * sizeof(BlobType));
00199 }
00200
00201
00202
00203
00204
00205 UtilExport BOOL DLGetTextExtent(HDC hDC, const MCHAR* text, LPSIZE lpExtent);
00206 UtilExport BOOL DLGetTextExtent(HDC hDC, const MCHAR* text, size_t len, LPSIZE lpExtent);
00207
00208
00209
00210
00211 UtilExport BOOL DLTextOut(HDC hDC, int x, int y, const MCHAR* text);
00212 UtilExport BOOL DLTextOut(HDC hDC, int x, int y, const MCHAR* text, size_t len);
00213 UtilExport LONG DLTabbedTextOut(HDC hDC, int x, int y, const MCHAR* text, int nTabs,
00214 const INT* pTabPositions, int nTabOrigin);
00215
00216 UtilExport int DLDrawText(HDC hDC, MCHAR* lpString, LPRECT lpRect, UINT uFormat);
00217 UtilExport int DLDrawText(HDC hDC, MCHAR* lpString, size_t len, LPRECT lpRect, UINT uFormat);
00218
00219
00220
00221
00222
00223
00224
00225
00226 #if defined( _WIN64 )
00227
00228 inline DWORD PointerHiPart(LONG_PTR ptr)
00229 {
00230 return static_cast<DWORD>((ptr >> 32) & 0xffffffff);
00231 }
00232
00233 inline DWORD PointerLoPart(LONG_PTR ptr)
00234 {
00235 return static_cast<DWORD>(ptr & 0xffffffff);
00236 }
00237
00238 inline DWORD PointerHiPart(ULONG_PTR ptr)
00239 {
00240 return static_cast<DWORD>(ptr >> 32);
00241 }
00242
00243 inline DWORD PointerLoPart(ULONG_PTR ptr)
00244 {
00245 return static_cast<DWORD>(ptr);
00246 }
00247
00248 inline DWORD PointerHiPart(void* ptr)
00249 {
00250 return PointerHiPart(reinterpret_cast<ULONG_PTR>(ptr));
00251 }
00252
00253 inline DWORD PointerLoPart(void* ptr)
00254 {
00255 return PointerLoPart(reinterpret_cast<ULONG_PTR>(ptr));
00256 }
00257
00258 #else
00259
00260 inline WORD PointerHiPart(ULONG_PTR ptr)
00261 {
00262 return static_cast<WORD>(ptr >> 16);
00263 }
00264
00265 inline WORD PointerLoPart(ULONG_PTR ptr)
00266 {
00267 return static_cast<WORD>(ptr);
00268 }
00269
00270 inline WORD PointerHiPart(LONG_PTR ptr)
00271 {
00272 return static_cast<WORD>((ptr >> 16) & 0xffff);
00273 }
00274
00275 inline WORD PointerLoPart(LONG_PTR ptr)
00276 {
00277 return static_cast<WORD>(ptr & 0xffff);
00278 }
00279
00280 inline WORD PointerHiPart(void* ptr)
00281 {
00282 return PointerHiPart(reinterpret_cast<ULONG_PTR>(ptr));
00283 }
00284
00285 inline WORD PointerLoPart(void* ptr)
00286 {
00287 return PointerLoPart(reinterpret_cast<ULONG_PTR>(ptr));
00288 }
00289
00290 #endif
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342 enum
00343 {
00344 FNV1_32_INIT = 0x811c9dc5,
00345 FNV_32_PRIME = 0x01000193
00346 };
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366 inline unsigned int fnv_32_buf(const void *buf, int len, unsigned int hval)
00367 {
00368 const unsigned char *bp = (const unsigned char *)buf;
00369 const unsigned char *be = bp + len;
00370
00371
00372
00373
00374 while (bp < be)
00375 {
00376
00377 hval *= FNV_32_PRIME;
00378
00379
00380 hval ^= (unsigned int)*bp++;
00381 }
00382
00383
00384 return hval;
00385 }
00386
00387
00388 template <typename T> inline unsigned int DLObjectHash(T& t, int HashTableSize = 0)
00389 {
00390
00391
00392
00393
00394
00395
00396 unsigned int hash = fnv_32_buf(&t, sizeof(t), (unsigned int)FNV1_32_INIT);
00397
00398 return HashTableSize ? hash % HashTableSize : hash;
00399 }
00400
00401 inline unsigned int DLPointerHash(const void* pv, int HashTableSize = 0)
00402 {
00403 return DLObjectHash(pv, HashTableSize);
00404 }
00405
00406
00407
00408
00409
00410
00411
00412
00413 inline int DL_abs(int n) { return std::abs(n); }
00414 inline __int64 DL_abs(__int64 n) { return (n < 0) ? -n : n; }
00415
00416 inline float DL_abs(float f) { return std::fabsf(f); }
00417 inline double DL_abs(double f) { return std::fabs(f); }
00418 inline long double DL_abs(long double f) { return std::fabsl(f); }
00419
00420
00421
00422
00423 #define DL_STDEXT stdext
00424
00425 #define DL_NON_RTTI_OBJECT std::__non_rtti_object
00426
00427
00428
00429
00430 #ifndef DL_TYPENAME_OUTSIDE_TEMPLATE
00431 #define DL_TYPENAME_OUTSIDE_TEMPLATE typename
00432 #endif
00433