dxutil.h
上传用户:sycq158
上传日期:2008-10-22
资源大小:15361k
文件大小:8k
源码类别:

游戏

开发平台:

Visual C++

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