3dsmaxdlport.h File Reference

#include "utilexp.h"
#include "strbasic.h"
#include "BuildWarnings.h"
#include <wtypes.h>
#include <cmath>
#include <cstdlib>

Macros

#define DL_STDEXT   stdext
 
#define DL_NON_RTTI_OBJECT   std::__non_rtti_object
 
#define DL_TYPENAME_OUTSIDE_TEMPLATE   typename
 

Typedefs

typedef INT_PTR(CALLBACK * DL_NOTQUITE_WNDPROC) (HWND, UINT, WPARAM, LPARAM)
 

Enumerations

enum  { FNV1_32_INIT = 0x811c9dc5, FNV_32_PRIME = 0x01000193 }
 

Functions

template<typename DataPtr >
DataPtr DLGetWindowLongPtr (HWND hWnd, int n=GWLP_USERDATA, DataPtr=NULL)
 
template<typename DataPtr >
DataPtr DLGetWindowLongPtrA (HWND hWnd, int n=GWLP_USERDATA)
 
template<typename DataPtr >
DataPtr DLGetWindowLongPtrW (HWND hWnd, int n=GWLP_USERDATA)
 
template<typename DataPtr >
DataPtr DLGetWindowLongPtr (HWND hWnd, DataPtr *pPtr, int n=GWLP_USERDATA)
 
template<>
bool DLGetWindowLongPtr (HWND hWnd, int n, bool)
 
WNDPROC DLGetWindowProc (HWND hWnd)
 
WNDPROC DLGetWindowProcA (HWND hWnd)
 
WNDPROC DLGetWindowProcW (HWND hWnd)
 
HINSTANCE DLGetWindowInstance (HWND hWnd)
 
template<typename Type >
Type DLSetWindowLongPtr (HWND hWnd, Type ptr, int n=GWLP_USERDATA)
 
template<>
bool DLSetWindowLongPtr (HWND hWnd, bool bo, int n)
 
WNDPROC DLSetWindowLongPtr (HWND hWnd, WNDPROC pfn)
 
WNDPROC DLSetWindowProc (HWND hWnd, WNDPROC pfn)
 
template<typename DataPtr >
DataPtr DLGetClassLongPtr (HWND hWnd, int n, DataPtr=NULL)
 
template<typename DataPtr >
DataPtr DLGetClassLongPtrA (HWND hWnd, int n)
 
template<typename DataPtr >
DataPtr DLGetClassLongPtrW (HWND hWnd, int n)
 
template<typename DataPtr >
DataPtr DLGetClassLongPtr (HWND hWnd, DataPtr *pPtr, int n)
 
template<>
bool DLGetClassLongPtr (HWND hWnd, int n, bool)
 
WNDPROC DLGetClassWindowProc (HWND hWnd)
 
WNDPROC DLGetClassWindowProcA (HWND hWnd)
 
WNDPROC DLGetClassWindowProcW (HWND hWnd)
 
template<typename Type >
Type DLSetClassLongPtr (HWND hWnd, Type ptr, int n)
 
template<>
bool DLSetClassLongPtr (HWND hWnd, bool bo, int n)
 
template<typename Type >
Type DLSetClassLongPtrA (HWND hWnd, Type ptr, int n)
 
template<typename Type >
Type DLSetClassLongPtrW (HWND hWnd, Type ptr, int n)
 
WNDPROC DLSetClassWindowProc (HWND hWnd, WNDPROC pfn)
 
WNDPROC DLSetClassWindowProcA (HWND hWnd, WNDPROC pfn)
 
WNDPROC DLSetClassWindowProcW (HWND hWnd, WNDPROC pfn)
 
UtilExport LONG DLRegSetString (HKEY key, const MCHAR *data, const MCHAR *name=NULL)
 Wrapper around the windows function RegSetValueEx. More...
 
UtilExport LONG DLRegSetDWord (HKEY key, DWORD data, const MCHAR *name=NULL)
 Wrapper around the windows function RegSetValueEx for DWORD data. More...
 
template<typename BlobType >
LONG DLRegSetBlob (HKEY key, const BlobType *lpbValue, DWORD n, LPCMSTR lpValueName=NULL)
 
UtilExport bool GetQtTextExtent (const MCHAR *text, SIZE &extent)
 Calculates the text extents using Qt. More...
 
UtilExport BOOL DLGetTextExtent (HDC hDC, const MCHAR *text, LPSIZE lpExtent, bool removeUIScaling=false, bool useQtTextWidth=true)
 
UtilExport BOOL DLGetTextExtent (HDC hDC, const MCHAR *text, size_t len, LPSIZE lpExtent, bool removeUIScaling=false, bool useQtTextWidth=true)
 
