dxutil.h
上传用户:fengshi120
上传日期:2014-07-17
资源大小:6155k
文件大小:8k
源码类别:

3D图形编程

开发平台:

C/C++

  1. //-----------------------------------------------------------------------------
  2. // File: DXUtil.h
  3. //
  4. // Desc: Helper functions and typing shortcuts for DirectX programming.
  5. //-----------------------------------------------------------------------------
  6. #ifndef DXUTIL_H
  7. #define DXUTIL_H
  8. //-----------------------------------------------------------------------------
  9. // Miscellaneous helper functions
  10. //-----------------------------------------------------------------------------
  11. #define SAFE_DELETE(p)       { if(p) { delete (p);     (p)=NULL; } }
  12. #define SAFE_DELETE_ARRAY(p) { if(p) { delete[] (p);   (p)=NULL; } }
  13. #define SAFE_RELEASE(p)      { if(p) { (p)->Release(); (p)=NULL; } }
  14. #ifndef UNDER_CE
  15. //-----------------------------------------------------------------------------
  16. // Name: DXUtil_GetDXSDKMediaPath() and DXUtil_FindMediaFile() 
  17. // Desc: Returns the DirectX SDK path, as stored in the system registry
  18. //       during the SDK install.
  19. //-----------------------------------------------------------------------------
  20. HRESULT DXUtil_GetDXSDKMediaPathCch( TCHAR* strDest, int cchDest );
  21. HRESULT DXUtil_GetDXSDKMediaPathCb( TCHAR* szDest, int cbDest );
  22. HRESULT DXUtil_FindMediaFileCch( TCHAR* strDestPath, int cchDest, TCHAR* strFilename );
  23. HRESULT DXUtil_FindMediaFileCb( TCHAR* szDestPath, int cbDest, TCHAR* strFilename );
  24. #endif // !UNDER_CE
  25. //-----------------------------------------------------------------------------
  26. // Name: DXUtil_Read*RegKey() and DXUtil_Write*RegKey()
  27. // Desc: Helper functions to read/write a string registry key 
  28. //-----------------------------------------------------------------------------
  29. HRESULT DXUtil_WriteStringRegKey( HKEY hKey, TCHAR* strRegName, TCHAR* strValue );
  30. HRESULT DXUtil_WriteIntRegKey( HKEY hKey, TCHAR* strRegName, DWORD dwValue );
  31. HRESULT DXUtil_WriteGuidRegKey( HKEY hKey, TCHAR* strRegName, GUID guidValue );
  32. HRESULT DXUtil_WriteBoolRegKey( HKEY hKey, TCHAR* strRegName, BOOL bValue );
  33. HRESULT DXUtil_ReadStringRegKeyCch( HKEY hKey, TCHAR* strRegName, TCHAR* strDest, DWORD cchDest, TCHAR* strDefault );
  34. HRESULT DXUtil_ReadStringRegKeyCb( HKEY hKey, TCHAR* strRegName, TCHAR* strDest, DWORD cbDest, TCHAR* strDefault );
  35. HRESULT DXUtil_ReadIntRegKey( HKEY hKey, TCHAR* strRegName, DWORD* pdwValue, DWORD dwDefault );
  36. HRESULT DXUtil_ReadGuidRegKey( HKEY hKey, TCHAR* strRegName, GUID* pGuidValue, GUID& guidDefault );
  37. HRESULT DXUtil_ReadBoolRegKey( HKEY hKey, TCHAR* strRegName, BOOL* pbValue, BOOL bDefault );
  38. //-----------------------------------------------------------------------------
  39. // Name: DXUtil_Timer()
  40. // Desc: Performs timer opertations. Use the following commands:
  41. //          TIMER_RESET           - to reset the timer
  42. //          TIMER_START           - to start the timer
  43. //          TIMER_STOP            - to stop (or pause) the timer
  44. //          TIMER_ADVANCE         - to advance the timer by 0.1 seconds
  45. //          TIMER_GETABSOLUTETIME - to get the absolute system time
  46. //          TIMER_GETAPPTIME      - to get the current time
  47. //          TIMER_GETELAPSEDTIME  - to get the time that elapsed between 
  48. //                                  TIMER_GETELAPSEDTIME calls
  49. //-----------------------------------------------------------------------------
  50. enum TIMER_COMMAND { TIMER_RESET, TIMER_START, TIMER_STOP, TIMER_ADVANCE,
  51.                      TIMER_GETABSOLUTETIME, TIMER_GETAPPTIME, TIMER_GETELAPSEDTIME };
  52. FLOAT __stdcall DXUtil_Timer( TIMER_COMMAND command );
  53. //-----------------------------------------------------------------------------
  54. // UNICODE support for converting between CHAR, TCHAR, and WCHAR strings
  55. //-----------------------------------------------------------------------------
  56. HRESULT DXUtil_ConvertAnsiStringToWideCch( WCHAR* wstrDestination, const CHAR* strSource, int cchDestChar );
  57. HRESULT DXUtil_ConvertWideStringToAnsiCch( CHAR* strDestination, const WCHAR* wstrSource, int cchDestChar );
  58. HRESULT DXUtil_ConvertGenericStringToAnsiCch( CHAR* strDestination, const TCHAR* tstrSource, int cchDestChar );
  59. HRESULT DXUtil_ConvertGenericStringToWideCch( WCHAR* wstrDestination, const TCHAR* tstrSource, int cchDestChar );
  60. HRESULT DXUtil_ConvertAnsiStringToGenericCch( TCHAR* tstrDestination, const CHAR* strSource, int cchDestChar );
  61. HRESULT DXUtil_ConvertWideStringToGenericCch( TCHAR* tstrDestination, const WCHAR* wstrSource, int cchDestChar );
  62. HRESULT DXUtil_ConvertAnsiStringToWideCb( WCHAR* wstrDestination, const CHAR* strSource, int cbDestChar );
  63. HRESULT DXUtil_ConvertWideStringToAnsiCb( CHAR* strDestination, const WCHAR* wstrSource, int cbDestChar );
  64. HRESULT DXUtil_ConvertGenericStringToAnsiCb( CHAR* strDestination, const TCHAR* tstrSource, int cbDestChar );
  65. HRESULT DXUtil_ConvertGenericStringToWideCb( WCHAR* wstrDestination, const TCHAR* tstrSource, int cbDestChar );
  66. HRESULT DXUtil_ConvertAnsiStringToGenericCb( TCHAR* tstrDestination, const CHAR* strSource, int cbDestChar );
  67. HRESULT DXUtil_ConvertWideStringToGenericCb( TCHAR* tstrDestination, const WCHAR* wstrSource, int cbDestChar );
  68. //-----------------------------------------------------------------------------
  69. // Readme functions
  70. //-----------------------------------------------------------------------------
  71. VOID DXUtil_LaunchReadme( HWND hWnd, TCHAR* strLoc = NULL );
  72. //-----------------------------------------------------------------------------
  73. // GUID to String converting 
  74. //-----------------------------------------------------------------------------
  75. HRESULT DXUtil_ConvertGUIDToStringCch( const GUID* pGuidSrc, TCHAR* strDest, int cchDestChar );
  76. HRESULT DXUtil_ConvertGUIDToStringCb( const GUID* pGuidSrc, TCHAR* strDest, int cbDestChar );
  77. HRESULT DXUtil_ConvertStringToGUID( const TCHAR* strIn, GUID* pGuidOut );
  78. //-----------------------------------------------------------------------------
  79. // Debug printing support
  80. // See dxerr9.h for more debug printing support
  81. //-----------------------------------------------------------------------------
  82. VOID    DXUtil_Trace( TCHAR* strMsg, ... );
  83. #if defined(DEBUG) | defined(_DEBUG)
  84.     #define DXTRACE           DXUtil_Trace
  85. #else
  86.     #define DXTRACE           sizeof
  87. #endif
  88. //-----------------------------------------------------------------------------
  89. // Name: ArrayListType
  90. // Desc: Indicates how data should be stored in a CArrayList
  91. //-----------------------------------------------------------------------------
  92. enum ArrayListType
  93. {
  94.     AL_VALUE,       // entry data is copied into the list
  95.     AL_REFERENCE,   // entry pointers are copied into the list
  96. };
  97. //-----------------------------------------------------------------------------
  98. // Name: CArrayList
  99. // Desc: A growable array
  100. //-----------------------------------------------------------------------------
  101. class CArrayList
  102. {
  103. protected:
  104.     ArrayListType m_ArrayListType;
  105.     void* m_pData;
  106.     UINT m_BytesPerEntry;
  107.     UINT m_NumEntries;
  108.     UINT m_NumEntriesAllocated;
  109. public:
  110.     CArrayList( ArrayListType Type, UINT BytesPerEntry = 0 );
  111.     ~CArrayList( void );
  112.     HRESULT Add( void* pEntry );
  113.     void Remove( UINT Entry );
  114.     void* GetPtr( UINT Entry );
  115.     UINT Count( void ) { return m_NumEntries; }
  116.     bool Contains( void* pEntryData );
  117.     void Clear( void ) { m_NumEntries = 0; }
  118. };
  119. //-----------------------------------------------------------------------------
  120. // WinCE build support
  121. //-----------------------------------------------------------------------------
  122. #ifdef UNDER_CE
  123. #define CheckDlgButton(hdialog, id, state) ::SendMessage(::GetDlgItem(hdialog, id), BM_SETCHECK, state, 0)
  124. #define IsDlgButtonChecked(hdialog, id) ::SendMessage(::GetDlgItem(hdialog, id), BM_GETCHECK, 0L, 0L)
  125. #define GETTIMESTAMP GetTickCount
  126. #define _TWINCE(x) _T(x)
  127. __inline int GetScrollPos(HWND hWnd, int nBar)
  128. {
  129. SCROLLINFO si;
  130. memset(&si, 0, sizeof(si));
  131. si.cbSize = sizeof(si);
  132. si.fMask = SIF_POS;
  133. if (!GetScrollInfo(hWnd, nBar, &si))
  134. {
  135. return 0;
  136. }
  137. else
  138. {
  139. return si.nPos;
  140. }
  141. }
  142. #else // !UNDER_CE
  143. #define GETTIMESTAMP timeGetTime
  144. #define _TWINCE(x) x
  145. #endif // UNDER_CE
  146. #endif // DXUTIL_H