Windows NT 4.0 source code leak
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.

1698 lines
46 KiB

4 years ago
  1. /****************************************************************************
  2. *
  3. * config.c
  4. *
  5. * Copyright (c) Microsoft Corporation 1993-1994. All rights reserved.
  6. *
  7. ***************************************************************************/
  8. #include <windows.h>
  9. #include <windowsx.h>
  10. #include <mmsystem.h>
  11. #include <commctrl.h>
  12. #include <drvlib.h>
  13. #include <registry.h>
  14. #include "driver.h"
  15. #include <stdlib.h>
  16. TCHAR STR_PRODUCTNAME[] = TEXT("Sound Blaster");
  17. #define INVALID_DSP_VERSION ((DWORD)-1)
  18. /****************************************************************************
  19. typedefs
  20. ***************************************************************************/
  21. typedef struct {
  22. UINT CardId; // Card number
  23. DWORD Port; // Port number
  24. DWORD MPU401Port; // MPU401 Port number
  25. DWORD Interrupt; // Interrupt
  26. DWORD DmaChannel; // Dma Channel number
  27. DWORD DmaChannel16; // Dma Channel number for 16-bit record
  28. DWORD LoadType; // Normal or configuration
  29. DWORD DmaBufferSize; // Size for DMA buffer
  30. DWORD SynthType; // Opl3?
  31. } SB_CONFIG, *PSB_CONFIG;
  32. /************************
  33. Globals
  34. *************************/
  35. DWORD CurrentCard;
  36. DWORD NumberOfCards;
  37. DWORD DSPVersion;
  38. SB_CONFIG Configuration;
  39. DWORD InterruptsInUse;
  40. DWORD DmaChannelsInUse;
  41. BOOL FirstTime;
  42. WNDPROC OldButtonProc;
  43. WNDPROC OldComboProc;
  44. HFONT g_hDlgFont;
  45. TCHAR g_szAppFontName[] = TEXT("MS Shell Dlg");
  46. RECT g_OrgRect[MAX_IDDS];
  47. RECT g_OrgRectDlg;
  48. /*****************************************************************************
  49. internal function prototypes
  50. ****************************************************************************/
  51. int Configure(HWND hDlg);
  52. BOOL CenterPopup(HWND hWnd, HWND hParentWnd);
  53. VOID GetDriverConfig(UINT CardId, PSB_CONFIG Config);
  54. BOOL SetDriverConfig(PSB_CONFIG Config);
  55. LRESULT CALLBACK
  56. ButtonSubClassProc(
  57. HWND hwnd,
  58. UINT uMsg,
  59. WPARAM wParam,
  60. LPARAM lParam
  61. );
  62. LRESULT CALLBACK
  63. ComboBoxSubClassProc(
  64. HWND hwnd,
  65. UINT uMsg,
  66. WPARAM wParam,
  67. LPARAM lParam
  68. );
  69. BOOL
  70. Config_OnInitDialog(
  71. HWND hwnd,
  72. HWND hwndFocus,
  73. LPARAM lParam
  74. );
  75. void
  76. Config_OnCommand(
  77. HWND hwnd,
  78. int id,
  79. HWND hwndCtl,
  80. UINT codeNotify
  81. );
  82. void
  83. PrintHelpText(
  84. HWND hwnd
  85. );
  86. void
  87. ResizeDialog(
  88. HWND hwnd
  89. );
  90. void
  91. SetDialogTitle(
  92. HWND hwnd
  93. );
  94. void
  95. GetOriginalControlPositions(
  96. HWND hwnd
  97. );
  98. /*
  99. ** Set the configuration to invalid - this will stop SetDriverConfig writing
  100. ** things we didn't set
  101. */
  102. VOID InitConfiguration(PSB_CONFIG Config)
  103. {
  104. Config->Port = (DWORD)-1;
  105. Config->MPU401Port = (DWORD)-2;
  106. Config->Interrupt = (DWORD)-1;
  107. Config->DmaChannel = (DWORD)-1;
  108. Config->DmaChannel16 = SOUND_DEF_DMACHANNEL16;
  109. Config->DmaBufferSize = (DWORD)-1;
  110. Config->SynthType = (DWORD)-1;
  111. }
  112. /*****************************************************************************
  113. ConfigRemove()
  114. *****************************************************************************/
  115. LRESULT ConfigRemove(HWND hDlg)
  116. {
  117. BOOL Unloaded;
  118. BOOL Deleted;
  119. //
  120. // Is the driver currently loaded
  121. //
  122. if (!DrvIsDriverLoaded(&RegAccess)) {
  123. DrvDeleteServicesNode(&RegAccess); // Just in case
  124. return DRVCNF_OK;
  125. }
  126. //
  127. // Try to unload the driver
  128. //
  129. Unloaded = DrvUnloadKernelDriver(&RegAccess);
  130. //
  131. // Remove the driver entry from the registry
  132. //
  133. Deleted = DrvDeleteServicesNode(&RegAccess);
  134. if (Unloaded && Deleted) {
  135. return DRVCNF_RESTART;
  136. } else {
  137. if (Deleted) {
  138. return DRVCNF_OK;
  139. } else {
  140. /*
  141. * Tell the user there's a problem
  142. */
  143. ConfigErrorMsgBox( hDlg, IDS_FAILREMOVE );
  144. return DRVCNF_CANCEL;
  145. }
  146. }
  147. }
  148. /**********************************************************************
  149. *
  150. * Determine which dialogue to use based upon the DSP version
  151. *
  152. **********************************************************************/
  153. DWORD VersionToDlgId(DWORD DSPVersion)
  154. {
  155. DWORD DialogId;
  156. if (DSPVersion == INVALID_DSP_VERSION) {
  157. return (DLG_PORTSELECT);
  158. }
  159. if (DSPVersion < 0x200) {
  160. DialogId = (DLG_SB1CONFIG);
  161. } else {
  162. if (DSPVersion == 0x200) {
  163. DialogId = (DLG_SB15CONFIG);
  164. } else {
  165. if (DSPVersion < 0x0300) {
  166. DialogId = (DLG_SB20CONFIG);
  167. } else {
  168. if (DSPVersion < 0x400) {
  169. DialogId = (DLG_SBPROCONFIG);
  170. } else {
  171. DialogId = (DLG_SB16CONFIG);
  172. }
  173. }
  174. }
  175. }
  176. return DialogId;
  177. }
  178. /*
  179. ** Work out the default DMA buffer size. Anything less than
  180. ** an SB16 really only needs 4K because the most that can be done is
  181. ** 44Khz mono (or 22Khz stereo). This gets multiplied by 4 for the 16.
  182. */
  183. DWORD DefaultDmaBufferSize(DWORD DSPVersion)
  184. {
  185. if (DSPVersion == INVALID_DSP_VERSION) {
  186. return (DWORD)-1;
  187. }
  188. if (DSPVersion < 0x400) {
  189. return 0x1000; // 4K
  190. } else {
  191. return 0x4000; // 16K
  192. }
  193. }
  194. /****************************************************************************
  195. * @doc INTERNAL
  196. *
  197. * @api int | Config | This puts up the configuration dialog box.
  198. *
  199. * @parm HWND | hWnd | Our Window handle.
  200. *
  201. * @parm HANDLE | hInstance | Our instance handle.
  202. *
  203. * @rdesc Returns whatever was returned from the dialog box procedure.
  204. ***************************************************************************/
  205. int Config(HWND hWnd, HANDLE hInstance)
  206. {
  207. BOOL ReturnCode;
  208. BOOL DriverWasLoaded;
  209. SB_CONFIG InitConfig;
  210. DSPVersion = INVALID_DSP_VERSION;
  211. FirstTime = TRUE;
  212. /*
  213. ** Find out what stuff is in use!
  214. */
  215. GetInterruptsAndDMA(&InterruptsInUse, &DmaChannelsInUse, STR_DRIVERNAME);
  216. DriverWasLoaded = DrvIsDriverLoaded(&RegAccess);
  217. CurrentCard = 0;
  218. DrvNumberOfDevices(&RegAccess, &NumberOfCards);
  219. if (!bInstall && NumberOfCards != 0) {
  220. DSPVersion = INVALID_DSP_VERSION;
  221. DrvQueryDeviceIdParameter(
  222. &RegAccess,
  223. CurrentCard,
  224. SOUND_REG_DSP_VERSION,
  225. &DSPVersion );
  226. }
  227. if (!bInstall) {
  228. // Save configuration in case Dialog is cancelled
  229. GetDriverConfig(CurrentCard, &InitConfig);
  230. }
  231. if (NumberOfCards == 0) {
  232. HKEY hKey;
  233. hKey = DrvCreateDeviceKey(RegAccess.DriverName);
  234. RegCloseKey(hKey);
  235. DrvNumberOfDevices(&RegAccess, &NumberOfCards);
  236. if (NumberOfCards == 0) {
  237. ConfigErrorMsgBox(hWnd, IDS_ERROR_UNKNOWN);
  238. return DRVCNF_CANCEL;
  239. }
  240. }
  241. ReturnCode = DialogBox( hInstance,
  242. MAKEINTRESOURCE(DLG_SB16CONFIG),
  243. hWnd,
  244. (DLGPROC)ConfigDlgProc );
  245. if (ReturnCode == DRVCNF_CANCEL) {
  246. if (bInstall) {
  247. DrvRemoveDriver(&RegAccess);
  248. } else {
  249. SetDriverConfig(&InitConfig);
  250. if (DriverWasLoaded) {
  251. DrvConfigureDriver(&RegAccess,
  252. STR_DRIVERNAME,
  253. SoundDriverTypeNormal,
  254. NULL,
  255. NULL);
  256. }
  257. }
  258. }
  259. return ReturnCode;
  260. }
  261. /****************************************************************************
  262. *
  263. * GetDriverConfig
  264. *
  265. * Parameters:
  266. *
  267. * UINT CardId
  268. *
  269. * PAS_CONFIG * Config
  270. *
  271. * Returns:
  272. *
  273. * Config copied into Config (unobtainable values set to (DWORD)-1)
  274. *
  275. ****************************************************************************/
  276. VOID GetDriverConfig(UINT CardId, PSB_CONFIG Config)
  277. {
  278. Config->CardId = CardId;
  279. /*
  280. ** Set up the defaults in case we get nothing from the registry
  281. */
  282. InitConfiguration(Config);
  283. DrvQueryDeviceIdParameter(&RegAccess,
  284. CardId,
  285. SOUND_REG_PORT,
  286. &Config->Port);
  287. DrvQueryDeviceIdParameter(&RegAccess,
  288. CardId,
  289. SOUND_REG_MPU401_PORT,
  290. &Config->MPU401Port);
  291. DrvQueryDeviceIdParameter(&RegAccess,
  292. CardId,
  293. SOUND_REG_INTERRUPT,
  294. &Config->Interrupt);
  295. if (Config->Interrupt == 9) {
  296. Config->Interrupt = 2;
  297. }
  298. DrvQueryDeviceIdParameter(&RegAccess,
  299. CardId,
  300. SOUND_REG_DMACHANNEL,
  301. &Config->DmaChannel);
  302. DrvQueryDeviceIdParameter(&RegAccess,
  303. CardId,
  304. SOUND_REG_DMACHANNEL16,
  305. &Config->DmaChannel16);
  306. DrvQueryDeviceIdParameter(&RegAccess,
  307. CardId,
  308. SOUND_REG_DMABUFFERSIZE,
  309. &Config->DmaBufferSize);
  310. DrvQueryDeviceIdParameter(&RegAccess,
  311. CardId,
  312. SOUND_REG_SYNTH_TYPE,
  313. &Config->SynthType);
  314. }
  315. /****************************************************************************
  316. * @doc INTERNAL
  317. *
  318. * @api BOOL | SetDriverConfig | Callback to set config info in the registry
  319. * does not write uninitialized values (-1)
  320. *
  321. * @parm PVOID | Context | Our context.
  322. *
  323. * @rdesc Returns TRUE if success, FALSE otherwise.
  324. ***************************************************************************/
  325. BOOL SetDriverConfig(PSB_CONFIG Config)
  326. {
  327. /* We set the DMA channel and interrupt values */
  328. /* and set the returned version to 0 */
  329. /* */
  330. /* If any of these calls fail then give up */
  331. if (Config->DmaChannel != (DWORD)-1 &&
  332. DrvSetDeviceIdParameter(
  333. &RegAccess,
  334. Config->CardId,
  335. SOUND_REG_DMACHANNEL,
  336. Config->DmaChannel) != ERROR_SUCCESS ||
  337. DrvSetDeviceIdParameter(
  338. &RegAccess,
  339. Config->CardId,
  340. SOUND_REG_DMACHANNEL16,
  341. Config->DmaChannel16) != ERROR_SUCCESS ||
  342. Config->Port != (DWORD)-1 &&
  343. DrvSetDeviceIdParameter(
  344. &RegAccess,
  345. Config->CardId,
  346. SOUND_REG_PORT,
  347. Config->Port) != ERROR_SUCCESS ||
  348. DrvSetDeviceIdParameter(
  349. &RegAccess,
  350. Config->CardId,
  351. SOUND_REG_MPU401_PORT,
  352. Config->MPU401Port) != ERROR_SUCCESS ||
  353. Config->Interrupt != (DWORD)-1 &&
  354. DrvSetDeviceIdParameter(
  355. &RegAccess,
  356. Config->CardId,
  357. SOUND_REG_INTERRUPT,
  358. Config->Interrupt == 2 ? 9 : Config->Interrupt) != ERROR_SUCCESS ||
  359. Config->DmaBufferSize != (DWORD)-1 &&
  360. DrvSetDeviceIdParameter(
  361. &RegAccess,
  362. Config->CardId,
  363. SOUND_REG_DMABUFFERSIZE,
  364. Config->DmaBufferSize) != ERROR_SUCCESS ||
  365. /*
  366. ** Initialize the DSP version
  367. */
  368. DrvSetDeviceIdParameter(
  369. &RegAccess,
  370. Config->CardId,
  371. SOUND_REG_DSP_VERSION,
  372. INVALID_DSP_VERSION) != ERROR_SUCCESS ||
  373. DrvSetDeviceIdParameter(
  374. &RegAccess,
  375. Config->CardId,
  376. SOUND_REG_LOADTYPE,
  377. Config->LoadType != ERROR_SUCCESS)) {
  378. return FALSE;
  379. } else {
  380. return TRUE;
  381. }
  382. }
  383. VOID SetItem(HWND hDlg, UINT Combo, DWORD Value, DWORD Current)
  384. {
  385. LRESULT Index;
  386. TCHAR String[20];
  387. HWND hwndCombo;
  388. hwndCombo = GetDlgItem(hDlg, Combo);
  389. if (hwndCombo == NULL) {
  390. //
  391. // This can happen since we share some code between dialogs
  392. return;
  393. }
  394. if (Value == (DWORD)-1) {
  395. LoadString(ghModule, IDS_DISABLED, String, sizeof(String) / sizeof(String[0]));
  396. } else {
  397. wsprintf(String, Combo == IDD_IRQCB ? TEXT("%d") : TEXT("%X"), Value);
  398. }
  399. Index = ComboBox_AddString(hwndCombo, String);
  400. if (Value == Current || Index == 0) {
  401. ComboBox_SetCurSel(hwndCombo, Index);
  402. }
  403. ComboBox_SetItemData(hwndCombo, Index, Value);
  404. }
  405. BOOL PortItem(HWND hDlg, UINT Combo, DWORD Value, LPDWORD Current)
  406. {
  407. SetItem(hDlg, Combo, Value, *Current);
  408. return TRUE;
  409. }
  410. BOOL DMAItem(HWND hDlg, UINT Combo, DWORD Value, LPDWORD Current)
  411. {
  412. if (*Current != (DWORD)-1 && (DmaChannelsInUse & (1 << *Current))) {
  413. if (Value != (DWORD)-1 && !(DmaChannelsInUse & (1 << Value))) {
  414. *Current = Value;
  415. }
  416. }
  417. SetItem(hDlg, Combo, Value, *Current);
  418. return TRUE;
  419. }
  420. BOOL InterruptItem(HWND hDlg, UINT Combo, DWORD Value, LPDWORD Current)
  421. {
  422. if (InterruptsInUse & (1 << *Current)) {
  423. if (!(InterruptsInUse & (1 << Value))) {
  424. *Current = Value;
  425. }
  426. }
  427. SetItem(hDlg, Combo, Value, *Current);
  428. return TRUE;
  429. }
  430. DWORD GetCurrentValue(HWND hDlg, UINT Combo)
  431. {
  432. HWND hwndCombo;
  433. hwndCombo = GetDlgItem(hDlg, Combo);
  434. if (hwndCombo == NULL) {
  435. /*
  436. ** -1 means nothing there
  437. */
  438. return (DWORD)-1;
  439. }
  440. return ComboBox_GetItemData(hwndCombo, ComboBox_GetCurSel(hwndCombo));
  441. }
  442. /*
  443. ** Get the configuration the user has entered and put it in the
  444. ** registry
  445. */
  446. BOOL
  447. SetCurrentConfig(HWND hDlg, UINT CardId, PSB_CONFIG Config)
  448. {
  449. Config->CardId = CardId;
  450. /*
  451. ** Get the new configuration which the user entered
  452. */
  453. Config->Port = GetCurrentValue(hDlg, IDD_IOADDRESSCB);
  454. if (Config->Port == (DWORD)-1) {
  455. Config->Port = SOUND_DEF_PORT;
  456. }
  457. Config->LoadType = DSPVersion == INVALID_DSP_VERSION ?
  458. SOUND_LOADTYPE_CONFIG :
  459. SOUND_LOADTYPE_NORMAL;
  460. Config->MPU401Port = GetCurrentValue(hDlg, IDD_MPU401IOADDRESSCB);
  461. Config->Interrupt = GetCurrentValue(hDlg, IDD_IRQCB);
  462. if (Config->Interrupt == (DWORD)-1) {
  463. Config->Interrupt = SOUND_DEF_INT;
  464. } else
  465. if (Config->Interrupt == 2) {
  466. Config->Interrupt = 9;
  467. }
  468. Config->DmaChannel = GetCurrentValue(hDlg, IDD_DMACB);
  469. if (Config->DmaChannel == (DWORD)-1) {
  470. Config->DmaChannel = SOUND_DEF_DMACHANNEL;
  471. }
  472. Config->DmaChannel16 = GetCurrentValue(hDlg, IDD_DMA16CB);
  473. Config->DmaBufferSize = (DWORD)GetWindowLong(hDlg, DWL_USER);
  474. if (Config->DmaBufferSize == (DWORD)-1) {
  475. Config->DmaBufferSize = DefaultDmaBufferSize(DSPVersion);
  476. }
  477. /*
  478. ** Write it to the registry for the driver
  479. */
  480. SetDriverConfig(Config);
  481. return TRUE;
  482. }
  483. /*
  484. ** Switch to a new card
  485. */
  486. BOOL SetupDialog(HWND hDlg, UINT CardId )
  487. {
  488. GetDriverConfig(CardId, &Configuration);
  489. /*
  490. ** First reset the combo boxes contents
  491. */
  492. ComboBox_ResetContent( GetDlgItem(hDlg, IDD_IOADDRESSCB));
  493. /*
  494. ** Fill our combo boxes
  495. */
  496. if (Configuration.Port == (DWORD)-1) {
  497. Configuration.Port = SOUND_DEF_PORT; // 0x220
  498. }
  499. PortItem(hDlg, IDD_IOADDRESSCB, 0x210, &Configuration.Port);
  500. PortItem(hDlg, IDD_IOADDRESSCB, 0x220, &Configuration.Port);
  501. PortItem(hDlg, IDD_IOADDRESSCB, 0x230, &Configuration.Port);
  502. PortItem(hDlg, IDD_IOADDRESSCB, 0x240, &Configuration.Port);
  503. PortItem(hDlg, IDD_IOADDRESSCB, 0x250, &Configuration.Port);
  504. PortItem(hDlg, IDD_IOADDRESSCB, 0x260, &Configuration.Port);
  505. PortItem(hDlg, IDD_IOADDRESSCB, 0x270, &Configuration.Port);
  506. PortItem(hDlg, IDD_IOADDRESSCB, 0x280, &Configuration.Port);
  507. {
  508. TCHAR szPort[10];
  509. wsprintf(szPort, TEXT("%X"), Configuration.Port);
  510. SetWindowText(GetDlgItem(hDlg, IDD_IOADDRESSCB_S), szPort);
  511. }
  512. if (Configuration.Interrupt == (DWORD)-1) {
  513. Configuration.Interrupt = SOUND_DEF_INT; //7
  514. }
  515. ComboBox_ResetContent( GetDlgItem(hDlg, IDD_IRQCB));
  516. InterruptItem(hDlg, IDD_IRQCB, 0x02, &Configuration.Interrupt);
  517. if (DSPVersion < 0x0300) {
  518. InterruptItem(hDlg, IDD_IRQCB, 0x03, &Configuration.Interrupt);
  519. }
  520. InterruptItem(hDlg, IDD_IRQCB, 0x05, &Configuration.Interrupt);
  521. InterruptItem(hDlg, IDD_IRQCB, 0x07, &Configuration.Interrupt);
  522. if (DSPVersion >= 0x0300) {
  523. InterruptItem(hDlg, IDD_IRQCB, 0x0A, &Configuration.Interrupt);
  524. }
  525. if (Configuration.DmaChannel == (DWORD)-1) {
  526. Configuration.DmaChannel = 1;
  527. }
  528. ComboBox_ResetContent( GetDlgItem(hDlg, IDD_DMACB));
  529. DMAItem(hDlg, IDD_DMACB, 0x00, &Configuration.DmaChannel);
  530. DMAItem(hDlg, IDD_DMACB, 0x01, &Configuration.DmaChannel);
  531. DMAItem(hDlg, IDD_DMACB, 0x03, &Configuration.DmaChannel);
  532. ComboBox_ResetContent( GetDlgItem(hDlg, IDD_DMA16CB));
  533. DMAItem(hDlg, IDD_DMA16CB, 0x05, &Configuration.DmaChannel16);
  534. DMAItem(hDlg, IDD_DMA16CB, 0x06, &Configuration.DmaChannel16);
  535. DMAItem(hDlg, IDD_DMA16CB, 0x07, &Configuration.DmaChannel16);
  536. DMAItem(hDlg, IDD_DMA16CB, (DWORD)-1, &Configuration.DmaChannel16);
  537. ComboBox_ResetContent( GetDlgItem(hDlg, IDD_MPU401IOADDRESSCB));
  538. if (Configuration.MPU401Port == (DWORD)-2) {
  539. Configuration.MPU401Port = SOUND_DEF_MPU401_PORT;
  540. }
  541. PortItem(hDlg, IDD_MPU401IOADDRESSCB, 0x300, &Configuration.MPU401Port);
  542. PortItem(hDlg, IDD_MPU401IOADDRESSCB, 0x330, &Configuration.MPU401Port);
  543. PortItem(hDlg, IDD_MPU401IOADDRESSCB, (DWORD)-1, &Configuration.MPU401Port);
  544. SetWindowLong(hDlg, DWL_USER, (LONG)Configuration.DmaBufferSize);
  545. {
  546. TCHAR OKString[30];
  547. TCHAR IOAddressString[30];
  548. LoadString(ghModule,
  549. DSPVersion == INVALID_DSP_VERSION ?
  550. IDS_DETECT :
  551. IDS_OK,
  552. OKString,
  553. sizeof(OKString) / sizeof(OKString[0]));
  554. LoadString(ghModule,
  555. DSPVersion == INVALID_DSP_VERSION ?
  556. IDS_PORT_ADDRESS_SELECT :
  557. IDS_PORT_ADDRESS,
  558. IOAddressString,
  559. sizeof(IOAddressString) / sizeof(IOAddressString[0]));
  560. SetWindowText(GetDlgItem(hDlg, IDOK), OKString);
  561. SetWindowText(GetDlgItem(hDlg, IDD_IOADDRESSCB_T), IOAddressString);
  562. }
  563. return TRUE;
  564. }
  565. //------------------------------------------------------------------------
  566. // int AdvancedDlgProc
  567. //
  568. // Description:
  569. // Dialog procedure for the configuration dialog box.
  570. //
  571. // Parameters:
  572. // HWND hDlg
  573. // handle to configuration dialog box
  574. //
  575. // UINT uMsg
  576. // message
  577. //
  578. // WPARAM wParam
  579. // message dependent parameter
  580. //
  581. // LPARAM lParam
  582. // message dependent parameter
  583. //
  584. // Return Value:
  585. // DRV_OK on success, otherwise DRV_CANCEL
  586. //
  587. //------------------------------------------------------------------------
  588. BOOL CALLBACK AdvancedDlgProc
  589. (
  590. HWND hDlg,
  591. UINT uMsg,
  592. WPARAM wParam,
  593. LPARAM lParam
  594. )
  595. {
  596. /*
  597. ** The most we'll use for a DMA buffer in the kernel driver is 1/8th of
  598. ** as second at 176KBytes per second = approx 22K. For non-16bit
  599. ** cards the most we'll use is 6K
  600. */
  601. #define MAX_DMA_BUFFER_SIZE (DSPVersion < 0x400 ? 6 : 22)
  602. switch ( uMsg )
  603. {
  604. case WM_INITDIALOG:
  605. {
  606. LONG BufferSize;
  607. BufferSize = GetWindowLong(GetParent(hDlg), DWL_USER);
  608. if (BufferSize == -1L) {
  609. BufferSize = DefaultDmaBufferSize(DSPVersion);
  610. }
  611. /*
  612. ** Center the Dialog Box
  613. */
  614. SendDlgItemMessage( hDlg, IDD_DMABUFFERSC, UDM_SETRANGE, 0,
  615. MAKELPARAM(MAX_DMA_BUFFER_SIZE, 4) );
  616. CenterPopup( hDlg, GetParent(hDlg) );
  617. SetDlgItemInt( hDlg,
  618. IDD_DMABUFFEREC,
  619. BufferSize / 0x400,
  620. FALSE ) ;
  621. }
  622. break ;
  623. case WM_CLOSE:
  624. EndDialog( hDlg, DRV_CANCEL ) ;
  625. break ;
  626. case WM_COMMAND:
  627. switch ( wParam )
  628. {
  629. #if 0
  630. case IDD_HELPADV:
  631. WinHelp( hDlg, gszHelpFile, HELP_CONTEXT, 6000 ) ;
  632. break ;
  633. #endif
  634. case IDOK:
  635. {
  636. BOOL fWasted ;
  637. int nDMABufferSize ;
  638. nDMABufferSize =
  639. (DWORD) GetDlgItemInt( hDlg, IDD_DMABUFFEREC,
  640. &fWasted, TRUE );
  641. if ((nDMABufferSize < 4) || (nDMABufferSize > MAX_DMA_BUFFER_SIZE))
  642. {
  643. ConfigErrorMsgBox( hDlg,
  644. IDS_BADDMABUFFERSIZE,
  645. MAX_DMA_BUFFER_SIZE ) ;
  646. return ( FALSE ) ;
  647. }
  648. SetWindowLong(GetParent(hDlg), DWL_USER, nDMABufferSize * 0x400);
  649. EndDialog( hDlg, TRUE ) ;
  650. }
  651. break ;
  652. case IDCANCEL:
  653. EndDialog(hDlg, FALSE ) ;
  654. break ;
  655. default:
  656. break ;
  657. }
  658. break ;
  659. default:
  660. return FALSE ;
  661. }
  662. return TRUE ;
  663. } // end of AdvancedDlgProc()
  664. /****************************************************************************
  665. * @doc INTERNAL
  666. *
  667. * @api int | ConfigDlgProc | Dialog proc for the configuration dialog box.
  668. *
  669. * @parm HWND | hDlg | Handle to the configuration dialog box.
  670. *
  671. * @parm WORD | msg | Message sent to the dialog box.
  672. *
  673. * @parm WORD | wParam | Message dependent parameter.
  674. *
  675. * @parm LONG | lParam | Message dependent parameter.
  676. *
  677. * @rdesc Returns DRV_RESTART if the user has changed settings, which will
  678. * cause the drivers applet which launched this to give the user a
  679. * message about having to restart Windows for the changes to take
  680. * effect. If the user clicks on "Cancel" or if no settings have changed,
  681. * DRV_CANCEL is returned.
  682. ***************************************************************************/
  683. int ConfigDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
  684. {
  685. switch (msg) {
  686. HANDLE_MSG( hwnd, WM_INITDIALOG, Config_OnInitDialog );
  687. HANDLE_MSG( hwnd, WM_COMMAND, Config_OnCommand );
  688. default:
  689. return FALSE;
  690. }
  691. return TRUE;
  692. }
  693. /*****************************Private*Routine******************************\
  694. * Config_OnInitDialog
  695. *
  696. *
  697. *
  698. * History:
  699. * 18-11-93 - StephenE - Created
  700. *
  701. \**************************************************************************/
  702. BOOL
  703. Config_OnInitDialog(
  704. HWND hwnd,
  705. HWND hwndFocus,
  706. LPARAM lParam
  707. )
  708. {
  709. LOGFONT lf;
  710. int iLogPelsY;
  711. HDC hdc;
  712. D3(("ConfigDlgProc() - WM_INITDIALOG"));
  713. hdc = GetDC( hwnd );
  714. iLogPelsY = GetDeviceCaps( hdc, LOGPIXELSY );
  715. ReleaseDC( hwnd, hdc );
  716. ZeroMemory( &lf, sizeof(lf) );
  717. #ifdef JAPAN
  718. //fix kksuzuka: #2562
  719. lf.lfHeight = (-10 * iLogPelsY) / 72; /* 10pt */
  720. lf.lfWeight = 400; /* normal */
  721. lf.lfCharSet = SHIFTJIS_CHARSET;
  722. lf.lfOutPrecision = OUT_DEFAULT_PRECIS;
  723. lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
  724. lf.lfQuality = PROOF_QUALITY;
  725. lf.lfPitchAndFamily = DEFAULT_PITCH | FF_SWISS;
  726. lstrcpy( lf.lfFaceName, TEXT("System") );
  727. #else
  728. lf.lfHeight = (-8 * iLogPelsY) / 72; /* 8pt */
  729. lf.lfWeight = 400; /* normal */
  730. lf.lfCharSet = ANSI_CHARSET;
  731. lf.lfOutPrecision = OUT_DEFAULT_PRECIS;
  732. lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
  733. lf.lfQuality = PROOF_QUALITY;
  734. lf.lfPitchAndFamily = DEFAULT_PITCH | FF_SWISS;
  735. lstrcpy( lf.lfFaceName, g_szAppFontName );
  736. #endif
  737. g_hDlgFont = CreateFontIndirect(&lf);
  738. if (g_hDlgFont) {
  739. SendDlgItemMessage( hwnd, IDD_HELPTEXT, WM_SETFONT,
  740. (WPARAM)g_hDlgFont, 0L );
  741. SendDlgItemMessage( hwnd, IDD_IOADDRESSCB, WM_SETFONT,
  742. (WPARAM)g_hDlgFont, 0L );
  743. SendDlgItemMessage( hwnd, IDD_IOADDRESSCB_S, WM_SETFONT,
  744. (WPARAM)g_hDlgFont, 0L );
  745. SendDlgItemMessage( hwnd, IDD_MPU401IOADDRESSCB, WM_SETFONT,
  746. (WPARAM)g_hDlgFont, 0L );
  747. SendDlgItemMessage( hwnd, IDD_IRQCB, WM_SETFONT,
  748. (WPARAM)g_hDlgFont, 0L );
  749. SendDlgItemMessage( hwnd, IDD_DMACB, WM_SETFONT,
  750. (WPARAM)g_hDlgFont, 0L );
  751. SendDlgItemMessage( hwnd, IDD_DMA16CB, WM_SETFONT,
  752. (WPARAM)g_hDlgFont, 0L );
  753. }
  754. /*
  755. ** Subclass the buttons
  756. */
  757. {
  758. HWND hwndButton;
  759. hwndButton = GetDlgItem( hwnd, IDOK );
  760. if (hwndButton) {
  761. OldButtonProc = SubclassWindow( hwndButton,
  762. ButtonSubClassProc );
  763. }
  764. hwndButton = GetDlgItem( hwnd, IDCANCEL );
  765. if (hwndButton) {
  766. OldButtonProc = SubclassWindow( hwndButton,
  767. ButtonSubClassProc );
  768. }
  769. hwndButton = GetDlgItem( hwnd, IDD_ADVANCEDBTN );
  770. if (hwndButton) {
  771. OldButtonProc = SubclassWindow( hwndButton,
  772. ButtonSubClassProc );
  773. }
  774. }
  775. /*
  776. ** Subclass the combo boxes
  777. */
  778. {
  779. HWND hwndCombo;
  780. hwndCombo = GetDlgItem( hwnd, IDD_IOADDRESSCB );
  781. if (hwndCombo) {
  782. OldComboProc = SubclassWindow( hwndCombo,
  783. ComboBoxSubClassProc );
  784. }
  785. hwndCombo = GetDlgItem( hwnd, IDD_MPU401IOADDRESSCB );
  786. if (hwndCombo) {
  787. OldComboProc = SubclassWindow( hwndCombo,
  788. ComboBoxSubClassProc );
  789. }
  790. hwndCombo = GetDlgItem( hwnd, IDD_IRQCB );
  791. if (hwndCombo) {
  792. OldComboProc = SubclassWindow( hwndCombo,
  793. ComboBoxSubClassProc );
  794. }
  795. hwndCombo = GetDlgItem( hwnd, IDD_DMACB );
  796. if (hwndCombo) {
  797. OldComboProc = SubclassWindow( hwndCombo,
  798. ComboBoxSubClassProc );
  799. }
  800. hwndCombo = GetDlgItem( hwnd, IDD_DMA16CB );
  801. if (hwndCombo) {
  802. OldComboProc = SubclassWindow( hwndCombo,
  803. ComboBoxSubClassProc );
  804. }
  805. }
  806. /*
  807. ** Display card data and centre the Dialog Box
  808. */
  809. GetOriginalControlPositions( hwnd );
  810. ResizeDialog( hwnd );
  811. SetDialogTitle( hwnd );
  812. SetupDialog(hwnd, CurrentCard);
  813. CenterPopup( hwnd, GetParent(hwnd) );
  814. /*
  815. ** Set the focus
  816. */
  817. SetFocus(GetDlgItem(hwnd, IDOK));
  818. return FALSE; // FALSE means WE set the focus
  819. }
  820. /*****************************Private*Routine******************************\
  821. * Config_OnCommand
  822. *
  823. *
  824. *
  825. * History:
  826. * 18-11-93 - StephenE - Created
  827. *
  828. \**************************************************************************/
  829. void
  830. Config_OnCommand(
  831. HWND hwnd,
  832. int id,
  833. HWND hwndCtl,
  834. UINT codeNotify
  835. )
  836. {
  837. DWORD ConfigReturn;
  838. switch ( id) {
  839. case IDOK:
  840. /*
  841. ** If we successfully configure then finish
  842. */
  843. ConfigReturn = Configure(hwnd);
  844. if ( DRVCNF_CONTINUE != ConfigReturn) {
  845. EndDialog( hwnd, ConfigReturn );
  846. } else {
  847. DSPVersion = INVALID_DSP_VERSION;
  848. DrvQueryDeviceIdParameter( &RegAccess,
  849. CurrentCard,
  850. SOUND_REG_DSP_VERSION,
  851. &DSPVersion );
  852. ResizeDialog( hwnd );
  853. SetDialogTitle( hwnd );
  854. /*
  855. ** Update the help for the button we've pressed
  856. */
  857. PrintHelpText( GetDlgItem(hwnd, IDOK ) );
  858. SetupDialog(hwnd, CurrentCard);
  859. }
  860. break;
  861. case IDCANCEL:
  862. EndDialog( hwnd, DRVCNF_CANCEL );
  863. break;
  864. case IDD_ABOUT:
  865. // About( hwnd );
  866. break;
  867. case IDD_ADVANCEDBTN:
  868. {
  869. HINSTANCE hLib = LoadLibrary( TEXT("comctl32.dll") );
  870. if (hLib) {
  871. DialogBox(hInstance,
  872. MAKEINTRESOURCE(DLG_ADVANCED),
  873. hwnd,
  874. (DLGPROC)AdvancedDlgProc);
  875. FreeLibrary( hLib);
  876. }
  877. }
  878. break;
  879. }
  880. }
  881. /**************************************************************************
  882. *
  883. * Function : Configure
  884. *
  885. * Arguments :
  886. *
  887. * hDlg - Dialog window handle
  888. *
  889. **************************************************************************/
  890. int Configure(HWND hDlg)
  891. {
  892. BOOL ConfigLoad;
  893. BOOL Success;
  894. /*
  895. * We have a new config - Configure the driver for this configuration
  896. */
  897. ConfigLoad = DSPVersion == INVALID_DSP_VERSION;
  898. /*
  899. ** Make sure the current settings are in the registry
  900. */
  901. SetCurrentConfig( hDlg, CurrentCard, &Configuration );
  902. Success = DrvConfigureDriver(&RegAccess,
  903. STR_DRIVERNAME,
  904. SoundDriverTypeNormal,
  905. NULL,
  906. NULL);
  907. /*
  908. ** Get the DriverEntry() load Status from the Kernel driver
  909. ** by reading the registry
  910. */
  911. /*
  912. ** See if we succeeded
  913. */
  914. if ( !DrvIsDriverLoaded(&RegAccess) ) {
  915. /*
  916. ** Search for what went wrong
  917. */
  918. UINT CardId;
  919. DWORD DriverLoadStatus;
  920. BOOL ErrorFound;
  921. DWORD ErrorStringId;
  922. DWORD OldDSPVersion;
  923. /*
  924. ** Make sure we know how many devices we have
  925. */
  926. DrvNumberOfDevices(&RegAccess, &NumberOfCards);
  927. for (CardId = 0,
  928. DriverLoadStatus = SOUND_CONFIG_OK,
  929. ErrorFound = FALSE;
  930. CardId < NumberOfCards;
  931. CardId++) {
  932. if ( DrvQueryDeviceIdParameter(
  933. &RegAccess,
  934. CardId,
  935. SOUND_REG_CONFIGERROR,
  936. &DriverLoadStatus ) == ERROR_SUCCESS &&
  937. DriverLoadStatus != SOUND_CONFIG_OK) {
  938. ErrorFound = TRUE;
  939. break;
  940. }
  941. }
  942. /*
  943. ** Point to failing card
  944. */
  945. if (ErrorFound) {
  946. CurrentCard = CardId;
  947. } else {
  948. /*
  949. ** Might have been a config load
  950. */
  951. if (ConfigLoad) {
  952. return DRVCNF_CONTINUE;
  953. }
  954. }
  955. /*
  956. ** This is a private interface to the Kernel driver
  957. ** Read the status and put up a dialog message
  958. */
  959. #define CONFIGERR(_x_) \
  960. case _x_: \
  961. ErrorStringId = IDS_##_x_; \
  962. break;
  963. switch (DriverLoadStatus) {
  964. CONFIGERR(SOUND_CONFIG_BADPORT)
  965. CONFIGERR(SOUND_CONFIG_BADDMA)
  966. CONFIGERR(SOUND_CONFIG_BADINT)
  967. CONFIGERR(SOUND_CONFIG_BAD_MPU401_PORT)
  968. CONFIGERR(SOUND_CONFIG_DMA_INUSE)
  969. CONFIGERR(SOUND_CONFIG_ERROR)
  970. CONFIGERR(SOUND_CONFIG_INT_INUSE)
  971. CONFIGERR(SOUND_CONFIG_MPU401_PORT_INUSE)
  972. CONFIGERR(SOUND_CONFIG_PORT_INUSE)
  973. CONFIGERR(SOUND_CONFIG_RESOURCE)
  974. default:
  975. ErrorStringId = IDS_SOUND_CONFIG_ERROR;
  976. break;
  977. }
  978. ConfigErrorMsgBox(hDlg, ErrorStringId);
  979. /*
  980. ** Check to see if the DSP version has changed
  981. */
  982. DSPVersion = INVALID_DSP_VERSION;
  983. DrvQueryDeviceIdParameter(
  984. &RegAccess,
  985. CurrentCard,
  986. SOUND_REG_DSP_VERSION,
  987. &DSPVersion);
  988. return DRVCNF_CONTINUE;
  989. } else {
  990. DWORD NewBufferSize;
  991. /*
  992. ** The driver may be loaded but it's possible we failed to unload it
  993. */
  994. if (!Success) {
  995. ConfigErrorMsgBox(hDlg, IDS_BUSY);
  996. return DRVCNF_CONTINUE;
  997. }
  998. /*
  999. ** Check for Thunderboard and DMA buffer
  1000. */
  1001. NewBufferSize = Configuration.DmaBufferSize;
  1002. DrvQueryDeviceIdParameter(
  1003. &RegAccess,
  1004. Configuration.CardId,
  1005. SOUND_REG_REALBUFFERSIZE,
  1006. &NewBufferSize);
  1007. if (NewBufferSize / 0x400 != Configuration.DmaBufferSize / 0x400) {
  1008. ConfigErrorMsgBox(hDlg,
  1009. IDS_CHANGEDDMABUFFERSIZE,
  1010. Configuration.DmaBufferSize / 0x400,
  1011. NewBufferSize / 0x400);
  1012. }
  1013. if (bInstall) {
  1014. /*
  1015. ** Set up midi mapper
  1016. */
  1017. DrvQueryDeviceIdParameter(
  1018. &RegAccess,
  1019. Configuration.CardId,
  1020. SOUND_REG_SYNTH_TYPE,
  1021. &Configuration.SynthType);
  1022. if (Configuration.SynthType != (DWORD)-1) {
  1023. DrvSetMapperName(Configuration.SynthType == SOUND_SYNTH_TYPE_OPL3 ?
  1024. SNDBLST_MAPPER_OPL3 : SNDBLST_MAPPER_ADLIB);
  1025. }
  1026. /*
  1027. ** Reset the Install Flag
  1028. */
  1029. bInstall = FALSE;
  1030. }
  1031. return DRVCNF_RESTART;
  1032. }
  1033. }
  1034. /****************************************************************************
  1035. * @doc INTERNAL
  1036. *
  1037. * @api int | About | This puts up the About dialog box.
  1038. *
  1039. * @parm HWND | hWnd | Our Window handle.
  1040. *
  1041. * @parm HANDLE | hInstance | Our instance handle.
  1042. *
  1043. * @rdesc Returns whatever was returned from the dialog box procedure.
  1044. ***************************************************************************/
  1045. int About( HWND hWnd )
  1046. {
  1047. return TRUE;
  1048. #if 0
  1049. return DialogBox(ghModule,
  1050. MAKEINTRESOURCE(DLG_ABOUT),
  1051. hWnd,
  1052. (DLGPROC) AboutDlgProc );
  1053. #endif
  1054. }
  1055. /*****************************************************************************
  1056. * CenterPopup( hWnd, hParentWnd ) *
  1057. * *
  1058. * hWnd window handle *
  1059. * hParentWnd parent window handle *
  1060. * *
  1061. * This routine centers the popup window in the screen or display *
  1062. * using the window handles provided. The window is centered over *
  1063. * the parent if the parent window is valid. Special provision *
  1064. * is made for the case when the popup would be centered outside *
  1065. * the screen - in this case it is positioned at the appropriate *
  1066. * border. *
  1067. * *
  1068. *****************************************************************************/
  1069. BOOL FAR PASCAL CenterPopup( HWND hWnd,
  1070. HWND hParentWnd )
  1071. {
  1072. int xPopup;
  1073. int yPopup;
  1074. int cxPopup;
  1075. int cyPopup;
  1076. int cxScreen;
  1077. int cyScreen;
  1078. int cxParent;
  1079. int cyParent;
  1080. RECT rcWindow;
  1081. /* retrieve main display dimensions */
  1082. cxScreen = GetSystemMetrics( SM_CXSCREEN );
  1083. cyScreen = GetSystemMetrics( SM_CYSCREEN );
  1084. /* retrieve popup rectangle */
  1085. GetWindowRect( hWnd, (LPRECT)&rcWindow );
  1086. /* calculate popup extents */
  1087. cxPopup = rcWindow.right - rcWindow.left;
  1088. cyPopup = rcWindow.bottom - rcWindow.top;
  1089. /* calculate bounding rectangle */
  1090. if ( hParentWnd ) {
  1091. /* retrieve parent rectangle */
  1092. GetWindowRect( hParentWnd, (LPRECT)&rcWindow );
  1093. /* calculate parent extents */
  1094. cxParent = rcWindow.right - rcWindow.left;
  1095. cyParent = rcWindow.bottom - rcWindow.top;
  1096. /* center within parent window */
  1097. xPopup = rcWindow.left + ((cxParent - cxPopup)/2);
  1098. yPopup = rcWindow.top + ((cyParent - cyPopup)/2);
  1099. /* adjust popup x-location for screen size */
  1100. if ( xPopup+cxPopup > cxScreen ) {
  1101. xPopup = cxScreen - cxPopup;
  1102. }
  1103. /* adjust popup y-location for screen size */
  1104. if ( yPopup+cyPopup > cyScreen ) {
  1105. yPopup = cyScreen - cyPopup;
  1106. }
  1107. } else {
  1108. /* center within entire screen */
  1109. xPopup = (cxScreen - cxPopup) / 2;
  1110. yPopup = (cyScreen - cyPopup) / 2;
  1111. }
  1112. /* move window to new location & display */
  1113. MoveWindow( hWnd,
  1114. xPopup > 0 ? xPopup : 0,
  1115. yPopup > 0 ? yPopup : 0,
  1116. cxPopup,
  1117. cyPopup,
  1118. TRUE );
  1119. /* normal return */
  1120. return( TRUE );
  1121. }
  1122. /*****************************************************************************
  1123. ConfigErrorMsgBox()
  1124. *****************************************************************************/
  1125. void cdecl ConfigErrorMsgBox(HWND hDlg, UINT StringId, ...)
  1126. {
  1127. TCHAR szErrorBuffer[256]; /* buffer for error messages */
  1128. TCHAR szErrorString[256];
  1129. va_list va;
  1130. LoadString( ghModule,
  1131. StringId,
  1132. szErrorString,
  1133. sizeof(szErrorString) / sizeof(TCHAR));
  1134. va_start(va, StringId);
  1135. wvsprintf(szErrorBuffer, szErrorString, va);
  1136. va_end(va);
  1137. MessageBox( hDlg,
  1138. szErrorBuffer,
  1139. STR_PRODUCTNAME,
  1140. MB_OK | MB_ICONEXCLAMATION);
  1141. }
  1142. /******************************Public*Routine******************************\
  1143. * ButtonSubClassProc
  1144. *
  1145. * If the button is receiving the focus display a suitable help
  1146. * message in the help text box.
  1147. *
  1148. * History:
  1149. * dd-mm-94 - StephenE - Created
  1150. *
  1151. \**************************************************************************/
  1152. LRESULT CALLBACK
  1153. ButtonSubClassProc(
  1154. HWND hwnd,
  1155. UINT uMsg,
  1156. WPARAM wParam,
  1157. LPARAM lParam
  1158. )
  1159. {
  1160. if ( uMsg == WM_SETFOCUS) {
  1161. PrintHelpText( hwnd );
  1162. }
  1163. return CallWindowProc(OldButtonProc, hwnd, uMsg, wParam, lParam);
  1164. }
  1165. /******************************Public*Routine******************************\
  1166. * ComboBoxSubClassProc
  1167. *
  1168. * If the combo box is receiving the focus display a suitable help
  1169. * message in the help text box.
  1170. *
  1171. * History:
  1172. * dd-mm-94 - StephenE - Created
  1173. *
  1174. \**************************************************************************/
  1175. LRESULT CALLBACK
  1176. ComboBoxSubClassProc(
  1177. HWND hwnd,
  1178. UINT uMsg,
  1179. WPARAM wParam,
  1180. LPARAM lParam
  1181. )
  1182. {
  1183. if ( uMsg == WM_SETFOCUS) {
  1184. PrintHelpText( hwnd );
  1185. }
  1186. return CallWindowProc(OldComboProc, hwnd, uMsg, wParam, lParam);
  1187. }
  1188. /*****************************Private*Routine******************************\
  1189. * PrintHelpText
  1190. *
  1191. *
  1192. *
  1193. * History:
  1194. * dd-mm-94 - StephenE - Created
  1195. *
  1196. \**************************************************************************/
  1197. void
  1198. PrintHelpText(
  1199. HWND hwnd
  1200. )
  1201. {
  1202. HWND hwndParent = GetParent( hwnd );
  1203. UINT uID = GetWindowLong( hwnd, GWL_ID );
  1204. TCHAR szBuffer[IDS_MAX_HELP_SIZE];
  1205. /*
  1206. ** Hack to special case the OK button when it's detect
  1207. */
  1208. LoadString( ghModule,
  1209. IDS_HELP_BASE + uID + VersionToDlgId(DSPVersion),
  1210. szBuffer, IDS_MAX_HELP_SIZE );
  1211. SetDlgItemText( hwndParent, IDD_HELPTEXT, szBuffer );
  1212. if (DSPVersion == INVALID_DSP_VERSION && uID == IDOK) {
  1213. LoadString( ghModule, IDS_FRM_DETECTBTN,
  1214. szBuffer, IDS_MAX_HELP_SIZE );
  1215. } else {
  1216. LoadString( ghModule, IDS_HELP_FRM_BASE + uID,
  1217. szBuffer, IDS_MAX_HELP_SIZE );
  1218. }
  1219. SetDlgItemText( hwndParent, IDD_HELPTEXTFRAME, szBuffer );
  1220. }
  1221. void
  1222. MyShowWindow(HWND hwnd, int nCmdShow)
  1223. {
  1224. ShowWindow(hwnd, nCmdShow);
  1225. EnableWindow(hwnd, nCmdShow == SW_SHOW);
  1226. }
  1227. /******************************Public*Routine******************************\
  1228. * ResizeDialog
  1229. *
  1230. * Here we resize the dialog box according to the type of Sound Blaster
  1231. * that is being configured. Also, any unecessary controls get hidden here.
  1232. *
  1233. * History:
  1234. * dd-mm-94 - StephenE - Created
  1235. *
  1236. \**************************************************************************/
  1237. void
  1238. ResizeDialog(
  1239. HWND hwnd
  1240. )
  1241. {
  1242. POINT ptNewPos[3];
  1243. HDWP hdwp;
  1244. LONG lDecrement;
  1245. /*
  1246. ** Resize the dialog. Start by calculating the relative adjustment
  1247. ** for the main dialog and then decrement it from the help text frame
  1248. ** and help text controls. Also while were calculating the size
  1249. ** adjustments show/hide the necessary controls.
  1250. */
  1251. ptNewPos[0].x = g_OrgRectDlg.right - g_OrgRectDlg.left;
  1252. ptNewPos[0].y = g_OrgRectDlg.bottom - g_OrgRectDlg.top;
  1253. ptNewPos[1].x = g_OrgRect[IDD_HELPTEXTFRAME - IDD_DLG_BASE].left;
  1254. ptNewPos[1].y = g_OrgRect[IDD_HELPTEXTFRAME - IDD_DLG_BASE].top;
  1255. ptNewPos[2].x = g_OrgRect[IDD_HELPTEXT - IDD_DLG_BASE].left;
  1256. ptNewPos[2].y = g_OrgRect[IDD_HELPTEXT - IDD_DLG_BASE].top;
  1257. switch (VersionToDlgId(DSPVersion)) {
  1258. case DLG_SB16CONFIG:
  1259. MyShowWindow( GetDlgItem( hwnd, IDD_IOADDRESSCB_S ), SW_SHOW );
  1260. MyShowWindow( GetDlgItem( hwnd, IDD_IOADDRESSCB ), SW_HIDE );
  1261. MyShowWindow( GetDlgItem( hwnd, IDD_DMA16CB ), SW_SHOW );
  1262. MyShowWindow( GetDlgItem( hwnd, IDD_DMA16CB_T ), SW_SHOW );
  1263. MyShowWindow( GetDlgItem( hwnd, IDD_MPU401IOADDRESSCB ), SW_SHOW );
  1264. MyShowWindow( GetDlgItem( hwnd, IDD_MPU401IOADDRESSCB_T ), SW_SHOW );
  1265. MyShowWindow( GetDlgItem( hwnd, IDD_DMACB ), SW_SHOW );
  1266. MyShowWindow( GetDlgItem( hwnd, IDD_DMACB_T ), SW_SHOW );
  1267. MyShowWindow( GetDlgItem( hwnd, IDD_IRQCB ), SW_SHOW );
  1268. MyShowWindow( GetDlgItem( hwnd, IDD_IRQCB_T ), SW_SHOW );
  1269. MyShowWindow( GetDlgItem( hwnd, IDD_ADVANCEDBTN ), SW_SHOW );
  1270. lDecrement = 0L;
  1271. break;
  1272. case DLG_SBPROCONFIG:
  1273. MyShowWindow( GetDlgItem( hwnd, IDD_IOADDRESSCB_S ), SW_SHOW );
  1274. MyShowWindow( GetDlgItem( hwnd, IDD_IOADDRESSCB ), SW_HIDE );
  1275. MyShowWindow( GetDlgItem( hwnd, IDD_DMA16CB ), SW_HIDE );
  1276. MyShowWindow( GetDlgItem( hwnd, IDD_DMA16CB_T ), SW_HIDE );
  1277. MyShowWindow( GetDlgItem( hwnd, IDD_MPU401IOADDRESSCB ), SW_HIDE );
  1278. MyShowWindow( GetDlgItem( hwnd, IDD_MPU401IOADDRESSCB_T ), SW_HIDE );
  1279. MyShowWindow( GetDlgItem( hwnd, IDD_DMACB ), SW_SHOW );
  1280. MyShowWindow( GetDlgItem( hwnd, IDD_DMACB_T ), SW_SHOW );
  1281. MyShowWindow( GetDlgItem( hwnd, IDD_IRQCB ), SW_SHOW );
  1282. MyShowWindow( GetDlgItem( hwnd, IDD_IRQCB_T ), SW_SHOW );
  1283. MyShowWindow( GetDlgItem( hwnd, IDD_ADVANCEDBTN ), SW_SHOW );
  1284. lDecrement = (g_OrgRect[IDD_HELPTEXTFRAME - IDD_DLG_BASE].top -
  1285. g_OrgRect[IDD_DMA16CB - IDD_DLG_BASE].top);
  1286. break;
  1287. case DLG_SB1CONFIG:
  1288. MyShowWindow( GetDlgItem( hwnd, IDD_IOADDRESSCB_S ), SW_SHOW );
  1289. MyShowWindow( GetDlgItem( hwnd, IDD_IOADDRESSCB ), SW_HIDE );
  1290. MyShowWindow( GetDlgItem( hwnd, IDD_DMA16CB ), SW_HIDE );
  1291. MyShowWindow( GetDlgItem( hwnd, IDD_DMA16CB_T ), SW_HIDE );
  1292. MyShowWindow( GetDlgItem( hwnd, IDD_MPU401IOADDRESSCB ), SW_HIDE );
  1293. MyShowWindow( GetDlgItem( hwnd, IDD_MPU401IOADDRESSCB_T ), SW_HIDE );
  1294. MyShowWindow( GetDlgItem( hwnd, IDD_DMACB ), SW_HIDE );
  1295. MyShowWindow( GetDlgItem( hwnd, IDD_DMACB_T ), SW_HIDE );
  1296. MyShowWindow( GetDlgItem( hwnd, IDD_IRQCB ), SW_SHOW );
  1297. MyShowWindow( GetDlgItem( hwnd, IDD_IRQCB_T ), SW_SHOW );
  1298. MyShowWindow( GetDlgItem( hwnd, IDD_ADVANCEDBTN ), SW_HIDE );
  1299. lDecrement = (g_OrgRect[IDD_HELPTEXTFRAME - IDD_DLG_BASE].top -
  1300. g_OrgRect[IDD_DMACB - IDD_DLG_BASE].top);
  1301. break;
  1302. case DLG_PORTSELECT:
  1303. MyShowWindow( GetDlgItem( hwnd, IDD_IOADDRESSCB_S ), SW_HIDE );
  1304. MyShowWindow( GetDlgItem( hwnd, IDD_IOADDRESSCB ), SW_SHOW );
  1305. MyShowWindow( GetDlgItem( hwnd, IDD_DMA16CB ), SW_HIDE );
  1306. MyShowWindow( GetDlgItem( hwnd, IDD_DMA16CB_T ), SW_HIDE );
  1307. MyShowWindow( GetDlgItem( hwnd, IDD_MPU401IOADDRESSCB ), SW_HIDE );
  1308. MyShowWindow( GetDlgItem( hwnd, IDD_MPU401IOADDRESSCB_T ), SW_HIDE );
  1309. MyShowWindow( GetDlgItem( hwnd, IDD_DMACB ), SW_HIDE );
  1310. MyShowWindow( GetDlgItem( hwnd, IDD_DMACB_T ), SW_HIDE );
  1311. MyShowWindow( GetDlgItem( hwnd, IDD_IRQCB ), SW_HIDE );
  1312. MyShowWindow( GetDlgItem( hwnd, IDD_IRQCB_T ), SW_HIDE );
  1313. MyShowWindow( GetDlgItem( hwnd, IDD_ADVANCEDBTN ), SW_HIDE );
  1314. lDecrement = (g_OrgRect[IDD_HELPTEXTFRAME - IDD_DLG_BASE].top -
  1315. g_OrgRect[IDD_DMACB - IDD_DLG_BASE].top);
  1316. break;
  1317. }
  1318. ptNewPos[0].y -= lDecrement;
  1319. ptNewPos[1].y -= lDecrement;
  1320. ptNewPos[2].y -= lDecrement;
  1321. /*
  1322. ** First resize the dialog box.
  1323. */
  1324. SetWindowPos( hwnd, HWND_TOP, 0, 0, ptNewPos[0].x, ptNewPos[0].y,
  1325. SWP_NOMOVE | SWP_NOZORDER );
  1326. /*
  1327. ** Now move the help text controls
  1328. */
  1329. hdwp = BeginDeferWindowPos( 2 );
  1330. hdwp = DeferWindowPos( hdwp,
  1331. GetDlgItem( hwnd, IDD_HELPTEXTFRAME ),
  1332. HWND_TOP,
  1333. ptNewPos[1].x,
  1334. ptNewPos[1].y,
  1335. 0, 0,
  1336. SWP_NOSIZE | SWP_NOZORDER );
  1337. hdwp = DeferWindowPos( hdwp,
  1338. GetDlgItem( hwnd, IDD_HELPTEXT ),
  1339. HWND_TOP,
  1340. ptNewPos[2].x,
  1341. ptNewPos[2].y,
  1342. 0, 0,
  1343. SWP_NOSIZE | SWP_NOZORDER );
  1344. EndDeferWindowPos( hdwp );
  1345. }
  1346. /******************************Public*Routine******************************\
  1347. * SetDialogTitle
  1348. *
  1349. * Adjusts the dialog box title to match the type of sound balster card
  1350. * being configured.
  1351. *
  1352. * History:
  1353. * dd-mm-94 - StephenE - Created
  1354. *
  1355. \**************************************************************************/
  1356. void
  1357. SetDialogTitle(
  1358. HWND hwnd
  1359. )
  1360. {
  1361. TCHAR szTitle[80];
  1362. LoadString( ghModule, VersionToDlgId(DSPVersion) + IDS_DIALOG_BASE, szTitle, 80 );
  1363. SetWindowText( hwnd, szTitle );
  1364. }
  1365. /*****************************Private*Routine******************************\
  1366. * GetOriginalControlPositions
  1367. *
  1368. * Get the original positions/sizes of the dialog box and all the controls
  1369. * this information is converted into dialog box co-ordinates and used in
  1370. * the ResizeDialog function above.
  1371. *
  1372. * History:
  1373. * dd-mm-94 - StephenE - Created
  1374. *
  1375. \**************************************************************************/
  1376. void
  1377. GetOriginalControlPositions(
  1378. HWND hwnd
  1379. )
  1380. {
  1381. int i;
  1382. GetWindowRect( hwnd, &g_OrgRectDlg );
  1383. for ( i = 0; i < MAX_IDDS; i++ ) {
  1384. GetWindowRect( GetDlgItem( hwnd, IDD_DLG_BASE + i ), &g_OrgRect[i] );
  1385. MapWindowRect( HWND_DESKTOP, hwnd, &g_OrgRect[i] );
  1386. }
  1387. }