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.

505 lines
13 KiB

  1. /*
  2. ***************************************************************
  3. *
  4. * This file contains the functions to display and submit changes
  5. * for sound effects
  6. *
  7. * Copyright 2000, Microsoft Corporation
  8. *
  9. * History:
  10. *
  11. * 03/2000 - tsharp (Created)
  12. *
  13. ***************************************************************
  14. */
  15. #include <windows.h>
  16. #include <mmsystem.h>
  17. #include <string.h>
  18. #include <cpl.h>
  19. #include <shellapi.h>
  20. #include <ole2.h>
  21. #include <mmddkp.h>
  22. #define NOSTATUSBAR
  23. #include <commctrl.h>
  24. #include <prsht.h>
  25. #include <regstr.h>
  26. #include "mmcpl.h"
  27. #include "draw.h"
  28. #include "medhelp.h"
  29. #include "gfxui.h"
  30. #include <dsound.h>
  31. #include <dsprv.h>
  32. #include "advaudio.h"
  33. /****************** Debug Off *********************/
  34. //#define DEBUG
  35. //#define _INC_MMDEBUG_CODE_ TRUE
  36. //#include "mmdebug.h"
  37. // End debug stuff
  38. #define MAX_GFX_COUNT 128 // maximum number of global effects (Gfx) processed
  39. #define MAX_LIST_DESC 50 // maximum length of Gfx description in list view
  40. #define FILLER_MSG 257 // maximum number of Gfx applicable to the system
  41. const static DWORD aKeyWordIds[] =
  42. {
  43. IDC_EFFECT_STATIC, IDH_EFFECT_STATIC,
  44. IDC_TEXT_32, NO_HELP,
  45. IDB_EFFECT_PROP, IDH_EFFECT_PROP,
  46. 0,0
  47. };
  48. /****************************************************************
  49. * Definitions
  50. ***************************************************************/
  51. typedef HRESULT (WINAPI *GETCLASSOBJECTFUNC)( REFCLSID, REFIID, LPVOID * );
  52. /***************************************************************
  53. * File Globals
  54. ***************************************************************/
  55. PGFXUILIST gpFullList;
  56. PGFXUILIST gpGfxInitList;
  57. PGFXUI gpGfxNodeArray[MAX_GFX_COUNT];
  58. /***************************************************************
  59. * extern
  60. ***************************************************************/
  61. extern "C" {
  62. extern DWORD GetWaveOutID(BOOL *pfPreferred);
  63. }
  64. /***************************************************************
  65. * Prototypes
  66. ***************************************************************/
  67. DWORD GetWaveOutID(void)
  68. {
  69. return GetWaveOutID(NULL);
  70. }
  71. /***************************************************************
  72. * GetListIndex
  73. *
  74. * Description:
  75. * Returns the selected index for the combobox. Always add one
  76. * for the first entry of "None"
  77. *
  78. * Parameters:
  79. * HWND DWORD - GFX ID
  80. *
  81. * Returns:
  82. * int - Index number of the selected item
  83. *
  84. ***************************************************************/
  85. int GetListIndex(PGFXUI pGfx)
  86. {
  87. int iIndex = 0;
  88. int iCnt = 0;
  89. if (pGfx)
  90. {
  91. while (gpGfxNodeArray[iCnt])
  92. {
  93. if (lstrcmpi(pGfx->pszName, gpGfxNodeArray[iCnt++]->pszName) == 0 )
  94. {
  95. iIndex = iCnt;
  96. break;
  97. }
  98. }
  99. }
  100. return (iIndex);
  101. }
  102. /***************************************************************
  103. * CheckEffect
  104. *
  105. * Description:
  106. * Check to see if effect has properties,
  107. *
  108. * Parameters:
  109. * HWND hDlg - handle to dialog window.
  110. *
  111. * Returns: BOOL
  112. * TRUE if all the events for the selected module were read from the reg
  113. * database, else FALSE
  114. ***************************************************************/
  115. BOOL PASCAL CheckEffect(HWND hDlg)
  116. {
  117. PGFXUI pGfxTemp = NULL;
  118. PGFXUI pGfxBase = NULL;
  119. DWORD dwIndex = (DWORD)SendDlgItemMessage(hDlg, IDC_EFFECT_LIST, CB_GETCURSEL,0,0);
  120. if (0 == dwIndex) return FALSE;
  121. if (!gpGfxNodeArray[dwIndex-1]) return FALSE;
  122. else pGfxTemp = gpGfxNodeArray[dwIndex-1];
  123. if (!gpGfxInitList->puiList) return FALSE;
  124. else pGfxBase = gpGfxInitList->puiList;
  125. if (lstrcmpi(pGfxTemp->pszName, pGfxBase->pszName) == 0)
  126. return GFXUI_CanShowProperties(pGfxBase);
  127. else return FALSE;
  128. }
  129. /***************************************************************
  130. * SetEffects
  131. *
  132. * Description:
  133. * Adds all the effects to the ListView,
  134. *
  135. * Parameters:
  136. * HWND hDlg - handle to dialog window.
  137. *
  138. * Returns: None
  139. ***************************************************************/
  140. void SetEffects(HWND hDlg)
  141. {
  142. PGFXUI pGfxDelete;
  143. PGFXUI pGfxTemp;
  144. PGFXUI pGfxBase;
  145. DWORD dwIndex = (DWORD)SendDlgItemMessage(hDlg, IDC_EFFECT_LIST, CB_GETCURSEL,0,0);
  146. // Check to see Index is in range
  147. if ((0 != dwIndex)&&(gpGfxNodeArray[dwIndex-1]))
  148. pGfxBase = gpGfxNodeArray[dwIndex-1];
  149. else
  150. pGfxBase = NULL;
  151. if (gpGfxInitList->puiList)
  152. pGfxTemp = gpGfxInitList->puiList;
  153. else
  154. pGfxTemp = NULL;
  155. // No GFX Selected or previously set
  156. if ((0 == dwIndex)&&(!pGfxTemp)) return;
  157. // GFX has not been changed
  158. if (pGfxTemp && pGfxBase)
  159. if (lstrcmpi(pGfxTemp->pszName, pGfxBase->pszName) == 0)
  160. return;
  161. // If there was a previous GFX it is assigned to pGfxTemp
  162. // to be deleted
  163. gpGfxInitList->puiList = NULL;
  164. if (pGfxBase)
  165. GFXUI_CreateAddGFX(&(gpGfxInitList->puiList), pGfxBase);
  166. GFXUI_Apply (&gpGfxInitList, &pGfxTemp);
  167. EnableWindow(GetDlgItem(hDlg, IDB_EFFECT_PROP), CheckEffect(hDlg));
  168. return;
  169. }
  170. /***************************************************************
  171. * LoadEffects
  172. *
  173. * Description:
  174. * Adds all the effects to the ListView,
  175. *
  176. * Parameters:
  177. * HWND hDlg - handle to dialog window.
  178. *
  179. * Returns:
  180. * None
  181. *
  182. ***************************************************************/
  183. void LoadEffects(HWND hDlg)
  184. {
  185. TCHAR szBuffer[MAX_PATH];
  186. DWORD dwDefDeviceId = 0;
  187. DWORD dwType =0;
  188. DWORD dwDeviceId = 0;
  189. DWORD dwIndex = 0;
  190. UINT uMixId;
  191. HRESULT hr;
  192. PGFXUILIST pRetList = NULL;
  193. PGFXUI pTempGFX = NULL;
  194. dwDeviceId = gAudData.waveId;
  195. dwDefDeviceId = GetWaveOutID();
  196. if (dwDeviceId != dwDefDeviceId) ShowWindow (GetDlgItem(hDlg, IDB_EFFECT_PLAY), SW_HIDE);
  197. if (gAudData.fRecord)
  198. dwType = GFXTYPE_CAPTURE;
  199. else
  200. dwType = GFXTYPE_RENDER;
  201. if (mixerGetID(HMIXEROBJ_INDEX(dwDeviceId), &uMixId, gAudData.fRecord ? MIXER_OBJECTF_WAVEIN : MIXER_OBJECTF_WAVEOUT)) uMixId = (-1);
  202. hr = GFXUI_CreateList(uMixId, dwType, FALSE, &pRetList);
  203. if (SUCCEEDED (hr))
  204. {
  205. ASSERT(pRetList);
  206. gpGfxInitList = pRetList;
  207. pTempGFX = gpGfxInitList->puiList;
  208. }
  209. if(SUCCEEDED (hr) && pTempGFX)
  210. {
  211. dwIndex = GetListIndex(pTempGFX);
  212. SendDlgItemMessage(hDlg, IDC_EFFECT_LIST, CB_SETCURSEL, dwIndex, 0);
  213. } else {
  214. SendDlgItemMessage(hDlg, IDC_EFFECT_LIST, CB_SETCURSEL,0,0);
  215. }
  216. EnableWindow(GetDlgItem(hDlg, IDB_EFFECT_PROP), CheckEffect(hDlg));
  217. }
  218. /***************************************************************
  219. * LoadEffectList
  220. *
  221. * Description:
  222. * Adds all the effects to the Combobox,
  223. *
  224. * Parameters:
  225. * HWND hDlg - handle to dialog window.
  226. *
  227. * Returns:
  228. * None
  229. *
  230. ***************************************************************/
  231. void LoadEffectList(HWND hDlg)
  232. {
  233. int nItemNum = 0;
  234. TCHAR szBuffer[MAX_PATH];
  235. DWORD dwType = 0;
  236. DWORD dwWaveId = 0;
  237. UINT uMixId;
  238. PGFXUI pList = NULL;
  239. HRESULT hr;
  240. SendDlgItemMessage(hDlg, IDC_EFFECT_LIST, CB_RESETCONTENT,0,0);
  241. LoadString (ghInstance, IDS_NOGFXSET, szBuffer, sizeof(szBuffer)/sizeof(TCHAR));
  242. SendDlgItemMessage(hDlg, IDC_EFFECT_LIST, CB_INSERTSTRING, (WPARAM) -1, (LPARAM) szBuffer);
  243. if (gAudData.fRecord)
  244. dwType = GFXTYPE_CAPTURE;
  245. else
  246. dwType = GFXTYPE_RENDER;
  247. dwWaveId = gAudData.waveId;
  248. if (mixerGetID(HMIXEROBJ_INDEX(dwWaveId), &uMixId, gAudData.fRecord ? MIXER_OBJECTF_WAVEIN : MIXER_OBJECTF_WAVEOUT)) uMixId = (-1);
  249. hr = GFXUI_CreateList(uMixId, dwType, TRUE, &gpFullList);
  250. if (SUCCEEDED (hr))
  251. {
  252. ASSERT(gpFullList);
  253. pList = gpFullList->puiList;
  254. }
  255. if(SUCCEEDED (hr) && pList)
  256. {
  257. do
  258. {
  259. SendDlgItemMessage(hDlg, IDC_EFFECT_LIST, CB_INSERTSTRING, (WPARAM) -1, (LPARAM) pList->pszName);
  260. gpGfxNodeArray[nItemNum] = pList;
  261. nItemNum++;
  262. pList = pList->pNext;
  263. }while(pList);
  264. gpGfxNodeArray[nItemNum] = NULL;
  265. }
  266. }
  267. /****************************************************************
  268. * ShowProperties
  269. *
  270. * Description:
  271. * Show properties button if applicable.
  272. *
  273. * Parameters:
  274. * HWND hDlg window handle of dialog window
  275. *
  276. * Returns:
  277. * None
  278. *
  279. ****************************************************************/
  280. void ShowProperties (HWND hDlg)
  281. {
  282. PGFXUI pGfxTemp = NULL;
  283. PGFXUI pGfxBase = NULL;
  284. DWORD dwIndex = (DWORD)SendDlgItemMessage(hDlg, IDC_EFFECT_LIST, CB_GETCURSEL,0,0);
  285. if (0 == dwIndex) return;
  286. if (!gpGfxNodeArray[dwIndex-1]) return;
  287. else pGfxTemp = gpGfxNodeArray[dwIndex-1];
  288. if (!gpGfxInitList->puiList) return;
  289. else pGfxBase = gpGfxInitList->puiList;
  290. if (lstrcmpi(pGfxTemp->pszName, pGfxBase->pszName) == 0)
  291. GFXUI_Properties (pGfxBase, hDlg);;
  292. return;
  293. }
  294. /****************************************************************
  295. * ChangeGFX
  296. *
  297. * Description:
  298. * Show properties button if applicable.
  299. *
  300. * Parameters:
  301. * HWND hDlg window handle of dialog window
  302. *
  303. * Returns:
  304. * None
  305. *
  306. ****************************************************************/
  307. void ChangeGFX (HWND hDlg)
  308. {
  309. DWORD dwIndex = 0;
  310. HWND hwndSheet = GetParent(hDlg);
  311. EnableWindow(GetDlgItem(hDlg, IDB_EFFECT_PROP), FALSE);
  312. dwIndex = (DWORD)SendDlgItemMessage(hDlg, IDC_EFFECT_LIST, CB_GETCURSEL,0,0);
  313. if (dwIndex != CB_ERR)
  314. {
  315. EnableWindow(GetDlgItem(hDlg, IDB_EFFECT_PROP), CheckEffect(hDlg));
  316. PropSheet_Changed(hwndSheet,hDlg);
  317. }
  318. }
  319. /*
  320. ***************************************************************
  321. * EffectDlg
  322. *
  323. * Description:
  324. * EffectDlg for MM control panel applet.
  325. *
  326. * Parameters:
  327. * HWND hDlg window handle of dialog window
  328. * UINT uiMessage message number
  329. * WPARAM wParam message-dependent
  330. * LPARAM lParam message-dependent
  331. *
  332. * Returns: BOOL
  333. * TRUE if message has been processed, else FALSE
  334. *
  335. ***************************************************************
  336. */
  337. INT_PTR CALLBACK SoundEffectsDlg(HWND hDlg, UINT uMsg, WPARAM wParam,LPARAM lParam)
  338. {
  339. NMHDR FAR * lpnm;
  340. switch (uMsg)
  341. {
  342. case WM_NOTIFY:
  343. lpnm = (NMHDR FAR *)lParam;
  344. switch(lpnm->code)
  345. {
  346. case PSN_APPLY:
  347. FORWARD_WM_COMMAND(hDlg, ID_APPLY, 0, 0, SendMessage);
  348. break;
  349. case PSN_RESET:
  350. FORWARD_WM_COMMAND(hDlg, IDCANCEL, 0, 0, SendMessage);
  351. break;
  352. break;
  353. }
  354. break;
  355. case WM_INITDIALOG:
  356. {
  357. LoadEffectList(hDlg);
  358. if (gAudData.fRecord)
  359. {
  360. // Hide the "Play Default Sound" button for Recording devices
  361. ShowWindow (GetDlgItem(hDlg, IDB_EFFECT_PLAY), SW_HIDE);
  362. }
  363. LoadEffects(hDlg);
  364. }
  365. break;
  366. case WM_DESTROY:
  367. {
  368. GFXUI_FreeList(&gpGfxInitList);
  369. GFXUI_FreeList(&gpFullList);
  370. break;
  371. }
  372. case WM_CONTEXTMENU:
  373. WinHelp((HWND)wParam, NULL, HELP_CONTEXTMENU,
  374. (UINT_PTR)(LPTSTR)aKeyWordIds);
  375. break;
  376. case WM_HELP:
  377. WinHelp((HWND)((LPHELPINFO)lParam)->hItemHandle, NULL, HELP_WM_HELP
  378. , (UINT_PTR)(LPTSTR)aKeyWordIds);
  379. break;
  380. case WM_COMMAND:
  381. switch (LOWORD(wParam))
  382. {
  383. case ID_APPLY:
  384. {
  385. SetEffects(hDlg);
  386. }
  387. break;
  388. case IDC_EFFECT_LIST:
  389. {
  390. if (HIWORD(wParam) == CBN_SELCHANGE) ChangeGFX(hDlg);
  391. }
  392. break;
  393. case IDB_EFFECT_PROP:
  394. {
  395. ShowProperties (hDlg);
  396. }
  397. break;
  398. case IDB_EFFECT_PLAY:
  399. {
  400. PlaySound(TEXT(".Default"), NULL, SND_FILENAME | SND_ASYNC );
  401. }
  402. break;
  403. }
  404. break;
  405. default:
  406. break;
  407. }
  408. return FALSE;
  409. }