UtilExport BOOL DLTextOut (HDC hDC, int x, int y, const MCHAR *text)
 
UtilExport BOOL DLTextOut (HDC hDC, int x, int y, const MCHAR *text, size_t len)
 
UtilExport LONG DLTabbedTextOut (HDC hDC, int x, int y, const MCHAR *text, int nTabs, const INT *pTabPositions, int nTabOrigin)
 
UtilExport int DLDrawText (HDC hDC, const MCHAR *lpString, LPRECT lpRect, UINT uFormat)
 
UtilExport int DLDrawText (HDC hDC, const MCHAR *lpString, size_t len, LPRECT lpRect, UINT uFormat)
 
int DLGetSystemMetrics (int nIndex)
 Wrapper around the windows function GetSystemMetrics. More...
 
WORD PointerHiPart (ULONG_PTR ptr)
 
WORD PointerLoPart (ULONG_PTR ptr)
 
WORD PointerHiPart (LONG_PTR ptr)
 
WORD PointerLoPart (LONG_PTR ptr)
 
WORD PointerHiPart (void *ptr)
 
WORD PointerLoPart (void *ptr)
 
unsigned int fnv_32_buf (const void *buf, int len, unsigned int hval)
 
template<typename T >
unsigned int DLObjectHash (T &t, int HashTableSize=0)
 
unsigned int DLPointerHash (const void *pv, int HashTableSize=0)
 
int DL_abs (int n)
 
__int64 DL_abs (__int64 n)
 
float DL_abs (float f)
 
double DL_abs (double f)
 
long double DL_abs (long double f)
 

Macro Definition Documentation

#define DL_STDEXT   stdext
#define DL_NON_RTTI_OBJECT   std::__non_rtti_object
#define DL_TYPENAME_OUTSIDE_TEMPLATE   typename

Typedef Documentation

typedef INT_PTR(CALLBACK* DL_NOTQUITE_WNDPROC) (HWND, UINT, WPARAM, LPARAM)

Enumeration Type Documentation

anonymous enum
Enumerator
FNV1_32_INIT 
FNV_32_PRIME 
464 {
465  FNV1_32_INIT = 0x811c9dc5,
466  FNV_32_PRIME = 0x01000193
467 };
Definition: 3dsmaxdlport.h:465
Definition: 3dsmaxdlport.h:466

Function Documentation

