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.

830 lines
20 KiB

  1. /*
  2. ***************************************************************
  3. * sprop.c
  4. *
  5. * Copyright (C) Microsoft, 1990, All Rights Reserved.
  6. *
  7. * Displays the Simple media properties
  8. *
  9. * History:
  10. *
  11. * July 1994 -by- VijR (Created)
  12. *
  13. ***************************************************************
  14. */
  15. #include "mmcpl.h"
  16. #include <windowsx.h>
  17. #ifdef DEBUG
  18. #undef DEBUG
  19. #include <mmsystem.h>
  20. #define DEBUG
  21. #else
  22. #include <mmsystem.h>
  23. #endif
  24. #include <mmddk.h>
  25. #include <mmreg.h>
  26. #include <commctrl.h>
  27. #include <prsht.h>
  28. #include <regstr.h>
  29. #include "utils.h"
  30. #include "medhelp.h"
  31. #include "mmcpl.h"
  32. #include <winerror.h>
  33. //for digital cd audio
  34. #include "devguid.h"
  35. #include "setupapi.h"
  36. #include "cfgmgr32.h"
  37. #include "winioctl.h"
  38. #include "tchar.h"
  39. const TCHAR gszCreateCDFile[] = TEXT("\\\\.\\%c:");
  40. #define MYREGSTR_PATH_MEDIA TEXT("SYSTEM\\CurrentControlSet\\Control\\MediaResources")
  41. const TCHAR gszRegstrCDAPath[] = MYREGSTR_PATH_MEDIA TEXT("\\mci\\cdaudio");
  42. const TCHAR gszUnitEnum[] = TEXT("%s\\unit %d");
  43. const TCHAR gszSettingsKey[] = TEXT("Volume Settings");
  44. const TCHAR gszDefaultCDA[] = TEXT("Default Drive");
  45. const TCHAR gszRegstrCDROMPath[] = TEXT("System\\CurrentControlSet\\Services\\Class\\CDROM\\");
  46. const TCHAR gszDigitalPlay[] = TEXT("DigitalAudioPlay");
  47. const TCHAR gszRegstrDrivePath[] = TEXT("Enum\\SCSI");
  48. #define CDA_VT_UNSET 0
  49. #define CDA_VT_AUX 1
  50. #define CDA_VT_MIX 2
  51. #define CDROM_DIGITAL_PLAY_ENABLED 0x01
  52. #define CDROM_DIGITAL_PLAY_CAPABLE 0x02
  53. #define CDROM_DIGITAL_DEVICE_KNOWN 0x04
  54. typedef struct { // This struct is used in other places DO NOT CHANGE
  55. DWORD unit;
  56. DWORD dwVol;
  57. } CDAREG, *PCDAREG;
  58. typedef struct { // This is now the local version with addition data, this can change, but has to keep the
  59. CDAREG cdar;
  60. BOOLEAN fDigFlags;
  61. BOOLEAN DigitalEnabled;
  62. BOOLEAN DigitalKnownDevice;
  63. BOOLEAN oldDigEnabled;
  64. DWORD dwOldVol;
  65. TCHAR chDrive;
  66. HDEVINFO hDevInfo;
  67. PSP_DEVINFO_DATA pDevInfoData;
  68. } CDSTATE, *PCDSTATE;
  69. BOOL g_fWDMEnabled = FALSE;
  70. HMODULE g_hModStorProp = NULL;
  71. typedef LONG (WINAPI *CDROMISDIGITALPLAYBACKENABLEDPROC)(HDEVINFO,PSP_DEVINFO_DATA,BOOLEAN*);
  72. typedef BOOL (WINAPI *CDROMKNOWNGOODDIGITALPLAYBACKPROC)(HDEVINFO,PSP_DEVINFO_DATA);
  73. typedef LONG (WINAPI *CDROMENABLEDIGITALPLAYBACKPROC)(HDEVINFO,PSP_DEVINFO_DATA,BOOLEAN);
  74. typedef LONG (WINAPI *CDROMDISABLEDIGITALPLAYBACKPROC)(HDEVINFO,PSP_DEVINFO_DATA);
  75. CDROMISDIGITALPLAYBACKENABLEDPROC _gCdromIsDigitalPlaybackEnabled = NULL;
  76. CDROMKNOWNGOODDIGITALPLAYBACKPROC _gCdromKnownGoodDigitalPlayback = NULL;
  77. CDROMENABLEDIGITALPLAYBACKPROC _gCdromEnableDigitalPlayback = NULL;
  78. CDROMDISABLEDIGITALPLAYBACKPROC _gCdromDisableDigitalPlayback = NULL;
  79. void GetPrefInfo(PAUDIODLGINFO pai, HWND hDlg );
  80. HANDLE GetHandleForDevice(LPCTSTR DeviceName)
  81. {
  82. int i = 0;
  83. TCHAR fakeDeviceName[MAX_PATH];
  84. HANDLE h = INVALID_HANDLE_VALUE;
  85. BOOL success = FALSE;
  86. TCHAR buf[MAX_PATH];
  87. while (!success && i < 10)
  88. {
  89. wsprintf(buf, TEXT("DISK_FAKE_DEVICE_%d_"), i++);
  90. success = DefineDosDevice(DDD_RAW_TARGET_PATH,
  91. buf,
  92. DeviceName);
  93. if (success)
  94. {
  95. _tcscpy(fakeDeviceName, TEXT("\\\\.\\"));
  96. _tcscat(fakeDeviceName, buf);
  97. h = CreateFile(fakeDeviceName,
  98. GENERIC_WRITE | GENERIC_READ,
  99. FILE_SHARE_WRITE | FILE_SHARE_READ,
  100. NULL,
  101. OPEN_EXISTING,
  102. 0,
  103. NULL);
  104. DefineDosDevice(DDD_REMOVE_DEFINITION,
  105. buf,
  106. NULL);
  107. }
  108. } //end while
  109. return h;
  110. }
  111. HANDLE GetHandleForDeviceInst(DEVINST DevInst)
  112. {
  113. TCHAR DeviceName[MAX_PATH];
  114. CONFIGRET cr;
  115. DWORD len = MAX_PATH;
  116. cr = CM_Get_DevNode_Registry_Property(DevInst,
  117. CM_DRP_PHYSICAL_DEVICE_OBJECT_NAME,
  118. NULL,
  119. DeviceName,
  120. &len,
  121. 0);
  122. if (cr != CR_SUCCESS)
  123. {
  124. return 0;
  125. }
  126. return GetHandleForDevice(DeviceName);
  127. }
  128. BOOL EnableCdromFunctions(HMODULE* pMod)
  129. {
  130. BOOL fRet = FALSE;
  131. if (!*pMod)
  132. {
  133. *pMod = LoadLibrary(TEXT("STORPROP.DLL"));
  134. }
  135. if (*pMod)
  136. {
  137. _gCdromIsDigitalPlaybackEnabled = (CDROMISDIGITALPLAYBACKENABLEDPROC)GetProcAddress(*pMod,"CdromIsDigitalPlaybackEnabled");
  138. _gCdromKnownGoodDigitalPlayback = (CDROMKNOWNGOODDIGITALPLAYBACKPROC)GetProcAddress(*pMod,"CdromKnownGoodDigitalPlayback");
  139. _gCdromEnableDigitalPlayback = (CDROMENABLEDIGITALPLAYBACKPROC)GetProcAddress(*pMod,"CdromEnableDigitalPlayback");
  140. _gCdromDisableDigitalPlayback = (CDROMDISABLEDIGITALPLAYBACKPROC)GetProcAddress(*pMod,"CdromDisableDigitalPlayback");
  141. if (
  142. (_gCdromIsDigitalPlaybackEnabled)
  143. &&
  144. (_gCdromKnownGoodDigitalPlayback)
  145. &&
  146. (_gCdromEnableDigitalPlayback)
  147. &&
  148. (_gCdromDisableDigitalPlayback)
  149. )
  150. {
  151. fRet = TRUE;
  152. }
  153. }
  154. return fRet;
  155. }
  156. BYTE CDAudio_GetSetDigitalFlags(PCDSTATE pcds, BYTE fSetFlags, BOOL fSet)
  157. {
  158. BYTE bFlags = 0;
  159. BOOLEAN bEnabled = FALSE;
  160. if (EnableCdromFunctions(&g_hModStorProp))
  161. {
  162. bFlags = 0;
  163. if (fSet)
  164. {
  165. BOOLEAN bEnable = fSetFlags & CDROM_DIGITAL_PLAY_ENABLED;
  166. BOOLEAN bAlready = FALSE;
  167. _gCdromIsDigitalPlaybackEnabled(pcds->hDevInfo,pcds->pDevInfoData,&bAlready);
  168. if (bEnable != bAlready)
  169. {
  170. if (bEnable)
  171. {
  172. _gCdromEnableDigitalPlayback(pcds->hDevInfo,pcds->pDevInfoData,FALSE);
  173. }
  174. else
  175. {
  176. _gCdromDisableDigitalPlayback(pcds->hDevInfo,pcds->pDevInfoData);
  177. }
  178. }
  179. }
  180. //always do a get after a set
  181. _gCdromIsDigitalPlaybackEnabled(pcds->hDevInfo,pcds->pDevInfoData,&bEnabled);
  182. if (bEnabled)
  183. {
  184. bFlags |= CDROM_DIGITAL_PLAY_ENABLED;
  185. }
  186. if (_gCdromKnownGoodDigitalPlayback(pcds->hDevInfo,pcds->pDevInfoData))
  187. {
  188. bFlags |= CDROM_DIGITAL_DEVICE_KNOWN;
  189. }
  190. }
  191. return bFlags;
  192. }
  193. BYTE CDAudio_SetDigitalFlags(PCDSTATE pcds, BYTE fDigFlags)
  194. {
  195. return CDAudio_GetSetDigitalFlags(pcds,fDigFlags,TRUE);
  196. }
  197. BYTE CDAudio_GetDigitalFlags(PCDSTATE pcds)
  198. {
  199. return CDAudio_GetSetDigitalFlags(pcds,0,FALSE);
  200. }
  201. /*
  202. * */
  203. void CDAudio_GetRegData(PCDSTATE pcds,ULONG uDrive)
  204. {
  205. TCHAR szRegstrCDAudio[_MAX_PATH];
  206. HKEY hkTmp;
  207. if (!pcds)
  208. return;
  209. wsprintf(szRegstrCDAudio, gszUnitEnum, gszRegstrCDAPath, uDrive);
  210. pcds->cdar.dwVol = 0xFF;
  211. if (RegOpenKeyEx(HKEY_LOCAL_MACHINE
  212. , szRegstrCDAudio
  213. , 0
  214. , KEY_READ
  215. , &hkTmp ) == ERROR_SUCCESS)
  216. {
  217. DWORD cbCDA = sizeof(CDAREG);
  218. RegQueryValueEx(hkTmp
  219. , gszSettingsKey
  220. , NULL
  221. , NULL
  222. , (LPBYTE)&pcds->cdar
  223. , &cbCDA);
  224. RegCloseKey(hkTmp);
  225. }
  226. pcds->cdar.unit = uDrive;
  227. pcds->fDigFlags = CDAudio_GetDigitalFlags(pcds);
  228. pcds->DigitalEnabled = pcds->fDigFlags & CDROM_DIGITAL_PLAY_ENABLED;
  229. pcds->DigitalKnownDevice = pcds->fDigFlags & CDROM_DIGITAL_DEVICE_KNOWN;
  230. pcds->oldDigEnabled = pcds->DigitalEnabled;
  231. pcds->dwOldVol = pcds->cdar.dwVol;
  232. }
  233. /*
  234. * */
  235. void CDAudio_SetRegData(
  236. PCDSTATE pcds, HWND hwnd)
  237. {
  238. TCHAR szRegstrCDAudio[_MAX_PATH];
  239. HKEY hkTmp;
  240. BYTE bFlags = 0;
  241. wsprintf(szRegstrCDAudio, gszUnitEnum, gszRegstrCDAPath, pcds->cdar.unit);
  242. if (RegCreateKeyEx(HKEY_LOCAL_MACHINE
  243. , szRegstrCDAudio
  244. , 0
  245. , NULL
  246. , 0
  247. , KEY_WRITE
  248. , NULL
  249. , &hkTmp
  250. , NULL ) == ERROR_SUCCESS)
  251. {
  252. RegSetValueEx(hkTmp
  253. , gszSettingsKey
  254. , 0L
  255. , REG_BINARY
  256. , (LPBYTE)&pcds->cdar
  257. , sizeof(CDAREG));
  258. RegCloseKey(hkTmp);
  259. }
  260. if (pcds->DigitalEnabled)
  261. {
  262. pcds->fDigFlags |= CDROM_DIGITAL_PLAY_ENABLED;
  263. }
  264. else
  265. {
  266. pcds->fDigFlags &= ~CDROM_DIGITAL_PLAY_ENABLED;
  267. }
  268. bFlags = CDAudio_SetDigitalFlags(pcds,pcds->fDigFlags);
  269. //check for success
  270. if ((bFlags & CDROM_DIGITAL_PLAY_ENABLED) != (pcds->DigitalEnabled))
  271. {
  272. pcds->DigitalEnabled = bFlags & CDROM_DIGITAL_PLAY_ENABLED;
  273. Button_SetCheck(GetDlgItem(hwnd, IDC_CDEN_DIGAUDIO), pcds->DigitalEnabled);
  274. }
  275. }
  276. void ChangeCDVolume(PCDSTATE pcds)
  277. {
  278. MCI_OPEN_PARMS mciOpen;
  279. TCHAR szElementName[4];
  280. TCHAR szAliasName[32];
  281. DWORD dwFlags;
  282. DWORD dwAliasCount = GetCurrentTime();
  283. DWORD dwRet;
  284. CDAREG cdarCache;
  285. HKEY hkTmp;
  286. TCHAR szRegstrCDAudio[_MAX_PATH];
  287. ASSERT(pcds);
  288. if (pcds != NULL)
  289. {
  290. wsprintf(szRegstrCDAudio, gszUnitEnum, gszRegstrCDAPath, pcds->cdar.unit);
  291. if (RegOpenKeyEx(HKEY_LOCAL_MACHINE , szRegstrCDAudio , 0 , KEY_READ , &hkTmp ) == ERROR_SUCCESS)
  292. {
  293. DWORD cbCDA = sizeof(CDAREG);
  294. RegQueryValueEx(hkTmp , gszSettingsKey , NULL , NULL , (LPBYTE)&cdarCache , &cbCDA);
  295. RegCloseKey(hkTmp);
  296. }
  297. else
  298. {
  299. cdarCache = pcds->cdar;
  300. }
  301. if (RegCreateKeyEx(HKEY_LOCAL_MACHINE, szRegstrCDAudio, 0, NULL, 0, KEY_WRITE, NULL, &hkTmp, NULL ) == ERROR_SUCCESS)
  302. {
  303. CDAREG cdar;
  304. cdar = pcds->cdar;
  305. RegSetValueEx(hkTmp , gszSettingsKey , 0L , REG_BINARY , (LPBYTE)&cdar , sizeof(CDAREG));
  306. RegCloseKey(hkTmp);
  307. }
  308. ZeroMemory( &mciOpen, sizeof(mciOpen) );
  309. mciOpen.lpstrDeviceType = (LPTSTR)MCI_DEVTYPE_CD_AUDIO;
  310. wsprintf( szElementName, TEXT("%c:"), pcds->chDrive );
  311. wsprintf( szAliasName, TEXT("SJE%lu:"), dwAliasCount );
  312. mciOpen.lpstrElementName = szElementName;
  313. mciOpen.lpstrAlias = szAliasName;
  314. dwFlags = MCI_OPEN_ELEMENT | MCI_OPEN_ALIAS | MCI_OPEN_SHAREABLE |
  315. MCI_OPEN_TYPE | MCI_OPEN_TYPE_ID | MCI_WAIT;
  316. dwRet = mciSendCommand(0, MCI_OPEN, dwFlags, (DWORD_PTR)(LPVOID)&mciOpen);
  317. if ( dwRet == MMSYSERR_NOERROR )
  318. {
  319. mciSendCommand(mciOpen.wDeviceID, MCI_CLOSE, 0L, 0L );
  320. }
  321. if (RegOpenKeyEx(HKEY_LOCAL_MACHINE , szRegstrCDAudio , 0 , KEY_WRITE , &hkTmp ) == ERROR_SUCCESS)
  322. {
  323. RegSetValueEx(hkTmp , gszSettingsKey , 0L , REG_BINARY , (LPBYTE)&cdarCache , sizeof(CDAREG));
  324. RegCloseKey(hkTmp);
  325. }
  326. }
  327. }
  328. /*
  329. * */
  330. void CDAudio_SaveState(
  331. HWND hwnd)
  332. {
  333. PCDSTATE pcds;
  334. pcds = (PCDSTATE)GetWindowLongPtr(hwnd,DWLP_USER);
  335. if (pcds)
  336. {
  337. CDAudio_SetRegData(pcds,hwnd);
  338. pcds->oldDigEnabled = pcds->DigitalEnabled;
  339. pcds->dwOldVol = pcds->cdar.dwVol;
  340. ChangeCDVolume(pcds);
  341. }
  342. }
  343. void CDAudio_DigitalPlaybackEnable(HWND hDlg)
  344. {
  345. PCDSTATE pcds;
  346. pcds = (PCDSTATE)GetWindowLongPtr(hDlg,DWLP_USER);
  347. if (pcds)
  348. {
  349. pcds->DigitalEnabled = (BOOLEAN)Button_GetCheck(GetDlgItem(hDlg, IDC_CDEN_DIGAUDIO));
  350. }
  351. }
  352. ULONG MatchDriveToDevInst(DWORD DevInst)
  353. {
  354. HANDLE hMatch = INVALID_HANDLE_VALUE;
  355. STORAGE_DEVICE_NUMBER sDevice, sMatch;
  356. DWORD bytesReturned;
  357. ULONG uRet = 0;
  358. if (INVALID_HANDLE_VALUE != (hMatch =
  359. GetHandleForDeviceInst(DevInst)))
  360. {
  361. if (DeviceIoControl(hMatch,
  362. IOCTL_STORAGE_GET_DEVICE_NUMBER,
  363. NULL,
  364. 0,
  365. &sMatch,
  366. sizeof(STORAGE_DEVICE_NUMBER),
  367. &bytesReturned,
  368. NULL))
  369. {
  370. uRet = sMatch.DeviceNumber;
  371. }
  372. CloseHandle(hMatch);
  373. }
  374. return uRet;
  375. }
  376. /*
  377. * */
  378. DWORD CDAudio_InitDrives(HWND hwnd, PCDSTATE pcds)
  379. {
  380. DWORD cch;
  381. DWORD cCDs = 0;
  382. ULONG uDrive = 0;
  383. uDrive = MatchDriveToDevInst(pcds->pDevInfoData->DevInst);
  384. CDAudio_GetRegData(pcds,uDrive);
  385. if (cch = GetLogicalDriveStrings(0, NULL))
  386. {
  387. LPTSTR lpDrives,lp;
  388. lp = lpDrives = GlobalAllocPtr(GHND, cch * sizeof(TCHAR));
  389. cch = GetLogicalDriveStrings(cch, lpDrives);
  390. if (lpDrives && cch)
  391. {
  392. // upon the last drive enumerated, there will be a double
  393. // null termination
  394. while (*lpDrives)
  395. {
  396. if (GetDriveType(lpDrives) == DRIVE_CDROM)
  397. {
  398. int i;
  399. LPTSTR lp;
  400. lp = CharUpper(lpDrives);
  401. while (*lp != TEXT('\\'))
  402. lp = CharNext(lp);
  403. while (*lp)
  404. {
  405. *lp = TEXT(' ');
  406. lp = CharNext(lp);
  407. }
  408. if (cCDs == uDrive)
  409. {
  410. pcds->chDrive = lpDrives[0];
  411. }
  412. cCDs++;
  413. }
  414. for ( ; *lpDrives ; lpDrives++ );
  415. lpDrives++;
  416. }
  417. }
  418. if (lp)
  419. GlobalFreePtr(lp);
  420. }
  421. return cCDs;
  422. }
  423. //
  424. // Determines what device is currently being used by the mapper to play audio
  425. //
  426. MMRESULT GetWaveID(UINT *puWaveID)
  427. {
  428. PAUDIODLGINFO pInfo = (PAUDIODLGINFO)LocalAlloc(LPTR, sizeof(AUDIODLGINFO));;
  429. if (!pInfo) return MMSYSERR_NOMEM;
  430. GetPrefInfo(pInfo, NULL);
  431. if(-1 == pInfo->uPrefOut)
  432. {
  433. LocalFree((HLOCAL)pInfo);
  434. return MMSYSERR_BADDEVICEID;
  435. }
  436. *puWaveID = pInfo->uPrefOut;
  437. LocalFree((HLOCAL)pInfo);
  438. return MMSYSERR_NOERROR;
  439. }
  440. //
  441. // Checks to see if the current output audio device is a WDM Device or not
  442. //
  443. BOOL WDMAudioEnabled(void)
  444. {
  445. BOOL fResult = FALSE;
  446. UINT uWaveID;
  447. if (GetWaveID(&uWaveID) == MMSYSERR_NOERROR)
  448. {
  449. WAVEOUTCAPS woc;
  450. if (waveOutGetDevCaps(uWaveID, &woc, sizeof(WAVEOUTCAPS)) == MMSYSERR_NOERROR)
  451. {
  452. if ((woc.wMid == MM_MICROSOFT) && (woc.wPid == MM_MSFT_WDMAUDIO_WAVEOUT))
  453. {
  454. fResult = TRUE;
  455. }
  456. }
  457. }
  458. return(fResult);
  459. }
  460. BOOL CDAudio_OnInitDialog(
  461. HWND hwnd,
  462. HWND hwndFocus,
  463. LPARAM lParam)
  464. {
  465. HWND hwndTB1 = GetDlgItem(hwnd, IDC_CD_TB_VOLUME);
  466. HWND hwndCK3 = GetDlgItem(hwnd, IDC_CDEN_DIGAUDIO);
  467. HWND hwndTX1 = GetDlgItem(hwnd, IDC_TEXT_24);
  468. UINT uDrive;
  469. int i;
  470. PCDSTATE pcds = NULL;
  471. PALLDEVINFO pDevInfo = NULL;
  472. pcds = (PCDSTATE)GlobalAllocPtr(GHND, sizeof(CDSTATE));
  473. if (!pcds) return FALSE;
  474. SetWindowLongPtr(hwnd,DWLP_USER,(LONG_PTR)pcds);
  475. pDevInfo = (ALLDEVINFO *) ((LPPROPSHEETPAGE) lParam)->lParam;
  476. if (pDevInfo)
  477. {
  478. pcds->hDevInfo = pDevInfo->hDevInfo;
  479. pcds->pDevInfoData = pDevInfo->pDevInfoData;
  480. GlobalFreePtr(pDevInfo);
  481. ((LPPROPSHEETPAGE) lParam)->lParam = (LPARAM) NULL;
  482. }
  483. SendMessage(hwndTB1, TBM_SETTICFREQ, 10, 0);
  484. SendMessage(hwndTB1, TBM_SETRANGE, FALSE, MAKELONG(0,100));
  485. i = CDAudio_InitDrives(hwnd,pcds);
  486. if (i)
  487. {
  488. if (pcds)
  489. {
  490. SendMessage(hwndTB1, TBM_SETPOS, TRUE, (pcds->cdar.dwVol * 100L)/255L );
  491. Button_SetCheck(hwndCK3, pcds->DigitalEnabled);
  492. }
  493. g_fWDMEnabled = WDMAudioEnabled();
  494. // if (!g_fWDMEnabled) // Per bug 20964, never disable "Enable Digital CD" checkbox
  495. // {
  496. // EnableWindow(hwndCK3, FALSE);
  497. // EnableWindow(hwndTX1, FALSE);
  498. // }
  499. }
  500. // else
  501. // {
  502. // EnableWindow(hwndCK3, FALSE);
  503. // EnableWindow(hwndTB1, FALSE);
  504. // EnableWindow(hwndTX1, FALSE);
  505. // }
  506. return FALSE;
  507. }
  508. void CDToggleApply(HWND hDlg)
  509. {
  510. PCDSTATE pcds;
  511. BOOL fChanged = FALSE;
  512. pcds = (PCDSTATE)GetWindowLongPtr(hDlg,DWLP_USER);
  513. if (pcds)
  514. {
  515. if (pcds->DigitalEnabled != pcds->oldDigEnabled)
  516. {
  517. fChanged = TRUE;
  518. }
  519. if (pcds->dwOldVol != pcds->cdar.dwVol)
  520. {
  521. fChanged = TRUE;
  522. }
  523. }
  524. if (fChanged)
  525. {
  526. PropSheet_Changed(GetParent(hDlg),hDlg);
  527. }
  528. else
  529. {
  530. PropSheet_UnChanged(GetParent(hDlg),hDlg);
  531. }
  532. }
  533. void CDAudio_OnDestroy(
  534. HWND hwnd)
  535. {
  536. PCDSTATE lp = (PCDSTATE)GetWindowLongPtr(hwnd,DWLP_USER);
  537. if (lp)
  538. GlobalFreePtr(lp);
  539. if (g_hModStorProp)
  540. {
  541. FreeLibrary(g_hModStorProp);
  542. g_hModStorProp = NULL;
  543. }
  544. }
  545. void CDAudio_OnHScroll(
  546. HWND hwnd,
  547. HWND hwndCtl,
  548. UINT code,
  549. int pos)
  550. {
  551. if (code == TB_ENDTRACK || code == SB_THUMBTRACK)
  552. {
  553. HWND hwndTB1 = GetDlgItem(hwnd, IDC_CD_TB_VOLUME);
  554. int i;
  555. PCDSTATE pcds;
  556. DWORD dwVol;
  557. pcds = (PCDSTATE)GetWindowLongPtr(hwnd,DWLP_USER);
  558. if (CB_ERR != (UINT_PTR) pcds && pcds)
  559. {
  560. dwVol = (((DWORD)SendMessage(hwndTB1, TBM_GETPOS, 0, 0)) * 255L) / 100L;
  561. if (dwVol != pcds->cdar.dwVol)
  562. {
  563. pcds->cdar.dwVol = dwVol;
  564. ChangeCDVolume(pcds);
  565. CDToggleApply(hwnd);
  566. }
  567. }
  568. }
  569. }
  570. void CDAudio_OnCancel(
  571. HWND hwnd)
  572. {
  573. PCDSTATE pcds;
  574. pcds = (PCDSTATE)GetWindowLongPtr(hwnd,DWLP_USER);
  575. pcds->cdar.dwVol = pcds->dwOldVol;
  576. ChangeCDVolume(pcds);
  577. }
  578. BOOL PASCAL CDAudio_OnCommand(
  579. HWND hDlg,
  580. int id,
  581. HWND hwndCtl,
  582. UINT codeNotify)
  583. {
  584. BOOL fResult = FALSE;
  585. switch (id)
  586. {
  587. case ID_APPLY:
  588. {
  589. CDAudio_SaveState(hDlg);
  590. fResult = TRUE;
  591. }
  592. break;
  593. case IDCANCEL:
  594. {
  595. CDAudio_OnCancel(hDlg);
  596. fResult = TRUE;
  597. }
  598. break;
  599. case IDC_CDEN_DIGAUDIO:
  600. {
  601. CDAudio_DigitalPlaybackEnable(hDlg);
  602. CDToggleApply(hDlg);
  603. }
  604. break;
  605. }
  606. return fResult;
  607. }
  608. const static DWORD aCDHelpIds[] = { // Context Help IDs
  609. IDI_CDAUDIO, IDH_COMM_GROUPBOX,
  610. IDC_ICON_5, IDH_COMM_GROUPBOX,
  611. IDC_TEXT_25, IDH_COMM_GROUPBOX,
  612. IDC_GROUPBOX, IDH_COMM_GROUPBOX,
  613. IDC_GROUPBOX_2, IDH_COMM_GROUPBOX,
  614. IDC_TEXT_29, IDH_CD_VOL_HEADPHONE,
  615. IDC_CD_TB_VOLUME, IDH_CD_VOL_HEADPHONE,
  616. IDC_TEXT_30, IDH_CD_VOL_HEADPHONE,
  617. IDC_TEXT_24, IDH_CDROM_PROPERTIES_DIGITAL,
  618. IDC_CDEN_DIGAUDIO, IDH_CDROM_PROPERTIES_DIGITAL,
  619. 0, 0
  620. };
  621. BOOL CALLBACK CDDlg(
  622. HWND hDlg,
  623. UINT uMsg,
  624. WPARAM wParam,
  625. LPARAM lParam)
  626. {
  627. NMHDR FAR *lpnm;
  628. switch (uMsg)
  629. {
  630. case WM_NOTIFY:
  631. lpnm = (NMHDR FAR *)lParam;
  632. switch(lpnm->code)
  633. {
  634. case PSN_KILLACTIVE:
  635. FORWARD_WM_COMMAND(hDlg, IDOK, 0, 0, SendMessage);
  636. break;
  637. case PSN_APPLY:
  638. FORWARD_WM_COMMAND(hDlg, ID_APPLY, 0, 0, SendMessage);
  639. break;
  640. case PSN_SETACTIVE:
  641. FORWARD_WM_COMMAND(hDlg, ID_INIT, 0, 0, SendMessage);
  642. break;
  643. case PSN_RESET:
  644. FORWARD_WM_COMMAND(hDlg, IDCANCEL, 0, 0, SendMessage);
  645. break;
  646. }
  647. break;
  648. case WM_INITDIALOG:
  649. HANDLE_WM_INITDIALOG(hDlg, wParam, lParam, CDAudio_OnInitDialog);
  650. break;
  651. case WM_DESTROY:
  652. HANDLE_WM_DESTROY(hDlg, wParam, lParam, CDAudio_OnDestroy);
  653. break;
  654. case WM_DROPFILES:
  655. break;
  656. case WM_CONTEXTMENU:
  657. WinHelp((HWND)wParam, gszWindowsHlp, HELP_CONTEXTMENU,
  658. (UINT_PTR)(LPTSTR)aCDHelpIds);
  659. break;
  660. case WM_HELP:
  661. WinHelp(((LPHELPINFO)lParam)->hItemHandle, gszWindowsHlp,
  662. HELP_WM_HELP, (UINT_PTR)(LPTSTR)aCDHelpIds);
  663. break;
  664. case WM_COMMAND:
  665. HANDLE_WM_COMMAND(hDlg, wParam, lParam, CDAudio_OnCommand);
  666. break;
  667. case WM_HSCROLL:
  668. HANDLE_WM_HSCROLL(hDlg, wParam, lParam, CDAudio_OnHScroll);
  669. break;
  670. #if 0
  671. default:
  672. if (uMsg == wHelpMessage)
  673. {
  674. WinHelp(hDlg, gszWindowsHlp, HELP_CONTEXT, ID_SND_HELP);
  675. return TRUE;
  676. }
  677. break;
  678. #endif
  679. }
  680. return FALSE;
  681. }