Source code of Windows XP (NT5)
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.

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