DataPtr DLGetWindowLongPtr ( HWND  hWnd,
int  n = GWLP_USERDATA,
DataPtr  = NULL 
)
48 {
49  return (DataPtr)(static_cast<LONG_PTR>(::GetWindowLongPtr(hWnd, n)));
50 }
DataPtr DLGetWindowLongPtrA ( HWND  hWnd,
int  n = GWLP_USERDATA 
)
53 {
54  return (DataPtr)(static_cast<LONG_PTR>(::GetWindowLongPtrA(hWnd, n)));
55 }
DataPtr DLGetWindowLongPtrW ( HWND  hWnd,
int  n = GWLP_USERDATA 
)
58 {
59  return (DataPtr)(static_cast<LONG_PTR>(::GetWindowLongPtrW(hWnd, n)));
60 }
DataPtr DLGetWindowLongPtr ( HWND  hWnd,
DataPtr *  pPtr,
int  n = GWLP_USERDATA 
)
63 {
64  *pPtr = DLGetWindowLongPtr<DataPtr>(hWnd, n);
65 
66  return *pPtr;
67 }
bool DLGetWindowLongPtr ( HWND  hWnd,
int  n,
bool   
)
inline
70 {
71  // Specialize for bool so we can quietly deal
72  // warning C4800: 'LONG_PTR' : forcing value to bool 'true' or 'false' (performance warning)
73  return ::GetWindowLongPtr(hWnd, n) != 0;
74 }
WNDPROC DLGetWindowProc ( HWND  hWnd)
inline
77 {
78  return DLGetWindowLongPtr<WNDPROC>(hWnd, GWLP_WNDPROC);
79 }
WNDPROC DLGetWindowProcA ( HWND  hWnd)
inline
82 {
83  return DLGetWindowLongPtrA<WNDPROC>(hWnd, GWLP_WNDPROC);
84 }
WNDPROC DLGetWindowProcW ( HWND  hWnd)
inline
87 {
88  return DLGetWindowLongPtrW<WNDPROC>(hWnd, GWLP_WNDPROC);
89 }
HINSTANCE DLGetWindowInstance ( HWND  hWnd)
inline
92 {
93  return DLGetWindowLongPtr<HINSTANCE>(hWnd, GWLP_HINSTANCE);
94 }
Type DLSetWindowLongPtr ( HWND  hWnd,
Type  ptr,
int  n = GWLP_USERDATA 
)
inline
101 {
102 #if !defined( _WIN64 )
103  // SetWindowLongPtr() maps to SetWindowLong() in 32 bit land; react accordingly to keep
104  // the compiler happy, even with /Wp64.
105  return (Type)(static_cast<LONG_PTR>(::SetWindowLongPtr(hWnd, n, (LONG)((LONG_PTR)(ptr)))));
106 #else
107  return (Type)(static_cast<LONG_PTR>(::SetWindowLongPtr(hWnd, n, (LONG_PTR)(ptr))));
108 #endif
109 }
bool DLSetWindowLongPtr ( HWND  hWnd,
bool  bo,
int  n 
)
inline
112 {
113  // Specialize for bool so we can quietly deal
114  // warning C4800: 'LONG_PTR' : forcing value to bool 'true' or 'false' (performance warning)
115  return ::SetWindowLongPtr(hWnd, n, bo) != 0;
116 }
WNDPROC DLSetWindowLongPtr ( HWND  hWnd,
WNDPROC  pfn 
)
inline
119 {
120  return DLSetWindowLongPtr<WNDPROC>(hWnd, pfn, GWLP_WNDPROC);
121 }
WNDPROC DLSetWindowProc ( HWND  hWnd,
WNDPROC  pfn 
)
inline
124 {
125  return DLSetWindowLongPtr<WNDPROC>(hWnd, pfn, GWLP_WNDPROC);
126 }
DataPtr DLGetClassLongPtr ( HWND  hWnd,
int  n,
DataPtr  = NULL 
)
137 {
138  return (DataPtr)(static_cast<LONG_PTR>(::GetClassLongPtr(hWnd, n)));
139 }
DataPtr DLGetClassLongPtrA ( HWND  hWnd,
int  n 
)
142 {
143  return (DataPtr)(static_cast<LONG_PTR>(::GetClassLongPtrA(hWnd, n)));
144 }
DataPtr DLGetClassLongPtrW ( HWND  hWnd,
int  n 
)
147 {
148  return (DataPtr)(static_cast<LONG_PTR>(::GetClassLongPtrW(hWnd, n)));
149 }
DataPtr DLGetClassLongPtr ( HWND  hWnd,
DataPtr *  pPtr,
int  n 
)
152 {
153  *pPtr = DLGetClassLongPtr<DataPtr>(hWnd, n);
154 
155  return *pPtr;
156 }
bool DLGetClassLongPtr ( HWND  hWnd,
int  n,
bool   
)
inline
159 {
160  return ::GetClassLongPtr(hWnd, n) != 0;
161 }
WNDPROC DLGetClassWindowProc ( HWND  hWnd)
inline
164 {
165  return DLGetClassLongPtr<WNDPROC>(hWnd, GCLP_WNDPROC);
166 }
WNDPROC DLGetClassWindowProcA ( HWND  hWnd)
inline
169 {
170  return DLGetClassLongPtrA<WNDPROC>(hWnd, GCLP_WNDPROC);
171 }
WNDPROC DLGetClassWindowProcW ( HWND  hWnd)
inline
174 {
175  return DLGetClassLongPtrW<WNDPROC>(hWnd, GCLP_WNDPROC);
176 }
Type DLSetClassLongPtr ( HWND  hWnd,
Type  ptr,
int  n 
)
inline
179 {
180 #if !defined( _WIN64 )
181  // SetClassLongPtr() maps to SetClassLong() in 32 bit land; react accordingly to keep
182  // the compiler happy, even with /Wp64.
183  return (Type)(static_cast<LONG_PTR>(::SetClassLongPtr(hWnd, n, (LONG)((LONG_PTR)(ptr)))));
184 #else
185  return (Type)(static_cast<LONG_PTR>(::SetClassLongPtr(hWnd, n, (LONG_PTR)(ptr))));
186 #endif
187 }
bool DLSetClassLongPtr ( HWND  hWnd,
bool  bo,
int  n 
)
inline
190 {
191  // Specialize for bool so we can quietly deal
192  // warning C4800: 'LONG_PTR' : forcing value to bool 'true' or 'false' (performance warning)
193  return ::SetClassLongPtr(hWnd, n, bo) != 0;
194 }
Type DLSetClassLongPtrA ( HWND  hWnd,
Type  ptr,
int  n 
)
inline
197 {
198 #if !defined( _WIN64 )
199  // SetClassLongPtr() maps to SetClassLong() in 32 bit land; react accordingly to keep
200  // the compiler happy, even with /Wp64.
201  return (Type)(static_cast<LONG_PTR>(::SetClassLongPtrA(hWnd, n, (LONG)((LONG_PTR)(ptr)))));
202 #else
203  return (Type)(static_cast<LONG_PTR>(::SetClassLongPtrA(hWnd, n, (LONG_PTR)(ptr))));
204 #endif
205 }
Type DLSetClassLongPtrW ( HWND  hWnd,
Type  ptr,
int  n 
)
inline
208 {
209 #if !defined( _WIN64 )
210  // SetClassLongPtr() maps to SetClassLong() in 32 bit land; react accordingly to keep
211  // the compiler happy, even with /Wp64.
212  return (Type)(static_cast<LONG_PTR>(::SetClassLongPtrW(hWnd, n, (LONG)((LONG_PTR)(ptr)))));
213 #else
214  return (Type)(static_cast<LONG_PTR>(::SetClassLongPtrW(hWnd, n, (LONG_PTR)(ptr))));
215 #endif
216 }
WNDPROC DLSetClassWindowProc ( HWND  hWnd,
WNDPROC  pfn 
)
inline
219 {
220  return DLSetClassLongPtr<WNDPROC>(hWnd, pfn, GCLP_WNDPROC);
221 }
WNDPROC DLSetClassWindowProcA ( HWND  hWnd,
WNDPROC  pfn 
)
inline
224 {
225  return DLSetClassLongPtrA<WNDPROC>(hWnd, pfn, GCLP_WNDPROC);
226 }
WNDPROC DLSetClassWindowProcW ( HWND  hWnd,
WNDPROC  pfn 
)
inline
229 {
230  return DLSetClassLongPtrW<WNDPROC>(hWnd, pfn, GCLP_WNDPROC);
231 }
UtilExport LONG DLRegSetString ( HKEY  key,
const MCHAR data,
const MCHAR name = NULL 
)

