Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

382 lines
10 KiB

  1. /*****************************************************************************
  2. *
  3. * Component: sndvol32.exe
  4. * File: utils.c
  5. * Purpose: miscellaneous
  6. *
  7. * Copyright (c) 1985-1999 Microsoft Corporation
  8. *
  9. *****************************************************************************/
  10. #include <windows.h>
  11. #include <windowsx.h>
  12. #include <mmsystem.h>
  13. #include "volumei.h"
  14. #include "volids.h"
  15. #include "mmddkp.h"
  16. #define STRSAFE_LIB
  17. #include <strsafe.h>
  18. /* misc. */
  19. const TCHAR gszStateSubkey[] = TEXT ("%s\\%s");
  20. static TCHAR gszAppName[256];
  21. BOOL Volume_ErrorMessageBox(
  22. HWND hwnd,
  23. HINSTANCE hInst,
  24. UINT id)
  25. {
  26. TCHAR szMessage[256];
  27. BOOL fRet;
  28. szMessage[0] = 0;
  29. if (!gszAppName[0])
  30. LoadString(hInst, IDS_APPBASE, gszAppName, SIZEOF(gszAppName));
  31. LoadString(hInst, id, szMessage, SIZEOF(szMessage));
  32. fRet = (MessageBox(hwnd
  33. , szMessage
  34. , gszAppName
  35. , MB_APPLMODAL | MB_ICONINFORMATION
  36. | MB_OK | MB_SETFOREGROUND) == MB_OK);
  37. return fRet;
  38. }
  39. const TCHAR aszXPos[] = TEXT ("X");
  40. const TCHAR aszYPos[] = TEXT ("Y");
  41. const TCHAR aszLineInfo[] = TEXT ("LineStates");
  42. ///////////////////////////////////////////////////////////////////////////////////////////
  43. // Microsoft Confidential - DO NOT COPY THIS METHOD INTO ANY APPLICATION, THIS MEANS YOU!!!
  44. ///////////////////////////////////////////////////////////////////////////////////////////
  45. DWORD GetWaveOutID(BOOL *pfPreferred)
  46. {
  47. MMRESULT mmr;
  48. DWORD dwWaveID=0;
  49. DWORD dwFlags = 0;
  50. if (pfPreferred)
  51. {
  52. *pfPreferred = TRUE;
  53. }
  54. mmr = waveOutMessage((HWAVEOUT)UIntToPtr(WAVE_MAPPER), DRVM_MAPPER_PREFERRED_GET, (DWORD_PTR) &dwWaveID, (DWORD_PTR) &dwFlags);
  55. if (!mmr && pfPreferred)
  56. {
  57. *pfPreferred = dwFlags & 0x00000001;
  58. }
  59. return(dwWaveID);
  60. }
  61. ///////////////////////////////////////////////////////////////////////////////////////////
  62. // Microsoft Confidential - DO NOT COPY THIS METHOD INTO ANY APPLICATION, THIS MEANS YOU!!!
  63. ///////////////////////////////////////////////////////////////////////////////////////////
  64. DWORD GetWaveInID(BOOL *pfPreferred)
  65. {
  66. MMRESULT mmr;
  67. DWORD dwWaveID=0;
  68. DWORD dwFlags = 0;
  69. if (pfPreferred)
  70. {
  71. *pfPreferred = TRUE;
  72. }
  73. mmr = waveInMessage((HWAVEIN)UIntToPtr(WAVE_MAPPER), DRVM_MAPPER_PREFERRED_GET, (DWORD_PTR) &dwWaveID, (DWORD_PTR) &dwFlags);
  74. if (!mmr && pfPreferred)
  75. {
  76. *pfPreferred = dwFlags & 0x00000001;
  77. }
  78. return(dwWaveID);
  79. }
  80. /*
  81. * Volume_GetDefaultMixerID
  82. *
  83. * Get the default mixer id. We only appear if there is a mixer associated
  84. * with the default wave.
  85. *
  86. */
  87. MMRESULT Volume_GetDefaultMixerID(
  88. int *pid,
  89. BOOL fRecord)
  90. {
  91. MMRESULT mmr;
  92. UINT u, uMxID;
  93. BOOL fPreferredOnly = 0;
  94. *pid = 0;
  95. mmr = MMSYSERR_ERROR;
  96. //
  97. // We use messages to the Wave Mapper in Win2K to get the preferred device.
  98. //
  99. if (fRecord)
  100. {
  101. if(waveInGetNumDevs())
  102. {
  103. u = GetWaveInID(&fPreferredOnly);
  104. // Can we get a mixer device ID from the wave device?
  105. mmr = mixerGetID((HMIXEROBJ)UIntToPtr(u), &uMxID, MIXER_OBJECTF_WAVEIN);
  106. if (mmr == MMSYSERR_NOERROR)
  107. {
  108. // Return this ID.
  109. *pid = uMxID;
  110. }
  111. }
  112. }
  113. else
  114. {
  115. if(waveOutGetNumDevs())
  116. {
  117. u = GetWaveOutID(&fPreferredOnly);
  118. // Can we get a mixer device ID from the wave device?
  119. mmr = mixerGetID((HMIXEROBJ)UIntToPtr(u), &uMxID, MIXER_OBJECTF_WAVEOUT);
  120. if (mmr == MMSYSERR_NOERROR)
  121. {
  122. // Return this ID.
  123. *pid = uMxID;
  124. }
  125. }
  126. }
  127. return mmr;
  128. }
  129. const TCHAR aszOptionsSection[] = TEXT ("Options");
  130. /*
  131. * Volume_GetSetStyle
  132. *
  133. * */
  134. void Volume_GetSetStyle(
  135. DWORD *pdwStyle,
  136. BOOL Get)
  137. {
  138. const TCHAR aszStyle[] = TEXT ("Style");
  139. if (Get)
  140. {
  141. if (QueryRegistryDataSizeAndType((LPTSTR)aszOptionsSection
  142. , (LPTSTR)aszStyle
  143. , REG_DWORD
  144. , NULL) == NO_ERROR)
  145. {
  146. ReadRegistryData((LPTSTR)aszOptionsSection
  147. , (LPTSTR)aszStyle
  148. , NULL
  149. , (LPBYTE)pdwStyle
  150. , sizeof(DWORD));
  151. }
  152. }
  153. else
  154. {
  155. WriteRegistryData((LPTSTR)aszOptionsSection
  156. , (LPTSTR)aszStyle
  157. , REG_DWORD
  158. , (LPBYTE)pdwStyle
  159. , sizeof(DWORD));
  160. }
  161. }
  162. /*
  163. * Volume_GetTrayTimeout
  164. *
  165. * */
  166. //DWORD Volume_GetTrayTimeout(
  167. // DWORD dwTimeout)
  168. //{
  169. // const TCHAR aszTrayTimeout[] = TEXT ("TrayTimeout");
  170. // DWORD dwT = dwTimeout;
  171. // ReadRegistryData(NULL
  172. // , (LPTSTR)aszTrayTimeout
  173. // , NULL
  174. // , (LPBYTE)&dwT
  175. // , sizeof(DWORD));
  176. // return dwT;
  177. //}
  178. /*
  179. * Volume_GetSetRegistryLineStates
  180. *
  181. * Get/Set line states s.t. lines can be disabled if not used.
  182. *
  183. * */
  184. struct LINESTATE {
  185. DWORD dwSupport;
  186. TCHAR szName[MIXER_LONG_NAME_CHARS];
  187. };
  188. #define VCD_STATEMASK (VCD_SUPPORTF_VISIBLE|VCD_SUPPORTF_HIDDEN)
  189. BOOL Volume_GetSetRegistryLineStates(
  190. LPTSTR pszMixer,
  191. LPTSTR pszDest,
  192. PVOLCTRLDESC avcd,
  193. DWORD cvcd,
  194. BOOL Get)
  195. {
  196. struct LINESTATE * pls;
  197. DWORD ils, cls;
  198. TCHAR achEntry[128];
  199. if (cvcd == 0)
  200. return TRUE;
  201. StringCchPrintf(achEntry, SIZEOF(achEntry), gszStateSubkey, pszMixer, pszDest);
  202. if (Get)
  203. {
  204. UINT cb;
  205. if (QueryRegistryDataSizeAndType((LPTSTR)achEntry
  206. , (LPTSTR)aszLineInfo
  207. , REG_BINARY
  208. , &cb) != NO_ERROR)
  209. return FALSE;
  210. pls = (struct LINESTATE *)GlobalAllocPtr(GHND, cb);
  211. if (!pls)
  212. return FALSE;
  213. if (ReadRegistryData((LPTSTR)achEntry
  214. , (LPTSTR)aszLineInfo
  215. , NULL
  216. , (LPBYTE)pls
  217. , cb) != NO_ERROR)
  218. {
  219. GlobalFreePtr(pls);
  220. return FALSE;
  221. }
  222. cls = cb / sizeof(struct LINESTATE);
  223. if (cls > cvcd)
  224. cls = cvcd;
  225. //
  226. // Restore the hidden state of the line.
  227. //
  228. for (ils = 0; ils < cls; ils++)
  229. {
  230. if (lstrcmp(pls[ils].szName, avcd[ils].szName) == 0)
  231. {
  232. avcd[ils].dwSupport |= pls[ils].dwSupport;
  233. }
  234. }
  235. GlobalFreePtr(pls);
  236. }
  237. else
  238. {
  239. pls = (struct LINESTATE *)GlobalAllocPtr(GHND, cvcd * sizeof (struct LINESTATE));
  240. if (!pls)
  241. return FALSE;
  242. //
  243. // Save the hidden state of the line
  244. //
  245. for (ils = 0; ils < cvcd; ils++)
  246. {
  247. StringCchCopy(pls[ils].szName, SIZEOF(pls[ils].szName), avcd[ils].szName);
  248. pls[ils].dwSupport = avcd[ils].dwSupport & VCD_SUPPORTF_HIDDEN;
  249. }
  250. if (WriteRegistryData((LPTSTR)achEntry
  251. , (LPTSTR)aszLineInfo
  252. , REG_BINARY
  253. , (LPBYTE)pls
  254. , cvcd*sizeof(struct LINESTATE)) != NO_ERROR)
  255. {
  256. GlobalFreePtr(pls);
  257. return FALSE;
  258. }
  259. GlobalFreePtr(pls);
  260. }
  261. return TRUE;
  262. }
  263. /*
  264. * Volume_GetSetRegistryRect
  265. *
  266. * Set/Get window position for restoring the postion of the app window
  267. *
  268. * */
  269. BOOL Volume_GetSetRegistryRect(
  270. LPTSTR szMixer,
  271. LPTSTR szDest,
  272. LPRECT prc,
  273. BOOL Get)
  274. {
  275. TCHAR achEntry[128];
  276. StringCchPrintf(achEntry, SIZEOF(achEntry), gszStateSubkey, szMixer, szDest);
  277. if (Get)
  278. {
  279. if (QueryRegistryDataSizeAndType((LPTSTR)achEntry
  280. , (LPTSTR)aszXPos
  281. , REG_DWORD
  282. , NULL) != NO_ERROR)
  283. {
  284. return FALSE;
  285. }
  286. if (ReadRegistryData((LPTSTR)achEntry
  287. , (LPTSTR)aszXPos
  288. , NULL
  289. , (LPBYTE)&prc->left
  290. , sizeof(prc->left)) != NO_ERROR)
  291. {
  292. return FALSE;
  293. }
  294. if (QueryRegistryDataSizeAndType((LPTSTR)achEntry
  295. , (LPTSTR)aszYPos
  296. , REG_DWORD
  297. , NULL) != NO_ERROR)
  298. {
  299. return FALSE;
  300. }
  301. if (ReadRegistryData((LPTSTR)achEntry
  302. , (LPTSTR)aszYPos
  303. , NULL
  304. , (LPBYTE)&prc->top
  305. , sizeof(prc->top)) != NO_ERROR)
  306. {
  307. return FALSE;
  308. }
  309. }
  310. else
  311. {
  312. if (prc)
  313. {
  314. if (WriteRegistryData((LPTSTR)achEntry
  315. , (LPTSTR)aszXPos
  316. , REG_DWORD
  317. , (LPBYTE)&prc->left
  318. , sizeof(prc->left)) != NO_ERROR)
  319. {
  320. return FALSE;
  321. }
  322. if (WriteRegistryData((LPTSTR)achEntry
  323. , (LPTSTR)aszYPos
  324. , REG_DWORD
  325. , (LPBYTE)&prc->top
  326. , sizeof(prc->top)) != NO_ERROR)
  327. {
  328. return FALSE;
  329. }
  330. }
  331. }
  332. return TRUE;
  333. }