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