Wrapper around the windows function RegSetValueEx.

Parameters
key- The handle to an open registry key
data- The actual data to be added to the registry
name- The name of the registry key
1 HKEY query;
2 MSTR sub_key;
3 sub_key.printf(_T("Software\\Autodesk\\3dsMax\\%d.0"), MAX_VERSION_MAJOR);
4 LONG opened = ::RegOpenKeyEx(HKEY_CURRENT_USER, sub_key.data(), 0, KEY_ALL_ACCESS, &query);
5 if (opened != ERROR_SUCCESS)
6  return;
7 
8 LONG result = DLRegSetString(query, _T("TestValue"), _T("TestKey"));
UtilExport LONG DLRegSetDWord ( HKEY  key,
DWORD  data,
const MCHAR name = NULL 
)

Wrapper around the windows function RegSetValueEx for DWORD data.

Parameters
key- The handle to an open registry key
data- The actual data to be added to the registry
name- The name of the registry key
LONG DLRegSetBlob ( HKEY  key,
const BlobType *  lpbValue,
DWORD  n,
LPCMSTR  lpValueName = NULL 
)
inline
288 {
289  return ::RegSetValueEx(key, lpValueName, 0, REG_BINARY,
290  reinterpret_cast<LPBYTE>(const_cast<BlobType*>(lpbValue)),
291  n * sizeof(BlobType));
292 }
UtilExport bool GetQtTextExtent ( const MCHAR text,
SIZE &  extent 
)

Calculates the text extents using Qt.

Parameters
[in]text- The text.
[out]extent- The text's extent as calculated via qApp->fontMetrics().boundingRect(text).
Returns
true if the text's extent was calculated (qApp exists, text not null).
UtilExport BOOL DLGetTextExtent ( HDC  hDC,
const MCHAR text,
LPSIZE  lpExtent,
bool  removeUIScaling = false,
bool  useQtTextWidth = true 
)
UtilExport BOOL DLGetTextExtent ( HDC  hDC,
const MCHAR text,
size_t  len,
LPSIZE  lpExtent,
bool  removeUIScaling = false,
bool  useQtTextWidth = true 
)
UtilExport BOOL DLTextOut ( HDC  hDC,
int  x,
int  y,
const MCHAR text 
)
UtilExport BOOL DLTextOut ( HDC  hDC,
int  x,
int  y,
const MCHAR text,
size_t  len 
)
UtilExport LONG DLTabbedTextOut ( HDC  hDC,
int  x,
int  y,
const MCHAR text,
int  nTabs,
const INT *  pTabPositions,
int  nTabOrigin 
)
UtilExport int DLDrawText ( HDC  hDC,
const MCHAR lpString,
LPRECT  lpRect,
UINT  uFormat 
)
UtilExport int DLDrawText ( HDC  hDC,
const MCHAR lpString,
size_t  len,
LPRECT  lpRect,
UINT  uFormat 
)
int DLGetSystemMetrics ( int  nIndex)
inline

Wrapper around the windows function GetSystemMetrics.

In Vista+ when running Aero, the value returned for SM_CXFRAME and SM_CYFRAME is incorrect in order to provide backwards compatibility with NT. To get the correct value, also need to add the value from SM_CXPADDEDBORDER. The implementation of this method automatically corrects the values returned for SM_CXFRAME and SM_CYFRAME. Note that SM_CXSIZEFRAME is the same index as SM_CXFRAME, and SM_CYSIZEFRAME as SM_CYFRAME;

Parameters
nIndex- The system metric or configuration setting to be retrieved.
332 {
333  int res = GetSystemMetrics(nIndex);
334  static bool applyCorrection = true;
335  if ( applyCorrection && (nIndex == SM_CXFRAME || nIndex == SM_CYFRAME))
336  res += GetSystemMetrics(92); // SM_CXPADDEDBORDER == 92, defined only when _WIN32_WINNT >= 0x0600
337  return res;
338 }
WORD PointerHiPart ( ULONG_PTR  ptr)
inline
382 {
383  return static_cast<WORD>(ptr >> 16);
384 }
WORD PointerLoPart ( ULONG_PTR  ptr)
inline
387 {
388  return static_cast<WORD>(ptr);
389 }
WORD PointerHiPart ( LONG_PTR  ptr)
inline
392 {
393  return static_cast<WORD>((ptr >> 16) & 0xffff);
394 }
WORD PointerLoPart ( LONG_PTR  ptr)
inline
397 {
398  return static_cast<WORD>(ptr & 0xffff);
399 }
WORD PointerHiPart ( void ptr)
inline
402 {
403  return PointerHiPart(reinterpret_cast<ULONG_PTR>(ptr));
404 }
WORD PointerHiPart(ULONG_PTR ptr)
Definition: 3dsmaxdlport.h:381
WORD PointerLoPart ( void ptr)
inline
407 {
408  return PointerLoPart(reinterpret_cast<ULONG_PTR>(ptr));
409 }
WORD PointerLoPart(ULONG_PTR ptr)
Definition: 3dsmaxdlport.h:386
unsigned int fnv_32_buf ( const void buf,
int  len,
unsigned int  hval 
)
inline
488 {
489  const unsigned char *bp = (const unsigned char *)buf; /* start of buffer */
490  const unsigned char *be = bp + len; /* beyond end of buffer */
491 
492  /*
493  * FNV-1 hash each octet in the buffer
494  */
495  while (bp < be)
496  {
497  /* multiply by the 32 bit FNV magic prime mod 2^32 */
498  hval *= FNV_32_PRIME;
499 
500  /* xor the bottom with the current octet */
501  hval ^= (unsigned int)*bp++;
502  }
503 
504  /* return our new hash value */
505  return hval;
506 }
MAXMEM_EXTERN_C UtilExport int(__cdecl *MAX_heapchk)(void)
Definition: 3dsmaxdlport.h:466
unsigned int DLObjectHash ( T &  t,
int  HashTableSize = 0 
)
inline
510 {
511  // Since we're always hashing single objects, we hash using the 'init value';
512  // we'd have to carry it over if we were hashing all fields in a structure, for
513  // instance.
514  // You should never never never never attempt to hash a structure by passing its
515  // pointer, since you'd end up hashing the padding bytes as well, which are definitely
516  // not going to be preserved.
517  unsigned int hash = fnv_32_buf(&t, sizeof(t), (unsigned int)FNV1_32_INIT);
518 
519  return HashTableSize ? hash % HashTableSize : hash;
520 }
Definition: 3dsmaxdlport.h:465
unsigned int fnv_32_buf(const void *buf, int len, unsigned int hval)
Definition: 3dsmaxdlport.h:487
unsigned int DLPointerHash ( const void pv,
int  HashTableSize = 0 
)
inline
523 {
524  return DLObjectHash(pv, HashTableSize);
525 }
unsigned int DLObjectHash(T &t, int HashTableSize=0)
Definition: 3dsmaxdlport.h:509
int DL_abs ( int  n)
inline
534 { return std::abs(n); }
__int64 DL_abs ( __int64  n)
inline
535 { return (n < 0) ? -n : n; }
float DL_abs ( float  f)
inline
537 { return std::fabsf(f); }
double DL_abs ( double  f)
inline
538 { return std::fabs(f); }
long double DL_abs ( long double  f)
inline
539 { return std::fabsl(f); }