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.

3638 lines
85 KiB

  1. /*==========================================================================*/
  2. //
  3. // midi.c
  4. //
  5. // Copyright (C) 1993-1994 Microsoft Corporation. All Rights Reserved.
  6. /*==========================================================================*/
  7. #include "mmcpl.h"
  8. #include <windowsx.h>
  9. #include <mmsystem.h>
  10. #include <mmddkp.h>
  11. #include <mmreg.h>
  12. #include <cpl.h>
  13. #define NOSTATUSBAR
  14. #include <commctrl.h>
  15. #include <prsht.h>
  16. #include <string.h>
  17. #include <memory.h>
  18. #include <regstr.h>
  19. #include "draw.h"
  20. #include "utils.h"
  21. #include "roland.h"
  22. #include "midi.h"
  23. #include "tchar.h"
  24. //#include "newexe.h"
  25. #include <winnt.h>
  26. #if defined DEBUG || defined DEBUG_RETAIL
  27. extern TCHAR szNestLevel[];
  28. TCHAR szNestLevel[] = TEXT ("0MidiProp:");
  29. #define MODULE_DEBUG_PREFIX szNestLevel
  30. #endif
  31. #define ARRAYSIZE(a) (sizeof(a)/sizeof(a[0]))
  32. #define _INC_MMDEBUG_CODE_ TRUE
  33. #include "mmdebug.h"
  34. #include "medhelp.h"
  35. #ifndef TVIS_ALL
  36. #define TVIS_ALL 0xFF7F // internal
  37. #endif
  38. #ifndef MIDI_IO_CONTROL
  39. #define MIDI_IO_CONTROL 0x00000008L // internal
  40. #endif
  41. #ifndef DRV_F_ADD // FEATURE: These should be in MMDDK.H
  42. #define DRV_F_ADD 0x00000000
  43. #define DRV_F_REMOVE 0x00000001
  44. #define DRV_F_CHANGE 0x00000002
  45. #define DRV_F_PROP_INSTR 0x00000004
  46. #define DRV_F_NEWDEFAULTS 0x00000008
  47. #define DRV_F_PARAM_IS_DEVNODE 0x10000000
  48. #endif
  49. /*==========================================================================*/
  50. // containing struct for what would otherwise be global variables
  51. //
  52. struct _globalstate gs;
  53. // this is the registry key that has midi instrument aliases
  54. // as subkeys
  55. //
  56. SZCODE cszSchemeRoot[] = REGSTR_PATH_PRIVATEPROPERTIES TEXT ("\\MIDI\\Schemes");
  57. SZCODE cszMidiMapRoot[] = REGSTR_PATH_MULTIMEDIA TEXT ("\\MIDIMap");
  58. // this is the registry key that has midi driver/port names
  59. //
  60. SZCODE cszDriversRoot[] = REGSTR_PATH_MEDIARESOURCES TEXT ("\\MIDI");
  61. // this is the list of known hindered midi drivers (or rather,
  62. // known drivers that require special idf's)
  63. //
  64. SZCODE cszHinderedMidiList[] = REGSTR_PATH_MEDIARESOURCES TEXT ("\\NonGeneralMIDIDriverList");
  65. SZCODE cszFriendlyName[] = TEXT ("FriendlyName");
  66. SZCODE cszDescription[] = TEXT ("Description");
  67. SZCODE cszSlashInstruments[] = TEXT ("\\Instruments");
  68. SZCODE cszExternal[] = TEXT ("External");
  69. SZCODE cszActive[] = TEXT ("Active");
  70. SZCODE cszDefinition[] = TEXT ("Definition");
  71. SZCODE cszPort[] = TEXT ("Port");
  72. SZCODE cszMidiSlash[] = TEXT ("midi\\");
  73. SZCODE csz02d[] = TEXT ("%02d");
  74. SZCODE cszEmpty[] = TEXT ("");
  75. static SZCODE cszChannels[] = TEXT ("Channels");
  76. static SZCODE cszCurrentScheme[] = TEXT ("CurrentScheme");
  77. static SZCODE cszCurrentInstrument[] = TEXT ("CurrentInstrument");
  78. static SZCODE cszUseScheme[] = TEXT ("UseScheme");
  79. static SZCODE cszAutoScheme[] = TEXT ("AutoScheme");
  80. static SZCODE cszRunOnceCount[] = TEXT ("ConfigureCount");
  81. static SZCODE cszDriverList[] = TEXT ("DriverList");
  82. static SZCODE cszDriverVal[] = TEXT ("Driver");
  83. //
  84. // structures used to hold data for the control panel dialogs.
  85. //
  86. //
  87. typedef struct _midi_scheme {
  88. PMCMIDI pmcm;
  89. HKEY hkSchemes;
  90. TCHAR szNone[MAX_ALIAS];
  91. DWORD dwChanMask;
  92. TCHAR szName[MAX_ALIAS];
  93. UINT nChildren;
  94. BOOL bDirty;
  95. struct {
  96. PINSTRUM pi;
  97. DWORD dwMask;
  98. } a[NUM_CHANNEL*4 +1];
  99. } MSCHEME, * PMSCHEME;
  100. typedef struct _midi_cpl {
  101. LPPROPSHEETPAGE ppsp;
  102. MSCHEME ms;
  103. TCHAR szScheme[MAX_ALIAS];
  104. TCHAR szDefault[MAX_ALIAS];
  105. PINSTRUM piSingle;
  106. BOOL bUseScheme;
  107. BOOL bAutoScheme; // TRUE if scheme was auto created
  108. DWORD dwRunCount; // counts the number of times runonce
  109. LPTSTR pszReason; // reason for choosing external port
  110. BOOL bDlgType2;
  111. BOOL bPastInit;
  112. BOOL bIgnoreSelChange;
  113. MCMIDI mcm;
  114. } MCLOCAL, * PMCLOCAL;
  115. BOOL WINAPI ShowDetails (
  116. HWND hWnd,
  117. PMCLOCAL pmcl);
  118. LONG SHRegDeleteKey(HKEY hKey, LPCTSTR lpSubKey);
  119. static UINT
  120. DeviceIDFromDriverName(
  121. PTSTR pstrDriverName);
  122. extern BOOL AccessServiceController(void);
  123. /*+ SimulateNotify
  124. *
  125. *-=================================================================*/
  126. STATICFN LRESULT SimulateNotify (
  127. HWND hWnd,
  128. WORD uId,
  129. WORD wNotify)
  130. {
  131. #ifdef _WIN32
  132. return SendMessage (hWnd, WM_COMMAND,
  133. MAKELONG(uId, wNotify),
  134. (LPARAM)GetDlgItem (hWnd, uId));
  135. #else
  136. #error this code is not designed for 16 bits
  137. #endif
  138. }
  139. /*+ Confirm
  140. *
  141. *-=================================================================*/
  142. STATICFN UINT Confirm (
  143. HWND hWnd,
  144. UINT idQuery,
  145. LPTSTR pszArg)
  146. {
  147. TCHAR szQuery[255];
  148. TCHAR sz[255];
  149. LoadString (ghInstance, idQuery, sz, NUMELMS(sz));
  150. wsprintf (szQuery, sz, pszArg);
  151. LoadString (ghInstance, IDS_DEF_CAPTION, sz, NUMELMS(sz));
  152. return MessageBox (hWnd, szQuery, sz, MB_YESNO | MB_ICONQUESTION);
  153. }
  154. /*+ TellUser
  155. *
  156. *-=================================================================*/
  157. STATICFN UINT TellUser (
  158. HWND hWnd,
  159. UINT idQuery,
  160. LPTSTR pszArg)
  161. {
  162. TCHAR szQuery[255];
  163. TCHAR sz[255];
  164. LoadString (ghInstance, idQuery, sz, NUMELMS(sz));
  165. wsprintf (szQuery, sz, pszArg);
  166. LoadString (ghInstance, IDS_DEF_CAPTION, sz, NUMELMS(sz));
  167. return MessageBox (hWnd, szQuery, sz, MB_OK | MB_ICONINFORMATION);
  168. }
  169. /*+ ForwardBillNotify
  170. *
  171. *-=================================================================*/
  172. STATICFN void ForwardBillNotify (
  173. HWND hWnd,
  174. NMHDR FAR * lpnm)
  175. {
  176. static struct {
  177. UINT code;
  178. UINT uId;
  179. } amap[] = {PSN_KILLACTIVE, IDOK,
  180. PSN_APPLY, ID_APPLY,
  181. PSN_SETACTIVE, ID_INIT,
  182. PSN_RESET, IDCANCEL,
  183. };
  184. UINT ii;
  185. #ifdef DEBUG
  186. AuxDebugEx (4, DEBUGLINE TEXT ("ForwardBillNotify() code = %X\r\n"), lpnm->code);
  187. #endif
  188. for (ii = 0; ii < NUMELMS(amap); ++ii)
  189. if (lpnm->code == amap[ii].code)
  190. {
  191. FORWARD_WM_COMMAND (hWnd, amap[ii].uId, 0, 0, SendMessage);
  192. break;
  193. }
  194. return;
  195. }
  196. /*+
  197. *
  198. *-=================================================================*/
  199. STATICFN void EnumChildrenIntoCombo (
  200. HWND hWndT,
  201. LPTSTR pszSelect,
  202. HKEY hKey)
  203. {
  204. TCHAR sz[MAX_ALIAS];
  205. DWORD cch = sizeof(sz)/sizeof(TCHAR);
  206. UINT ii = 0;
  207. //SetWindowRedraw (hWndT, FALSE);
  208. ComboBox_ResetContent (hWndT);
  209. if (!hKey)
  210. return;
  211. while (RegEnumKey (hKey, ii, sz, cch) == ERROR_SUCCESS)
  212. {
  213. int ix = ComboBox_AddString (hWndT, sz);
  214. //ComboBox_SetItemData (hWndT, ix, ii);
  215. ++ii;
  216. }
  217. ii = 0;
  218. if (pszSelect)
  219. ii = ComboBox_FindString (hWndT, -1, pszSelect);
  220. ComboBox_SetCurSel (hWndT, ii);
  221. }
  222. STDAPI_(BOOL) QueryGSSynth(LPTSTR pszDriver)
  223. {
  224. MIDIOUTCAPS moc;
  225. MMRESULT mmr;
  226. UINT mid;
  227. BOOL fGSSynth = FALSE;
  228. if (pszDriver)
  229. {
  230. mid = DeviceIDFromDriverName(pszDriver);
  231. if (mid!=(UINT)-1)
  232. {
  233. mmr = midiOutGetDevCaps(mid, &moc, sizeof(moc));
  234. if (MMSYSERR_NOERROR == mmr)
  235. {
  236. if ((moc.wMid == MM_MICROSOFT) && (moc.wPid == MM_MSFT_WDMAUDIO_MIDIOUT) && (moc.wTechnology == MOD_SWSYNTH))
  237. {
  238. fGSSynth = TRUE;
  239. } //end if synth
  240. } //end if no mm error
  241. } //end if mid is valid
  242. } //end if driver is valid string
  243. return(fGSSynth);
  244. }
  245. /*+
  246. *
  247. *-=================================================================*/
  248. LONG WINAPI GetAlias (
  249. HKEY hKey,
  250. LPTSTR szSub,
  251. LPTSTR pszAlias,
  252. DWORD cchAlias,
  253. BOOL * pbExtern,
  254. BOOL * pbActive)
  255. {
  256. LONG lRet;
  257. DWORD cbSize;
  258. HKEY hkSub;
  259. DWORD dw;
  260. #ifdef DEBUG
  261. AuxDebugEx (8, DEBUGLINE TEXT ("GetAlias(%08x,'%s',%08x,%d,%08x)\r\n"),
  262. hKey, szSub, pszAlias, cchAlias, pbExtern);
  263. #endif
  264. if (!(lRet = RegOpenKeyEx (hKey, szSub, 0, KEY_QUERY_VALUE, &hkSub)))
  265. {
  266. cbSize = cchAlias * sizeof (TCHAR);
  267. if ((lRet = RegQueryValueEx (hkSub, cszFriendlyName, NULL, &dw, (LPBYTE)pszAlias, &cbSize)) || cbSize <= 2)
  268. {
  269. cbSize = cchAlias * sizeof (TCHAR);
  270. if ((lRet = RegQueryValueEx (hkSub, cszDescription, NULL, &dw, (LPBYTE)pszAlias, &cbSize)) || cbSize <= 2)
  271. {
  272. TCHAR szDriver[MAXSTR];
  273. cbSize = sizeof(szDriver);
  274. if (!RegQueryValueEx(hkSub, cszDriverVal, NULL, &dw, (LPBYTE)szDriver, &cbSize))
  275. {
  276. LoadVERSION();
  277. if (!LoadDesc(szDriver, pszAlias))
  278. lstrcpy(pszAlias, szDriver);
  279. FreeVERSION();
  280. cbSize = (lstrlen(pszAlias)+1) * sizeof(TCHAR);
  281. RegSetValueEx(hkSub, cszFriendlyName, (DWORD)0, REG_SZ, (LPBYTE)pszAlias, cbSize);
  282. RegSetValueEx(hkSub, cszDescription, (DWORD)0, REG_SZ, (LPBYTE)pszAlias, cbSize);
  283. }
  284. else
  285. pszAlias[0] = 0;
  286. }
  287. }
  288. if (pbExtern)
  289. {
  290. *pbExtern = 0;
  291. cbSize = sizeof(*pbExtern);
  292. if (!(lRet = RegQueryValueEx (hkSub, cszExternal, NULL, &dw, (LPBYTE)pbExtern, &cbSize)))
  293. {
  294. if (REG_SZ == dw)
  295. *pbExtern = (*(LPTSTR)pbExtern == TEXT('0')) ? FALSE : TRUE;
  296. }
  297. }
  298. if (pbActive)
  299. {
  300. *pbActive = 0;
  301. cbSize = sizeof(*pbActive);
  302. if (!(lRet = RegQueryValueEx (hkSub, cszActive, NULL, &dw, (LPBYTE)pbActive, &cbSize)))
  303. {
  304. if (REG_SZ == dw)
  305. *pbActive = (*(LPTSTR)pbActive == TEXT('1')) ? TRUE : FALSE;
  306. }
  307. }
  308. RegCloseKey (hkSub);
  309. }
  310. #ifdef DEBUG
  311. if (lRet)
  312. {
  313. TCHAR szErr[MAX_PATH];
  314. FormatMessage(FORMAT_MESSAGE_IGNORE_INSERTS, NULL, lRet, 0,
  315. szErr, NUMELMS(szErr), NULL);
  316. #ifdef DEBUG
  317. AuxDebugEx (1, DEBUGLINE TEXT ("GetAlias failed: %d %s\r\n"), lRet, szErr);
  318. #endif
  319. }
  320. #endif
  321. return lRet;
  322. }
  323. /*+
  324. *
  325. *-=================================================================*/
  326. LONG WINAPI GetDriverFilename (
  327. HKEY hKey,
  328. LPTSTR szSub,
  329. LPTSTR pszDriver,
  330. DWORD cchDriver)
  331. {
  332. HKEY hkSub;
  333. LONG lRet;
  334. if (!(lRet = RegOpenKeyEx (hKey, szSub, 0, KEY_QUERY_VALUE, &hkSub)))
  335. {
  336. DWORD dwType;
  337. TCHAR sz[MAX_PATH];
  338. UINT cb = sizeof(sz);
  339. // get the contents of the 'driver' value of the given key.
  340. // then copy the filename part
  341. //
  342. lRet = RegQueryValueEx(hkSub, cszDriverVal, NULL, &dwType, (LPBYTE)sz, &cb);
  343. if (lRet || dwType != REG_SZ)
  344. *pszDriver = 0;
  345. else
  346. {
  347. LPTSTR psz = sz;
  348. UINT ii;
  349. // scan forward till we get to the file part of the pathname
  350. // then copy that part into the supplied buffer
  351. //
  352. for (ii = 0; psz[ii]; )
  353. {
  354. if (psz[ii] == TEXT('\\') || psz[ii] == TEXT(':'))
  355. {
  356. psz += ii+1;
  357. ii = 0;
  358. }
  359. else
  360. ++ii;
  361. }
  362. lstrcpyn (pszDriver, psz, cchDriver);
  363. }
  364. RegCloseKey (hkSub);
  365. }
  366. return lRet;
  367. }
  368. /*+ LoadInstruments
  369. *
  370. * load interesting data for all instruments, if bDriverAsAlias
  371. * is true, then put driver filename in szFriendly field of each
  372. * instrument. (scheme init uses this for hindered driver detection)
  373. * if !bDriverAsAlias, put friendly name in friendly name slot
  374. *
  375. *
  376. *-=================================================================*/
  377. void WINAPI LoadInstruments (
  378. PMCMIDI pmcm,
  379. BOOL bDriverAsAlias)
  380. {
  381. HKEY hkMidi;
  382. TCHAR sz[MAX_ALIAS];
  383. DWORD cch = sizeof(sz)/sizeof(TCHAR);
  384. UINT ii;
  385. UINT nInstr;
  386. PINSTRUM pi;
  387. UINT idxPort = 0;
  388. pmcm->nInstr = 0;
  389. pmcm->bHasExternal = FALSE;
  390. if (!(hkMidi = pmcm->hkMidi))
  391. {
  392. if (RegCreateKey (HKEY_LOCAL_MACHINE, cszDriversRoot, &hkMidi))
  393. return;
  394. pmcm->hkMidi = hkMidi;
  395. }
  396. if (!(pi = pmcm->api[0]))
  397. {
  398. pmcm->api[0] = pi = (LPVOID)LocalAlloc (LPTR, sizeof(*pi));
  399. if (!pi)
  400. return;
  401. }
  402. for (cch = sizeof(pi->szKey)/sizeof(TCHAR), nInstr = 0, ii = 0;
  403. ! RegEnumKey (hkMidi, ii, pi->szKey, cch);
  404. ++ii)
  405. {
  406. UINT jj;
  407. HKEY hkInst;
  408. PINSTRUM piParent;
  409. BOOL bActive = FALSE;
  410. // get driver alias, external, and active flags. This has the side
  411. // effect of initializing the friendly name key for legacy drivers
  412. // that have neither friendly name, nor description
  413. //
  414. GetAlias (hkMidi, pi->szKey, pi->szFriendly,
  415. NUMELMS(pi->szFriendly), &pi->bExternal, &bActive);
  416. // if requested, stomp friendly name with driver filename
  417. //
  418. if (bDriverAsAlias)
  419. GetDriverFilename (hkMidi, pi->szKey,
  420. pi->szFriendly, NUMELMS(pi->szFriendly));
  421. pi->fGSSynth = QueryGSSynth(pi->szKey);
  422. pi->uID = idxPort;
  423. if (pi->bExternal)
  424. pmcm->bHasExternal = TRUE;
  425. pi->piParent = 0;
  426. pi->bActive = bActive;
  427. piParent = pi;
  428. ++nInstr;
  429. if (nInstr >= NUMELMS(pmcm->api))
  430. {
  431. assert2 (0, TEXT ("Tell JohnKn to make midi instrument table bigger"));
  432. break;
  433. }
  434. if (!(pi = pmcm->api[nInstr]))
  435. {
  436. pmcm->api[nInstr] = pi = (LPVOID)LocalAlloc (LPTR, sizeof(*pi));
  437. if (!pi)
  438. break;
  439. }
  440. // open the parent's instruments subkey
  441. //
  442. lstrcpy (sz, piParent->szKey);
  443. lstrcat (sz, cszSlashInstruments);
  444. if (RegCreateKey (hkMidi, sz, &hkInst))
  445. continue;
  446. // enum the instruments and add them to the list
  447. //
  448. for (jj = 0; ! RegEnumKey (hkInst, jj, sz, cch); ++jj)
  449. {
  450. lstrcpy (pi->szKey, piParent->szKey);
  451. lstrcat (pi->szKey, cszSlashInstruments);
  452. lstrcat (pi->szKey, cszSlash);
  453. lstrcat (pi->szKey, sz);
  454. GetAlias (hkInst, sz, pi->szFriendly,
  455. NUMELMS(pi->szFriendly), NULL, NULL);
  456. pi->piParent = piParent;
  457. pi->bExternal = FALSE;
  458. pi->bActive = bActive;
  459. ++nInstr;
  460. if (nInstr >= NUMELMS(pmcm->api))
  461. {
  462. assert2 (0, TEXT ("Tell JohnKn to make midi instrument table bigger"));
  463. break;
  464. }
  465. if (!(pi = pmcm->api[nInstr]))
  466. {
  467. pmcm->api[nInstr] = pi = (LPVOID)LocalAlloc (LPTR, sizeof(*pi));
  468. if (!pi)
  469. break;
  470. }
  471. }
  472. RegCloseKey (hkInst);
  473. }
  474. // create a 'none' entry at the end
  475. //
  476. if (pi)
  477. {
  478. pi->piParent = 0;
  479. pi->bExternal = FALSE;
  480. pi->bActive = TRUE;
  481. pi->szKey[0] = 0;
  482. LoadString (ghInstance, IDS_NONE, pi->szFriendly, NUMELMS(pi->szFriendly));
  483. ++nInstr;
  484. }
  485. pmcm->nInstr = nInstr;
  486. }
  487. /*+
  488. *
  489. *-=================================================================*/
  490. void WINAPI FreeInstruments (
  491. PMCMIDI pmcm)
  492. {
  493. UINT ii;
  494. for (ii = 0; ii < NUMELMS (pmcm->api); ++ii)
  495. if (pmcm->api[ii])
  496. LocalFree ((HLOCAL)(PVOID)pmcm->api[ii]), pmcm->api[ii] = NULL;
  497. pmcm->nInstr = 0;
  498. }
  499. #ifdef DEBUG
  500. /*+ CleanStringCopy
  501. *
  502. * Replaces unprintable characters with '.'
  503. *
  504. *-=================================================================*/
  505. STATICFN LPTSTR CleanStringCopy (
  506. LPTSTR pszOut,
  507. LPTSTR pszIn,
  508. UINT cbOut)
  509. {
  510. LPTSTR psz = pszOut;
  511. while (cbOut && *pszIn)
  512. {
  513. *psz = (*pszIn >= 32 && *pszIn < 127) ? *pszIn : TEXT('.');
  514. ++psz;
  515. ++pszIn;
  516. }
  517. *psz = 0;
  518. return pszOut;
  519. }
  520. /*+ DumpInstruments
  521. *
  522. *-=================================================================*/
  523. STATICFN void DumpInstruments (
  524. PMCMIDI pmcm)
  525. {
  526. UINT ii;
  527. PINSTRUM pi;
  528. #ifdef DEBUG
  529. AuxDebugEx (3, DEBUGLINE TEXT ("DumpInstruments(%08x) nInstr=%d\r\n"),
  530. pmcm, pmcm->nInstr);
  531. #endif
  532. for (ii = 0; ii < pmcm->nInstr; ++ii)
  533. {
  534. TCHAR szKey[MAX_ALIAS];
  535. TCHAR szFriendly[MAX_ALIAS];
  536. pi = pmcm->api[ii];
  537. if (!pi)
  538. {
  539. #ifdef DEBUG
  540. AuxDebugEx (2, TEXT ("\tapi[%d] NULL\r\n"), ii);
  541. #endif
  542. continue;
  543. }
  544. CleanStringCopy (szKey, pi->szKey, NUMELMS(szKey));
  545. CleanStringCopy (szFriendly, pi->szFriendly, NUMELMS(szFriendly));
  546. #ifdef DEBUG
  547. AuxDebugEx (3, TEXT ("\tapi[%d]%08X p:%08x x:%d a:%d '%s' '%s'\r\n"),
  548. ii, pi, pi->piParent,
  549. pi->bExternal, pi->bActive,
  550. szKey, szFriendly);
  551. #endif
  552. }
  553. }
  554. #endif
  555. /*+
  556. *
  557. *-=================================================================*/
  558. STATICFN PINSTRUM WINAPI FindInstrumPath (
  559. PMCMIDI pmcm,
  560. LPTSTR pszPath)
  561. {
  562. UINT ii;
  563. for (ii = 0; ii < pmcm->nInstr; ++ii)
  564. {
  565. assert (pmcm->api[ii]);
  566. if (IsSzEqual(pszPath, pmcm->api[ii]->szKey))
  567. return pmcm->api[ii];
  568. }
  569. return NULL;
  570. }
  571. /*+
  572. *
  573. *-=================================================================*/
  574. PINSTRUM WINAPI FindInstrumentFromKey (
  575. PMCMIDI pmcm,
  576. LPTSTR pszKey)
  577. {
  578. UINT ii;
  579. if (!pszKey || !pszKey[0])
  580. return NULL;
  581. for (ii = 0; ii < pmcm->nInstr; ++ii)
  582. {
  583. assert (pmcm->api[ii]);
  584. if (IsSzEqual(pszKey, pmcm->api[ii]->szKey))
  585. return pmcm->api[ii];
  586. }
  587. return NULL;
  588. }
  589. /*+
  590. *
  591. *-=================================================================*/
  592. STATICFN void LoadInstrumentsIntoCombo (
  593. HWND hWnd,
  594. UINT uId,
  595. PINSTRUM piSelect,
  596. PMCMIDI pmcm)
  597. {
  598. HWND hWndT = GetDlgItem (hWnd, uId);
  599. UINT ii;
  600. int ix;
  601. #ifdef DEBUG
  602. AuxDebugEx (4, DEBUGLINE TEXT ("LoadInstrumentsIntoCombo(%08X,%d,%08x,%08x)\r\n"),
  603. hWnd, uId, piSelect, pmcm);
  604. #endif
  605. assert (hWndT);
  606. if (!hWndT)
  607. return;
  608. if (pmcm->nInstr > 0)
  609. SetWindowRedraw (hWndT, FALSE);
  610. ComboBox_ResetContent(hWndT);
  611. for (ii = 0; ii < pmcm->nInstr; ++ii)
  612. {
  613. if (ii == pmcm->nInstr-1)
  614. SetWindowRedraw (hWndT, TRUE);
  615. if (pmcm->api[ii]->bActive
  616. #ifdef EXCLUDE_EXTERNAL
  617. && !pmcm->api[ii]->bExternal
  618. #endif
  619. )
  620. {
  621. #ifdef DEBUG
  622. AuxDebugEx (7, DEBUGLINE TEXT ("Instrument[%d] = '%s'\r\n"),
  623. ii, pmcm->api[ii]->szFriendly);
  624. #endif
  625. ix = ComboBox_AddString (hWndT, pmcm->api[ii]->szFriendly);
  626. ComboBox_SetItemData (hWndT, ix, (LPARAM)pmcm->api[ii]);
  627. if (piSelect && pmcm->api[ii] == piSelect)
  628. ComboBox_SetCurSel (hWndT, ix);
  629. }
  630. }
  631. }
  632. /*+
  633. *
  634. *-=================================================================*/
  635. STATICFN void LoadInstrumentsIntoTree (
  636. HWND hWnd,
  637. UINT uId,
  638. UINT uIdSingle,
  639. PINSTRUM piSelect,
  640. PMCLOCAL pmcl)
  641. {
  642. PMCMIDI pmcm = &pmcl->mcm;
  643. HWND hWndT = GetDlgItem (hWnd, uId);
  644. UINT ii;
  645. HTREEITEM htiSelect = NULL;
  646. HTREEITEM htiParent = TVI_ROOT;
  647. assert (hWndT);
  648. if (!hWndT)
  649. return;
  650. #ifdef UNICODE
  651. TreeView_SetUnicodeFormat(hWndT,TRUE);
  652. #endif
  653. //if (pmcm->nInstr > 0)
  654. // SetWindowRedraw (hWndT, FALSE);
  655. pmcl->bIgnoreSelChange = TRUE;
  656. #ifdef DEBUG
  657. AuxDebugEx (6, DEBUGLINE TEXT ("tv_DeleteAllItems(%08X)\r\n"), hWndT);
  658. #endif
  659. TreeView_DeleteAllItems(hWndT);
  660. #ifdef DEBUG
  661. AuxDebugEx (6, DEBUGLINE TEXT ("tv_DeleteAllItems(%08X) ends\r\n"), hWndT);
  662. #endif
  663. pmcl->bIgnoreSelChange = FALSE;
  664. for (ii = 0; ii < pmcm->nInstr; ++ii)
  665. {
  666. PINSTRUM pi = pmcm->api[ii];
  667. TV_INSERTSTRUCT ti;
  668. HTREEITEM hti;
  669. //if (ii == pmcm->nInstr-1)
  670. // SetWindowRedraw (hWndT, TRUE);
  671. if (!pi->szKey[0] || !pi->bActive)
  672. continue;
  673. ZeroMemory (&ti, sizeof(ti));
  674. ti.hParent = TVI_ROOT;
  675. if (pi->piParent)
  676. ti.hParent = htiParent;
  677. ti.hInsertAfter = TVI_SORT;
  678. ti.item.mask = TVIF_TEXT | TVIF_STATE | TVIF_PARAM;
  679. // TV_ITEM may not be ported to UNICODE ?!?
  680. ti.item.pszText = pi->szFriendly;
  681. ti.item.state = TVIS_EXPANDED;
  682. ti.item.stateMask = TVIS_ALL;
  683. ti.item.lParam = (LPARAM)pi;
  684. hti = TreeView_InsertItem (hWndT, &ti);
  685. if (piSelect && (piSelect == pi))
  686. htiSelect = hti;
  687. if ( ! pi->piParent)
  688. htiParent = hti;
  689. }
  690. // if a 'single' control id has been specified, propagate
  691. // selected item text into this control
  692. //
  693. if (uIdSingle)
  694. {
  695. if (htiSelect)
  696. {
  697. assert (piSelect);
  698. TreeView_SelectItem (hWndT, htiSelect);
  699. SetDlgItemText (hWnd, uIdSingle, piSelect->szFriendly);
  700. EnableWindow(GetDlgItem(hWnd, IDC_ABOUTSYNTH), piSelect->fGSSynth);
  701. }
  702. else
  703. SetDlgItemText (hWnd, uIdSingle, cszEmpty);
  704. }
  705. }
  706. /*+
  707. *
  708. *-=================================================================*/
  709. STATICFN void LoadSchemesIntoCombo (
  710. HWND hWnd,
  711. UINT uId,
  712. LPTSTR pszSelect,
  713. PMSCHEME pms)
  714. {
  715. HWND hWndT = GetDlgItem (hWnd, uId);
  716. HKEY hKey;
  717. assert (hWndT);
  718. if (!hWndT)
  719. return;
  720. hKey = pms->hkSchemes;
  721. if (!hKey &&
  722. !RegCreateKey (HKEY_LOCAL_MACHINE, cszSchemeRoot, &hKey))
  723. pms->hkSchemes = hKey;
  724. EnumChildrenIntoCombo (hWndT, pszSelect, hKey);
  725. }
  726. /*+ ChildKeyExists
  727. *
  728. * given an open registry key, and the name of a child of that
  729. * registry key, returns true if a child key with the given
  730. * name exists.
  731. *
  732. *-=================================================================*/
  733. STATICFN BOOL ChildKeyExists (
  734. HKEY hKey,
  735. LPTSTR pszChild)
  736. {
  737. TCHAR sz[MAX_ALIAS];
  738. UINT ii;
  739. if (!hKey)
  740. return FALSE;
  741. for (ii = 0; ! RegEnumKey (hKey, ii, sz, sizeof(sz)/sizeof(TCHAR)); ++ii)
  742. {
  743. if (IsSzEqual (pszChild, sz))
  744. return TRUE;
  745. }
  746. return FALSE;
  747. }
  748. /*+ LoadSchemeFromReg
  749. *
  750. *-=================================================================*/
  751. STATICFN void LoadSchemeFromReg (
  752. PMCMIDI pmcm,
  753. PMSCHEME pms,
  754. LPTSTR pszName)
  755. {
  756. HKEY hKey;
  757. DWORD dwAccum;
  758. UINT count;
  759. // try to open the indicated scheme key in the registry
  760. // and read channel map from it. Failure here is permissible.
  761. // it indicates that we are createing a new scheme.
  762. //
  763. count = 0;
  764. if (RegOpenKey (pms->hkSchemes, pszName, &hKey) == ERROR_SUCCESS)
  765. {
  766. DWORD cb;
  767. TCHAR sz[MAX_ALIAS];
  768. while (RegEnumKey (hKey, count, sz, sizeof(sz)/sizeof(TCHAR)) == ERROR_SUCCESS)
  769. {
  770. HKEY hKeyA;
  771. DWORD dwType;
  772. if (RegOpenKey (hKey, sz, &hKeyA) != ERROR_SUCCESS)
  773. break;
  774. pms->a[count].pi = NULL;
  775. cb = sizeof(sz);
  776. if ( ! RegQueryValue (hKeyA, NULL, sz, &cb))
  777. pms->a[count].pi = FindInstrumPath (pmcm, sz);
  778. pms->a[count].dwMask = 0;
  779. cb = sizeof(pms->a[count].dwMask);
  780. RegQueryValueEx (hKeyA, cszChannels, NULL,
  781. &dwType, (LPBYTE)&pms->a[count].dwMask, &cb);
  782. assert (dwType == REG_DWORD);
  783. RegCloseKey (hKeyA);
  784. // Don't allow empty entries
  785. //assert (pms->a[ii].dwMask);
  786. if (0 == pms->a[count].dwMask)
  787. {
  788. pms->a[count].pi = NULL;
  789. }
  790. ++count;
  791. #ifdef DEBUG
  792. AuxDebugEx (4, DEBUGLINE TEXT ("[%d]Chan %08X Alias '%s'\r\n"),
  793. count, pms->a[count].dwMask, pms->a[count].pi
  794. ? pms->a[count].pi->szFriendly
  795. : TEXT ("(null)"));
  796. #endif
  797. if (count == NUMELMS(pms->a) -1)
  798. break;
  799. }
  800. RegCloseKey (hKey);
  801. }
  802. pms->nChildren = count;
  803. lstrcpyn (pms->szName, pszName, NUMELMS(pms->szName));
  804. // slam a dummy (none) alias that matches all channels
  805. // at the end of our channel/alias list
  806. //
  807. assert (count < NUMELMS(pms->a));
  808. pms->a[count].dwMask = (DWORD)~0;
  809. pms->a[count].pi = NULL;
  810. #ifdef DEBUG
  811. AuxDebugEx (4, DEBUGLINE TEXT ("[%d]Chan %08X Alias '%s'\r\n"),
  812. count, pms->a[count].dwMask, "null");
  813. #endif
  814. // make sure scheme channel masks are in a valid state
  815. //
  816. for (dwAccum = 0, count = 0; count < NUMELMS(pms->a); ++count)
  817. {
  818. pms->a[count].dwMask &= ~dwAccum;
  819. dwAccum |= pms->a[count].dwMask;
  820. }
  821. return;
  822. }
  823. /*+ KickMapper
  824. *
  825. *-=================================================================*/
  826. void WINAPI KickMapper (
  827. HWND hWnd)
  828. {
  829. HMIDIOUT hmo;
  830. if (! midiOutOpen(&hmo, MIDI_MAPPER, 0, 0, MIDI_IO_CONTROL))
  831. {
  832. BOOL bDone;
  833. #ifdef DEBUG
  834. AuxDebugEx (2, DEBUGLINE TEXT ("Kicking Midi Mapper\r\n"));
  835. #endif
  836. bDone = midiOutMessage(hmo, DRVM_MAPPER_RECONFIGURE, 0, DRV_F_PROP_INSTR);
  837. midiOutClose(hmo);
  838. /*
  839. //no longer necessary due to winmm change allowing configure during play
  840. if (!bDone && hWnd)
  841. TellUser (hWnd, IDS_MAPPER_BUSY, NULL);
  842. */
  843. }
  844. #ifdef DEBUG
  845. AuxDebugEx (2, DEBUGLINE TEXT ("Done Kicking Midi Mapper\r\n"));
  846. #endif
  847. }
  848. /*+ SaveSchemeToReg
  849. *
  850. *-=================================================================*/
  851. STATICFN void SaveSchemeToReg (
  852. PMCMIDI pmcm,
  853. PMSCHEME pms,
  854. LPTSTR pszName,
  855. HWND hWnd)
  856. {
  857. TCHAR sz[MAX_ALIAS];
  858. HKEY hKey;
  859. DWORD dwAccum;
  860. UINT ii;
  861. UINT kk;
  862. UINT cb;
  863. #ifdef DEBUG
  864. AuxDebugEx (4, DEBUGLINE TEXT ("Saving Scheme '%s' children=%d\r\n"),
  865. pszName, pms->nChildren);
  866. for (ii = 0; ii < NUMELMS(pms->a); ++ii)
  867. {
  868. AuxDebugEx (4, TEXT ("\t%08X '%s'\r\n"),
  869. pms->a[ii].dwMask,
  870. pms->a[ii].pi ? pms->a[ii].pi->szKey : TEXT ("(null)"));
  871. }
  872. #endif
  873. // make sure scheme channel masks are in a valid state,
  874. // that is, prevent a channel bit from being set in more
  875. // than one member of a scheme
  876. //
  877. for (dwAccum = 0, ii = 0; ii < NUMELMS(pms->a); ++ii)
  878. {
  879. pms->a[ii].dwMask &= ~dwAccum;
  880. dwAccum |= pms->a[ii].dwMask;
  881. }
  882. // try to open/create the indicated scheme key in the registry
  883. // and write/update channel map to it.
  884. //
  885. if (!RegCreateKey (pms->hkSchemes, pszName, &hKey))
  886. {
  887. HKEY hKeyA;
  888. BOOL bKill;
  889. // salvage all of the existing keys that we can. delete
  890. // the rest.
  891. //
  892. for (dwAccum = 0, ii = 0; !RegEnumKey (hKey, ii, sz, sizeof(sz)/sizeof(TCHAR)); ++ii)
  893. {
  894. if (ii >= NUMELMS(pms->a))
  895. break;
  896. // we reuse the first N keys in this scheme
  897. // and delete the rest.
  898. //
  899. bKill = TRUE;
  900. if (((dwAccum & 0xFFFF) != 0xFFFF) &&
  901. pms->a[ii].pi &&
  902. (!ii || (pms->a[ii].pi->szKey[0] && pms->a[ii].dwMask)))
  903. bKill = FALSE;
  904. dwAccum |= pms->a[ii].dwMask;
  905. // if we have an obsolete alias key, remove it now
  906. // otherwise create/open the alias key and set it's
  907. // channel property to the correct value.
  908. //
  909. if (bKill)
  910. {
  911. #ifdef DEBUG
  912. AuxDebugEx (3, DEBUGLINE TEXT ("Deleting key[%d] '%s'\r\n"), ii, sz);
  913. #endif
  914. RegDeleteKey (hKey, sz);
  915. }
  916. else
  917. {
  918. #ifdef DEBUG
  919. AuxDebugEx (3, DEBUGLINE TEXT ("Reusing key[%d] '%s'\r\n"), ii, pms->a[ii].pi->szKey);
  920. #endif
  921. if (RegOpenKeyEx (hKey, sz, 0, KEY_ALL_ACCESS, &hKeyA))
  922. break;
  923. cb = (lstrlen(pms->a[ii].pi->szKey) + 1) * sizeof(TCHAR);
  924. RegSetValueEx (hKeyA, NULL, 0, REG_SZ,
  925. (LPBYTE)(pms->a[ii].pi->szKey), cb);
  926. RegSetValueEx (hKeyA, cszChannels, 0,
  927. REG_DWORD,
  928. (LPBYTE)&pms->a[ii].dwMask,
  929. sizeof(DWORD));
  930. RegCloseKey (hKeyA);
  931. }
  932. }
  933. // if we have channels that have not yet been written.
  934. // do that now
  935. //
  936. for (kk = 0; ii < NUMELMS(pms->a); ++ii)
  937. {
  938. // if this alias has any assigned channels, create
  939. // a key and give it a channels value
  940. //
  941. if (pms->a[ii].pi &&
  942. (!ii || (pms->a[ii].pi->szKey[0] && pms->a[ii].dwMask)))
  943. {
  944. #ifdef DEBUG
  945. AuxDebugEx (3, DEBUGLINE TEXT ("Creating key[%d] '%s'\r\n"), ii, pms->a[ii].pi->szKey);
  946. #endif
  947. // find an unused keyname;
  948. //
  949. for ( ; kk < NUMELMS(pms->a); ++kk)
  950. {
  951. wsprintf (sz, csz02d, kk);
  952. if (RegOpenKey (hKey, sz, &hKeyA))
  953. break;
  954. RegCloseKey (hKeyA);
  955. }
  956. // create a key with that name
  957. //
  958. if (RegCreateKey (hKey, sz, &hKeyA))
  959. break;
  960. cb = (lstrlen(pms->a[ii].pi->szKey) + 1) * sizeof(TCHAR);
  961. RegSetValueEx (hKeyA, NULL, 0, REG_SZ,
  962. (LPBYTE)(pms->a[ii].pi->szKey),cb);
  963. #ifdef DEBUG
  964. AuxDebugEx (3, DEBUGLINE TEXT ("Setting Channel Value %08X\r\n"), pms->a[ii].dwMask);
  965. #endif
  966. RegSetValueEx (hKeyA, cszChannels, 0,
  967. REG_DWORD,
  968. (LPBYTE)&pms->a[ii].dwMask,
  969. sizeof(DWORD));
  970. RegCloseKey (hKeyA);
  971. }
  972. }
  973. RegCloseKey (hKey);
  974. }
  975. // if no HWND supplied, we are in the runonce, so we dont
  976. // want to kick mapper just because a scheme has changed
  977. //
  978. if (hWnd)
  979. KickMapper (hWnd);
  980. return;
  981. }
  982. /*+ DeleteSchemeFromReg
  983. *
  984. *-=================================================================*/
  985. STATICFN void DeleteSchemeFromReg (
  986. HKEY hkSchemes,
  987. LPTSTR pszName)
  988. {
  989. TCHAR sz[MAX_ALIAS];
  990. HKEY hKey;
  991. UINT ii;
  992. #ifdef DEBUG
  993. AuxDebugEx (4, DEBUGLINE TEXT ("DeletingSchemeFromReg(%08X,'%s')\r\n"),
  994. hkSchemes,pszName);
  995. #endif
  996. SHRegDeleteKey(hkSchemes, pszName);
  997. /*
  998. // if we cannot open this key as a child of the 'schemes' key
  999. // we are done.
  1000. //
  1001. if (RegOpenKey (hkSchemes, pszName, &hKey))
  1002. return;
  1003. // Before we can delete a key, we must delete its children
  1004. //
  1005. for (ii = 0; !RegEnumKey (hKey, ii, sz, sizeof(sz)/sizeof(TCHAR)); ++ii)
  1006. {
  1007. // if we have an obsolete alias key, remove it now
  1008. // otherwise create/open the alias key and set it's
  1009. // channel property to the correct value.
  1010. //
  1011. AuxDebugEx (3, DEBUGLINE TEXT ("Deleting key[%d] '%s'\r\n"), ii, sz);
  1012. RegDeleteKey (hKey, sz);
  1013. }
  1014. RegCloseKey (hKey);
  1015. // now delete this key
  1016. //
  1017. RegDeleteKey (hkSchemes, pszName);
  1018. return;
  1019. */
  1020. }
  1021. /*+
  1022. *
  1023. *-=================================================================*/
  1024. STATICFN void LoadChannelsIntoList (
  1025. HWND hWnd,
  1026. UINT uId,
  1027. UINT uIdLabel,
  1028. PMSCHEME pms)
  1029. {
  1030. HWND hWndT = GetDlgItem (hWnd, uId);
  1031. RECT rc;
  1032. UINT ii;
  1033. UINT nChan;
  1034. int nTabs;
  1035. assert (pms);
  1036. // empty the list
  1037. //
  1038. SetWindowRedraw (hWndT, FALSE);
  1039. ListBox_ResetContent (hWndT);
  1040. // calculate the width of the tabstop
  1041. // so that the second column lines up under the indicated
  1042. // label
  1043. //
  1044. GetWindowRect (GetDlgItem(hWnd, uIdLabel), &rc);
  1045. nTabs = rc.left;
  1046. GetWindowRect (hWnd, &rc);
  1047. nTabs = MulDiv(nTabs - rc.left, 4, LOWORD(GetDialogBaseUnits()));
  1048. ListBox_SetTabStops (hWndT, 1, &nTabs);
  1049. // fill the list with channel data
  1050. //
  1051. for (nChan = 0; nChan < NUM_CHANNEL; ++nChan)
  1052. {
  1053. static CONST TCHAR cszDtabS[] = TEXT ("%d\t%s");
  1054. TCHAR sz[MAX_ALIAS + 10];
  1055. for (ii = 0; ii < NUMELMS(pms->a); ++ii)
  1056. if (pms->a[ii].dwMask & (1 << nChan))
  1057. break;
  1058. assert (ii < NUMELMS(pms->a));
  1059. wsprintf (sz, cszDtabS, nChan+1,
  1060. pms->a[ii].pi ? pms->a[ii].pi->szFriendly
  1061. : pms->szNone);
  1062. if (nChan == (UINT)NUM_CHANNEL-1)
  1063. SetWindowRedraw (hWndT, TRUE);
  1064. ListBox_InsertString (hWndT, nChan, sz);
  1065. if (pms->dwChanMask & (1 << nChan))
  1066. ListBox_SetSel (hWndT, TRUE, nChan);
  1067. }
  1068. }
  1069. /*+
  1070. *
  1071. *-=================================================================*/
  1072. /*+ ChannelMaskToEdit
  1073. *
  1074. * convert a bit mask to a string containing list of set bits
  1075. * and bit ranges. Then SetWindowText the result into the given
  1076. * edit control.
  1077. *
  1078. * This function loads prefix text from resource strings.
  1079. *
  1080. * For Example: ChannelMaskToEdit(....0x0000F0F) would set the text
  1081. * 'Channels 1-4,9-12'.
  1082. *
  1083. *-=================================================================*/
  1084. STATICFN void ChannelMaskToEdit (
  1085. HWND hWnd,
  1086. UINT uId,
  1087. DWORD dwMask)
  1088. {
  1089. HWND hWndT = GetDlgItem (hWnd, uId);
  1090. TCHAR sz[NUM_CHANNEL * 4 + MAX_ALIAS];
  1091. if (!dwMask)
  1092. LoadString (ghInstance, IDS_NOCHAN, sz, NUMELMS(sz));
  1093. else
  1094. {
  1095. LPTSTR psz;
  1096. LPTSTR pszT;
  1097. int ii;
  1098. int iSpan;
  1099. DWORD dwLast;
  1100. DWORD dwBit;
  1101. LoadString (ghInstance,
  1102. (dwMask & (dwMask-1)) ? IDS_CHANPLURAL : IDS_CHANSINGULAR,
  1103. sz, NUMELMS(sz));
  1104. pszT = psz = sz + lstrlen(sz);
  1105. for (ii = 0, dwBit = 1, dwLast = 0, iSpan = 0;
  1106. ii <= 32;
  1107. dwLast = dwMask & dwBit, ++ii, dwBit += dwBit)
  1108. {
  1109. if ((dwMask & dwBit) ^ (dwLast + dwLast))
  1110. {
  1111. static CONST TCHAR cszCommaD[] = TEXT (",%d");
  1112. static CONST TCHAR cszDashD[] = TEXT ("-%d");
  1113. if ( ! dwLast)
  1114. psz += wsprintf (psz, cszCommaD, ii+1);
  1115. else if (iSpan)
  1116. psz += wsprintf (psz, cszDashD, ii);
  1117. iSpan = 0;
  1118. }
  1119. else
  1120. ++iSpan;
  1121. }
  1122. *pszT = TEXT (' ');
  1123. }
  1124. SetWindowText (hWndT, sz);
  1125. }
  1126. /*+ MidiChangeCommands
  1127. *
  1128. *-=================================================================*/
  1129. BOOL WINAPI MidiChangeCommands (
  1130. HWND hWnd,
  1131. UINT wId,
  1132. HWND hWndCtl,
  1133. UINT wNotify)
  1134. {
  1135. PMCLOCAL pmcl = GetDlgData(hWnd);
  1136. PMSCHEME pms = &pmcl->ms;
  1137. #ifdef DEBUG
  1138. AuxDebugEx (5, DEBUGLINE TEXT ("MidiChangeCommands(%08X,%d,%08X,%d)\r\n"),
  1139. hWnd, wId, hWndCtl, wNotify);
  1140. #endif
  1141. switch (wId)
  1142. {
  1143. case ID_APPLY:
  1144. return TRUE;
  1145. case IDOK:
  1146. {
  1147. int ix;
  1148. HWND hWndT = GetDlgItem (hWnd, IDC_INSTRUMENTS);
  1149. ix = ComboBox_GetCurSel (hWndT);
  1150. if (ix >= 0)
  1151. {
  1152. BOOL bFound = FALSE;
  1153. PINSTRUM piSel;
  1154. BOOL bFoundFirst = FALSE;
  1155. piSel = (LPVOID)ComboBox_GetItemData (hWndT, ix);
  1156. assert (!IsBadWritePtr(piSel, sizeof(*piSel)));
  1157. // has the <none> item been selected? in this
  1158. // case, set stuff up so that we will not try
  1159. // to add none to the scheme, but we will clear
  1160. // all bits from other channels that are set
  1161. // to none.
  1162. //
  1163. if ( ! piSel || ! piSel->szKey[0])
  1164. piSel = NULL, bFound = TRUE;
  1165. // turn channels on for this instrument and off for
  1166. // other instruments in this scheme.
  1167. //
  1168. for (ix = 0; ix < (int)NUMELMS(pms->a); ++ix)
  1169. {
  1170. if (pms->a[ix].pi != piSel)
  1171. pms->a[ix].dwMask &= ~pms->dwChanMask;
  1172. else if (! pms->a[ix].pi)
  1173. {
  1174. if (! bFoundFirst)
  1175. {
  1176. pms->a[ix].dwMask |= pms->dwChanMask;
  1177. bFound = TRUE;
  1178. bFoundFirst = TRUE;
  1179. }
  1180. }
  1181. else
  1182. {
  1183. pms->a[ix].dwMask |= pms->dwChanMask;
  1184. bFound = TRUE;
  1185. }
  1186. }
  1187. // if this instrument was not already in the scheme,
  1188. // find an empty slot and add it to the scheme.
  1189. //
  1190. if (!bFound)
  1191. {
  1192. for (ix = 0; ix < (int)NUMELMS(pms->a); ++ix)
  1193. {
  1194. if ( ! pms->a[ix].dwMask)
  1195. {
  1196. pms->a[ix].dwMask = pms->dwChanMask;
  1197. pms->a[ix].pi = piSel;
  1198. bFound = TRUE;
  1199. break;
  1200. }
  1201. }
  1202. }
  1203. assert2 (bFound, TEXT ("no room to add instrument to scheme"));
  1204. }
  1205. EndDialog (hWnd, IDOK);
  1206. break;
  1207. }
  1208. case IDCANCEL:
  1209. EndDialog (hWnd, IDCANCEL);
  1210. break;
  1211. //
  1212. //case ID_INIT:
  1213. // break;
  1214. }
  1215. return FALSE;
  1216. }
  1217. /*+ SaveAsDlgProc
  1218. *
  1219. *-=================================================================*/
  1220. const static DWORD aSaveAsHelpIds[] = { // Context Help IDs
  1221. IDE_SCHEMENAME, IDH_MIDI_SAVEDLG_SCHEMENAME,
  1222. 0, 0
  1223. };
  1224. INT_PTR CALLBACK SaveAsDlgProc (
  1225. HWND hWnd,
  1226. UINT uMsg,
  1227. WPARAM wParam,
  1228. LPARAM lParam)
  1229. {
  1230. switch (uMsg)
  1231. {
  1232. case WM_COMMAND:
  1233. switch (GET_WM_COMMAND_ID(wParam, lParam))
  1234. {
  1235. case IDOK:
  1236. {
  1237. LPTSTR pszName = GetDlgData (hWnd);
  1238. assert (pszName);
  1239. GetDlgItemText (hWnd, IDE_SCHEMENAME, pszName, MAX_ALIAS);
  1240. }
  1241. // fall through
  1242. case IDCANCEL:
  1243. EndDialog (hWnd, GET_WM_COMMAND_ID(wParam, lParam));
  1244. break;
  1245. }
  1246. break;
  1247. case WM_CLOSE:
  1248. SendMessage (hWnd, WM_COMMAND, IDCANCEL, 0);
  1249. break;
  1250. case WM_INITDIALOG:
  1251. {
  1252. LPTSTR pszName = (LPVOID) lParam;
  1253. assert (pszName);
  1254. SetDlgData (hWnd, pszName);
  1255. SetDlgItemText (hWnd, IDE_SCHEMENAME, pszName);
  1256. break;
  1257. }
  1258. case WM_CONTEXTMENU:
  1259. WinHelp ((HWND) wParam, NULL, HELP_CONTEXTMENU,
  1260. (UINT_PTR) (LPTSTR) aSaveAsHelpIds);
  1261. return TRUE;
  1262. case WM_HELP:
  1263. {
  1264. LPHELPINFO lphi = (LPVOID) lParam;
  1265. WinHelp (lphi->hItemHandle, NULL, HELP_WM_HELP,
  1266. (UINT_PTR) (LPTSTR) aSaveAsHelpIds);
  1267. return TRUE;
  1268. }
  1269. }
  1270. return FALSE;
  1271. }
  1272. /*+ GetNewSchemeName
  1273. *
  1274. *-=================================================================*/
  1275. STATICFN BOOL WINAPI GetNewSchemeName (
  1276. HWND hWnd,
  1277. HKEY hkSchemes,
  1278. LPTSTR pszName)
  1279. {
  1280. TCHAR szNew[MAX_ALIAS];
  1281. UINT_PTR uBtn;
  1282. lstrcpy (szNew, pszName);
  1283. uBtn = DialogBoxParam (ghInstance,
  1284. MAKEINTRESOURCE(IDD_SAVENAME),
  1285. hWnd,
  1286. SaveAsDlgProc,
  1287. (LPARAM)szNew);
  1288. if (IDOK == uBtn)
  1289. {
  1290. if (ChildKeyExists (hkSchemes, szNew))
  1291. uBtn = Confirm (hWnd, IDS_QUERY_OVERSCHEME, szNew);
  1292. else
  1293. lstrcpy (pszName, szNew);
  1294. }
  1295. return (IDOK == uBtn || IDYES == uBtn);
  1296. }
  1297. /*+ MidiChangeDlgProc
  1298. *
  1299. *-=================================================================*/
  1300. const static DWORD aChngInstrHelpIds[] = { // Context Help IDs
  1301. IDC_INSTRUMENTS, IDH_ADDMIDI_INSTRUMENT,
  1302. IDC_TEXT_1, IDH_ADDMIDI_CHANNEL,
  1303. IDE_SHOW_CHANNELS, IDH_ADDMIDI_CHANNEL,
  1304. 0, 0
  1305. };
  1306. INT_PTR CALLBACK MidiChangeDlgProc (
  1307. HWND hWnd,
  1308. UINT uMsg,
  1309. WPARAM wParam,
  1310. LPARAM lParam)
  1311. {
  1312. switch (uMsg)
  1313. {
  1314. case WM_COMMAND:
  1315. HANDLE_WM_COMMAND (hWnd, wParam, lParam, MidiChangeCommands);
  1316. break;
  1317. case WM_NOTIFY:
  1318. ForwardBillNotify(hWnd, (NMHDR FAR *)lParam);
  1319. break;
  1320. case WM_CLOSE:
  1321. SendMessage (hWnd, WM_COMMAND, IDCANCEL, 0);
  1322. break;
  1323. case WM_INITDIALOG:
  1324. {
  1325. PMCLOCAL pmcl = (LPVOID) lParam;
  1326. PMSCHEME pms = &pmcl->ms;
  1327. SetDlgData (hWnd, pmcl);
  1328. LoadInstrumentsIntoCombo (hWnd, IDC_INSTRUMENTS, NULL, &pmcl->mcm);
  1329. ChannelMaskToEdit (hWnd, IDE_SHOW_CHANNELS, pms->dwChanMask);
  1330. break;
  1331. }
  1332. //case WM_DESTROY:
  1333. // break;
  1334. case WM_CONTEXTMENU:
  1335. WinHelp ((HWND) wParam, NULL, HELP_CONTEXTMENU,
  1336. (UINT_PTR) (LPTSTR) aChngInstrHelpIds);
  1337. return TRUE;
  1338. case WM_HELP:
  1339. {
  1340. LPHELPINFO lphi = (LPVOID) lParam;
  1341. WinHelp (lphi->hItemHandle, NULL, HELP_WM_HELP,
  1342. (UINT_PTR) (LPTSTR) aChngInstrHelpIds);
  1343. return TRUE;
  1344. }
  1345. }
  1346. return FALSE;
  1347. }
  1348. /*+ MidiConfigCommands
  1349. *
  1350. *-=================================================================*/
  1351. BOOL WINAPI MidiConfigCommands (
  1352. HWND hWnd,
  1353. UINT wId,
  1354. HWND hWndCtl,
  1355. UINT wNotify)
  1356. {
  1357. PMCLOCAL pmcl = GetDlgData(hWnd);
  1358. PMSCHEME pms = &pmcl->ms;
  1359. #ifdef DEBUG
  1360. AuxDebugEx (5, DEBUGLINE TEXT ("MidiConfigCommands(%08X,%d,%08X,%d)\r\n"),
  1361. hWnd, wId, hWndCtl, wNotify);
  1362. #endif
  1363. switch (wId)
  1364. {
  1365. case IDB_CHANGE:
  1366. {
  1367. UINT_PTR uRet;
  1368. int ii;
  1369. HWND hWndList = GetDlgItem (hWnd, IDL_CHANNELS);
  1370. #ifdef DEBUG
  1371. AuxDebugEx (2, DEBUGLINE TEXT ("Launching Change Dialog\r\n"));
  1372. #endif
  1373. pms->dwChanMask = 0;
  1374. for (ii = 0; ii < NUM_CHANNEL; ++ii)
  1375. if (ListBox_GetSel (hWndList, ii))
  1376. pms->dwChanMask |= (1 << ii);
  1377. uRet = DialogBoxParam (ghInstance,
  1378. MAKEINTRESOURCE(IDD_MIDICHANGE),
  1379. hWnd,
  1380. MidiChangeDlgProc,
  1381. (LPARAM)pmcl);
  1382. if (uRet == IDOK)
  1383. {
  1384. LoadChannelsIntoList (hWnd, IDL_CHANNELS, IDC_TEXT_1, pms);
  1385. pms->bDirty = TRUE;
  1386. }
  1387. break;
  1388. }
  1389. case IDB_DELETE:
  1390. if (IsSzEqual(pmcl->szScheme, pmcl->szDefault))
  1391. {
  1392. break;
  1393. }
  1394. if (Confirm (hWnd, IDS_QUERY_DELETESCHEME, pmcl->szScheme) == IDYES)
  1395. {
  1396. HWND hWndCtl = GetDlgItem (hWnd, IDC_SCHEMES);
  1397. int ix = ComboBox_FindStringExact (hWndCtl, -1, pmcl->szScheme);
  1398. assert (ix >= 0);
  1399. DeleteSchemeFromReg (pms->hkSchemes, pmcl->szScheme);
  1400. ComboBox_DeleteString (hWndCtl, ix);
  1401. ComboBox_SetCurSel (hWndCtl, 0);
  1402. SimulateNotify (hWnd, IDC_SCHEMES, CBN_SELCHANGE);
  1403. }
  1404. break;
  1405. case IDB_SAVE_AS:
  1406. if (GetNewSchemeName (hWnd, pms->hkSchemes, pmcl->szScheme))
  1407. {
  1408. SaveSchemeToReg (&pmcl->mcm, pms, pmcl->szScheme, hWnd);
  1409. LoadSchemesIntoCombo (hWnd, IDC_SCHEMES,
  1410. pmcl->szScheme, pms);
  1411. }
  1412. SimulateNotify (hWnd, IDC_SCHEMES, CBN_SELCHANGE);
  1413. break;
  1414. case IDC_SCHEMES:
  1415. if (wNotify == CBN_SELCHANGE)
  1416. {
  1417. int ix;
  1418. ix = ComboBox_GetCurSel (hWndCtl);
  1419. if (ix >= 0)
  1420. ComboBox_GetLBText (hWndCtl, ix, pmcl->szScheme);
  1421. LoadSchemeFromReg (&pmcl->mcm, pms, pmcl->szScheme);
  1422. pms->dwChanMask = 0;
  1423. LoadChannelsIntoList (hWnd, IDL_CHANNELS, IDC_TEXT_1, pms);
  1424. EnableWindow (GetDlgItem (hWnd, IDB_DELETE),
  1425. !IsSzEqual(pmcl->szDefault, pmcl->szScheme));
  1426. }
  1427. break;
  1428. case IDL_CHANNELS:
  1429. if (wNotify == LBN_SELCHANGE)
  1430. {
  1431. int ix;
  1432. ix = ListBox_GetSelCount (hWndCtl);
  1433. EnableWindow (GetDlgItem (hWnd, IDB_CHANGE), (ix > 0));
  1434. }
  1435. break;
  1436. case IDOK:
  1437. {
  1438. SaveSchemeToReg (&pmcl->mcm, pms, pmcl->szScheme, hWnd);
  1439. EndDialog (hWnd, IDOK);
  1440. break;
  1441. }
  1442. case IDCANCEL:
  1443. EndDialog (hWnd, IDCANCEL);
  1444. break;
  1445. }
  1446. return FALSE;
  1447. }
  1448. /*+ MidiConfigDlgProc
  1449. *
  1450. *-=================================================================*/
  1451. const static DWORD aMidiConfigHelpIds[] = { // Context Help IDs
  1452. IDC_GROUPBOX, IDH_COMM_GROUPBOX,
  1453. IDC_SCHEMES, IDH_MIDI_CFGDLG_SCHEME,
  1454. IDB_SAVE_AS, IDH_MIDI_CFGDLG_SAVEAS,
  1455. IDB_DELETE, IDH_MIDI_CFGDLG_DELETE,
  1456. IDC_GROUPBOX_2, IDH_COMM_GROUPBOX,
  1457. IDL_CHANNELS, IDH_MIDI_INSTRUMENTS,
  1458. IDB_CHANGE, IDH_MIDI_CFGDLG_CHANGE,
  1459. IDC_TEXT_1, IDH_MIDI_INSTRUMENTS,
  1460. IDC_TEXT_2, IDH_MIDI_INSTRUMENTS,
  1461. IDC_TEXT_3, NO_HELP,
  1462. 0, 0
  1463. };
  1464. INT_PTR CALLBACK MidiConfigDlgProc (
  1465. HWND hWnd,
  1466. UINT uMsg,
  1467. WPARAM wParam,
  1468. LPARAM lParam)
  1469. {
  1470. switch (uMsg)
  1471. {
  1472. case WM_COMMAND:
  1473. HANDLE_WM_COMMAND (hWnd, wParam, lParam, MidiConfigCommands);
  1474. break;
  1475. case WM_NOTIFY:
  1476. ForwardBillNotify(hWnd, (NMHDR FAR *)lParam);
  1477. break;
  1478. case WM_CLOSE:
  1479. SendMessage (hWnd, WM_COMMAND, IDCANCEL, 0);
  1480. break;
  1481. case WM_INITDIALOG:
  1482. {
  1483. PMCLOCAL pmcl = (LPVOID) lParam;
  1484. assert (pmcl);
  1485. SetDlgData (hWnd, pmcl);
  1486. LoadString (ghInstance, IDS_NONE, pmcl->ms.szNone, NUMELMS(pmcl->ms.szNone));
  1487. LoadSchemesIntoCombo (hWnd, IDC_SCHEMES, pmcl->szScheme, &pmcl->ms);
  1488. SimulateNotify (hWnd, IDC_SCHEMES, CBN_SELCHANGE);
  1489. EnableWindow (GetDlgItem(hWnd, IDB_CHANGE), FALSE);
  1490. break;
  1491. }
  1492. case WM_CONTEXTMENU:
  1493. WinHelp ((HWND) wParam, NULL, HELP_CONTEXTMENU,
  1494. (UINT_PTR) (LPTSTR) aMidiConfigHelpIds);
  1495. return TRUE;
  1496. case WM_HELP:
  1497. {
  1498. LPHELPINFO lphi = (LPVOID) lParam;
  1499. WinHelp (lphi->hItemHandle, NULL, HELP_WM_HELP,
  1500. (UINT_PTR) (LPTSTR) aMidiConfigHelpIds);
  1501. return TRUE;
  1502. }
  1503. }
  1504. return FALSE;
  1505. }
  1506. STATICFN void WINAPI PickMidiInstrument(
  1507. LPTSTR pszKey)
  1508. {
  1509. HKEY hKeyMR, hKeyDriver;
  1510. UINT cDevs;
  1511. UINT ii, jj;
  1512. DWORD cbSize, dwType;
  1513. LPMIDIOUTCAPS pmoc;
  1514. MMRESULT mmr;
  1515. PWSTR pszDevIntDev, pszDevIntKey;
  1516. UINT aTech[] = { MOD_SWSYNTH,
  1517. MOD_WAVETABLE,
  1518. MOD_SYNTH,
  1519. MOD_FMSYNTH,
  1520. MOD_SQSYNTH,
  1521. MOD_MIDIPORT};
  1522. UINT cTech = sizeof(aTech)/sizeof(aTech[0]);
  1523. TCHAR szKey[MAX_ALIAS];
  1524. TCHAR szPname[MAXPNAMELEN];
  1525. TCHAR szPnameTarget[MAXPNAMELEN];
  1526. LONG lr;
  1527. szPname[0] = 0;
  1528. cDevs = midiOutGetNumDevs();
  1529. if (0 == cDevs)
  1530. {
  1531. return;
  1532. }
  1533. pmoc = (LPMIDIOUTCAPS)LocalAlloc (LPTR, cDevs * sizeof(MIDIOUTCAPS));
  1534. if (NULL == pmoc)
  1535. {
  1536. return;
  1537. }
  1538. for (ii = cDevs; ii; ii--)
  1539. {
  1540. mmr = midiOutGetDevCaps(ii - 1, &(pmoc[ii - 1]), sizeof(MIDIOUTCAPS));
  1541. if (MMSYSERR_NOERROR != mmr)
  1542. {
  1543. LocalFree ((HLOCAL)pmoc);
  1544. return;
  1545. }
  1546. }
  1547. for (ii = 0; ii < cTech; ii++)
  1548. {
  1549. for (jj = cDevs; jj; jj--)
  1550. {
  1551. if (pmoc[jj - 1].wTechnology == aTech[ii])
  1552. {
  1553. lstrcpy(szPname, pmoc[jj - 1].szPname);
  1554. break;
  1555. }
  1556. }
  1557. if (jj)
  1558. {
  1559. // Broke out of inner loop, found match
  1560. break;
  1561. }
  1562. }
  1563. LocalFree ((HLOCAL)pmoc);
  1564. if (0 == jj)
  1565. {
  1566. // This should never happen...
  1567. return;
  1568. }
  1569. jj--;
  1570. mmr = midiOutMessage (HMIDIOUT_INDEX(jj), DRV_QUERYDEVICEINTERFACESIZE, (DWORD_PTR)(PULONG)&cbSize, 0L);
  1571. if (MMSYSERR_NOERROR != mmr)
  1572. {
  1573. return;
  1574. }
  1575. pszDevIntDev = (PWSTR)LocalAlloc (LPTR, cbSize);
  1576. if (NULL == pszDevIntDev)
  1577. {
  1578. return;
  1579. }
  1580. mmr = midiOutMessage (HMIDIOUT_INDEX(jj), DRV_QUERYDEVICEINTERFACE, (DWORD_PTR)pszDevIntDev, (DWORD)cbSize);
  1581. if (MMSYSERR_NOERROR != mmr)
  1582. {
  1583. LocalFree ((HLOCAL)pszDevIntDev);
  1584. return;
  1585. }
  1586. lr = RegOpenKey(HKEY_LOCAL_MACHINE, cszDriversRoot, &hKeyMR);
  1587. if (ERROR_SUCCESS != lr)
  1588. {
  1589. LocalFree ((HLOCAL)pszDevIntDev);
  1590. return;
  1591. }
  1592. for (ii = 0; ; )
  1593. {
  1594. lr = RegEnumKey(hKeyMR, ii++, szKey, sizeof(szKey)/sizeof(szKey[0]));
  1595. if (ERROR_SUCCESS != lr)
  1596. {
  1597. RegCloseKey(hKeyMR);
  1598. LocalFree ((HLOCAL)pszDevIntDev);
  1599. return;
  1600. }
  1601. lr = RegOpenKey(hKeyMR, szKey, &hKeyDriver);
  1602. if (ERROR_SUCCESS != lr)
  1603. {
  1604. RegCloseKey(hKeyMR);
  1605. LocalFree ((HLOCAL)pszDevIntDev);
  1606. return;
  1607. }
  1608. cbSize = sizeof(szPnameTarget);
  1609. lr = RegQueryValueEx(
  1610. hKeyDriver,
  1611. cszActive,
  1612. NULL,
  1613. &dwType,
  1614. (LPSTR)szPnameTarget,
  1615. &cbSize);
  1616. if (ERROR_SUCCESS != lr)
  1617. {
  1618. RegCloseKey(hKeyDriver);
  1619. RegCloseKey(hKeyMR);
  1620. LocalFree ((HLOCAL)pszDevIntDev);
  1621. return;
  1622. }
  1623. if (TEXT('1') != szPnameTarget[0])
  1624. {
  1625. RegCloseKey(hKeyDriver);
  1626. continue;
  1627. }
  1628. cbSize = sizeof(szPnameTarget);
  1629. lr = RegQueryValueEx(
  1630. hKeyDriver,
  1631. cszDescription,
  1632. NULL,
  1633. &dwType,
  1634. (LPSTR)szPnameTarget,
  1635. &cbSize);
  1636. if (ERROR_SUCCESS != lr)
  1637. {
  1638. RegCloseKey(hKeyDriver);
  1639. RegCloseKey(hKeyMR);
  1640. LocalFree ((HLOCAL)pszDevIntDev);
  1641. return;
  1642. }
  1643. if (0 != lstrcmp(szPnameTarget, szPname))
  1644. {
  1645. RegCloseKey(hKeyDriver);
  1646. continue;
  1647. }
  1648. cbSize = 0;
  1649. lr = RegQueryValueExW (
  1650. hKeyDriver,
  1651. L"DeviceInterface",
  1652. NULL,
  1653. &dwType,
  1654. (LPSTR)NULL,
  1655. &cbSize);
  1656. if (ERROR_SUCCESS != lr)
  1657. {
  1658. RegCloseKey(hKeyDriver);
  1659. RegCloseKey(hKeyMR);
  1660. LocalFree ((HLOCAL)pszDevIntDev);
  1661. return;
  1662. }
  1663. pszDevIntKey = (PWSTR) LocalAlloc (LPTR, cbSize);
  1664. if (NULL == pszDevIntKey)
  1665. {
  1666. RegCloseKey(hKeyDriver);
  1667. RegCloseKey(hKeyMR);
  1668. LocalFree ((HLOCAL)pszDevIntDev);
  1669. return;
  1670. }
  1671. lr = RegQueryValueExW (
  1672. hKeyDriver,
  1673. L"DeviceInterface",
  1674. NULL,
  1675. &dwType,
  1676. (LPSTR)pszDevIntKey,
  1677. &cbSize);
  1678. RegCloseKey(hKeyDriver);
  1679. if (ERROR_SUCCESS != lr)
  1680. {
  1681. LocalFree ((HLOCAL)pszDevIntKey);
  1682. RegCloseKey(hKeyMR);
  1683. LocalFree ((HLOCAL)pszDevIntDev);
  1684. return;
  1685. }
  1686. if (0 == lstrcmpiW(pszDevIntKey, pszDevIntDev))
  1687. {
  1688. LocalFree ((HLOCAL)pszDevIntKey);
  1689. RegCloseKey(hKeyMR);
  1690. LocalFree ((HLOCAL)pszDevIntDev);
  1691. lstrcpy(pszKey, szKey);
  1692. return;
  1693. }
  1694. LocalFree ((HLOCAL)pszDevIntKey);
  1695. }
  1696. }
  1697. /*+ SaveLocal
  1698. *
  1699. *-=================================================================*/
  1700. STATICFN void WINAPI SaveLocal (
  1701. PMCLOCAL pmcl,
  1702. BOOL bUserSetting,
  1703. HWND hWnd) // optional window to report errors: NULL - no reports
  1704. {
  1705. HKEY hKey = NULL;
  1706. UINT cb;
  1707. #ifdef DEBUG
  1708. AuxDebugEx (2, DEBUGLINE TEXT ("SaveLocal(%08X,%X) %s\r\n"),
  1709. pmcl, hWnd, pmcl->pszReason ? pmcl->pszReason : TEXT (""));
  1710. #endif
  1711. if ((RegCreateKey (HKEY_CURRENT_USER, cszMidiMapRoot, &hKey) == ERROR_SUCCESS) && hKey)
  1712. {
  1713. cb = (lstrlen(pmcl->szScheme) + 1) * sizeof(TCHAR);
  1714. RegSetValueEx (hKey, cszCurrentScheme, 0, REG_SZ,
  1715. (LPBYTE)pmcl->szScheme, cb);
  1716. //assert (pmcl->piSingle);
  1717. if ((pmcl->piSingle) && (pmcl->piSingle->bActive))
  1718. {
  1719. #ifdef DEBUG
  1720. AuxDebugEx (2, DEBUGLINE TEXT ("Setting CurrentInstrument Key to %08X '%s'\r\n"),
  1721. pmcl->piSingle, pmcl->piSingle->szKey);
  1722. #endif
  1723. cb = (lstrlen(pmcl->piSingle->szKey) + 1) * sizeof(TCHAR);
  1724. RegSetValueEx (hKey, cszCurrentInstrument, 0, REG_SZ,
  1725. (LPBYTE)(pmcl->piSingle->szKey),
  1726. cb);
  1727. }
  1728. else
  1729. {
  1730. // Assume No Match
  1731. TCHAR szKey[MAX_ALIAS];
  1732. LONG lr;
  1733. szKey[0] = 0;
  1734. RegSetValueEx (hKey, cszCurrentInstrument, 0, REG_SZ, (LPBYTE)cszEmpty, 0);
  1735. PickMidiInstrument(szKey);
  1736. cb = (lstrlen(szKey) + 1) * sizeof(TCHAR);
  1737. lr = RegSetValueEx (hKey, cszCurrentInstrument, 0, REG_SZ,
  1738. (LPBYTE)(szKey), cb);
  1739. }
  1740. RegSetValueEx (hKey, cszUseScheme, 0, REG_DWORD,
  1741. (LPBYTE)&pmcl->bUseScheme, sizeof(pmcl->bUseScheme));
  1742. if (bUserSetting)
  1743. pmcl->bAutoScheme = FALSE;
  1744. RegSetValueEx (hKey, cszAutoScheme, 0, REG_DWORD,
  1745. (LPBYTE)&pmcl->bAutoScheme, sizeof(pmcl->bAutoScheme));
  1746. RegSetValueEx (hKey, cszRunOnceCount, 0, REG_DWORD,
  1747. (LPBYTE)&pmcl->dwRunCount, sizeof(pmcl->dwRunCount));
  1748. if (pmcl->pszReason)
  1749. {
  1750. cb = (lstrlen(pmcl->pszReason) + 1) * sizeof(TCHAR);
  1751. RegSetValueEx (hKey, cszDriverList, 0, REG_SZ,
  1752. (LPBYTE)pmcl->pszReason, cb);
  1753. }
  1754. else
  1755. RegSetValueEx (hKey, cszDriverList, 0, REG_SZ, (LPBYTE)cszEmpty, 0);
  1756. RegCloseKey (hKey);
  1757. // Don't Kick mapper unless we have a window
  1758. if (hWnd)
  1759. KickMapper (hWnd);
  1760. }
  1761. }
  1762. /*+ InitLocal
  1763. *
  1764. *-=================================================================*/
  1765. STATICFN void WINAPI InitLocal (
  1766. PMCLOCAL pmcl,
  1767. LPARAM lParam,
  1768. BOOL bDriverAsAlias) // driver as alias mode used only for scheme init
  1769. {
  1770. HKEY hKey;
  1771. LoadString (ghInstance, IDS_DEFAULT_SCHEME_NAME,
  1772. pmcl->szDefault, NUMELMS(pmcl->szDefault));
  1773. // NOTE : Comment below regarding RunOnceSchemeInit is in reference
  1774. // to an obsolete RunOnce initialization.
  1775. //
  1776. // we allow driver as alias (szFriendly) only for InitLocal when called
  1777. // from RunOnceSchemeInit. this works because in this case we have
  1778. // no UI so we dont need the friendly names for anything.
  1779. //
  1780. assert (!bDriverAsAlias || lParam == 0);
  1781. LoadInstruments (&pmcl->mcm, bDriverAsAlias);
  1782. #ifdef DEBUG
  1783. if (mmdebug_OutputLevel >= 3)
  1784. DumpInstruments (&pmcl->mcm);
  1785. #endif
  1786. if (RegCreateKey (HKEY_CURRENT_USER, cszMidiMapRoot, &hKey) == ERROR_SUCCESS)
  1787. {
  1788. DWORD cb;
  1789. DWORD dwType;
  1790. TCHAR szSingle[MAX_ALIAS];
  1791. cb = sizeof(pmcl->szScheme);
  1792. if (RegQueryValueEx (hKey, cszCurrentScheme, NULL, &dwType, (LPBYTE)pmcl->szScheme, &cb))
  1793. pmcl->szScheme[0] = 0;
  1794. pmcl->piSingle = NULL;
  1795. cb = sizeof(szSingle);
  1796. if (!RegQueryValueEx (hKey, cszCurrentInstrument, NULL, &dwType, (LPBYTE)szSingle, &cb))
  1797. pmcl->piSingle = FindInstrumentFromKey (&pmcl->mcm, szSingle);
  1798. cb = sizeof(pmcl->bUseScheme);
  1799. if (RegQueryValueEx (hKey, cszUseScheme, NULL, &dwType, (LPBYTE)&pmcl->bUseScheme, &cb))
  1800. pmcl->bUseScheme = 0;
  1801. cb = sizeof(pmcl->bAutoScheme);
  1802. if (RegQueryValueEx (hKey, cszAutoScheme, NULL, &dwType, (LPBYTE)&pmcl->bAutoScheme, &cb))
  1803. pmcl->bAutoScheme = TRUE;
  1804. cb = sizeof(pmcl->dwRunCount);
  1805. if (RegQueryValueEx (hKey, cszRunOnceCount, NULL, &dwType, (LPBYTE)&pmcl->dwRunCount, &cb))
  1806. pmcl->dwRunCount = 0;
  1807. pmcl->pszReason = NULL;
  1808. RegCloseKey (hKey);
  1809. }
  1810. pmcl->ppsp = (LPVOID)lParam;
  1811. }
  1812. /*+ FixupHinderedIDFs
  1813. *
  1814. *-=================================================================*/
  1815. VOID WINAPI FixupHinderedIDFs (
  1816. PMCLOCAL pmcl,
  1817. LPTSTR pszTemp, // ptr to temp memory
  1818. UINT cchTemp) // size of temp memory
  1819. {
  1820. HKEY hkHind; // hinderedMidiList root
  1821. LPTSTR pszDriver = pszTemp; // max size is short filename
  1822. UINT cch;
  1823. LPTSTR pszIDF = (LPVOID)(pszTemp + MAX_PATH);
  1824. UINT cbSize;
  1825. DWORD iEnum;
  1826. DWORD dwType;
  1827. #ifdef DEBUG
  1828. AuxDebugEx (3, DEBUGLINE TEXT ("FixupHinderedIDFs(%08x)\r\n"), pmcl);
  1829. #endif
  1830. assert (pszTemp);
  1831. assert (cchTemp > MAX_PATH + MAX_PATH + 64);
  1832. // the midi key should have already been opened.
  1833. //
  1834. assert (pmcl->mcm.hkMidi);
  1835. if (RegCreateKey (HKEY_LOCAL_MACHINE, cszHinderedMidiList, &hkHind))
  1836. return;
  1837. // enumerate the known hindered driver list looking for
  1838. // drivers that need to have their IDF's set
  1839. //
  1840. for (iEnum = 0, cch = MAX_PATH, cbSize = (MAX_PATH + 64) * sizeof(TCHAR);
  1841. ! RegEnumValue (hkHind, iEnum, pszDriver, &cch, NULL, &dwType, (LPBYTE)pszIDF, &cbSize);
  1842. ++iEnum, cch = MAX_PATH, cbSize = (MAX_PATH + 64) * sizeof(TCHAR))
  1843. {
  1844. UINT ii;
  1845. #ifdef DEBUG
  1846. AuxDebugEx (3, DEBUGLINE TEXT ("enum[%d] pszDriver='%s' pszIDF='%s'\r\n"), iEnum, pszDriver, pszIDF);
  1847. #endif
  1848. // just to be careful. ignore any registry entry that
  1849. // does not have string data
  1850. //
  1851. assert (dwType == REG_SZ);
  1852. if (dwType != REG_SZ)
  1853. continue;
  1854. // scan through the list of drivers looking for one that is
  1855. // internal, and has the same driver name as one of our known
  1856. // list of hindered drivers. if we find one, force its
  1857. // IDF to be the given IDF
  1858. //
  1859. for (ii = 0; ii < pmcl->mcm.nInstr; ++ii)
  1860. {
  1861. PINSTRUM pi = pmcl->mcm.api[ii];
  1862. HKEY hkSub;
  1863. if (!pi || !pi->szKey[0] || pi->bExternal ||
  1864. !IsSzEqual (pi->szFriendly, pszDriver))
  1865. continue;
  1866. #ifdef DEBUG
  1867. AuxDebugEx (2, DEBUGLINE TEXT ("forcing driver '%s' to use IDF '%s'\r\n"), pi->szKey, pszIDF);
  1868. #endif
  1869. if ( ! RegOpenKeyEx (pmcl->mcm.hkMidi, pi->szKey, 0, KEY_ALL_ACCESS, &hkSub))
  1870. {
  1871. RegSetValueEx (hkSub, cszDefinition, 0, REG_SZ, (LPBYTE)pszIDF, cbSize);
  1872. RegCloseKey (hkSub);
  1873. }
  1874. }
  1875. }
  1876. RegCloseKey (hkHind);
  1877. return;
  1878. }
  1879. STDAPI_(void) HandleSynthAboutBox(HWND hWnd)
  1880. {
  1881. HWND hTree = GetDlgItem(hWnd, IDL_INSTRUMENTS);
  1882. HTREEITEM hItem = TreeView_GetSelection(hTree);
  1883. TV_ITEM ti;
  1884. PINSTRUM pi;
  1885. memset(&ti, 0, sizeof(ti));
  1886. ti.mask = TVIF_PARAM;
  1887. ti.hItem = hItem;
  1888. TreeView_GetItem (hTree, &ti);
  1889. pi = (LPVOID)ti.lParam;
  1890. if (pi)
  1891. {
  1892. UINT uWaveID;
  1893. if (GetWaveID(&uWaveID) != (MMRESULT)MMSYSERR_ERROR)
  1894. {
  1895. WAVEOUTCAPS woc;
  1896. if (waveOutGetDevCaps(uWaveID, &woc, sizeof(woc)) == MMSYSERR_NOERROR)
  1897. {
  1898. RolandProp(hWnd, ghInstance, woc.szPname);
  1899. }
  1900. }
  1901. }
  1902. }
  1903. /*+ MidiCplCommands
  1904. *
  1905. *-=================================================================*/
  1906. BOOL WINAPI MidiCplCommands (
  1907. HWND hWnd,
  1908. UINT wId,
  1909. HWND hWndCtl,
  1910. UINT wNotify)
  1911. {
  1912. PMCLOCAL pmcl = GetDlgData(hWnd);
  1913. #ifdef DEBUG
  1914. AuxDebugEx (3, DEBUGLINE TEXT ("MidiCplCommands(%08X,%X,%08X,%d)\r\n"),
  1915. hWnd, wId, hWndCtl, wNotify);
  1916. #endif
  1917. assert (pmcl);
  1918. if (!pmcl)
  1919. return FALSE;
  1920. switch (wId)
  1921. {
  1922. case IDB_CONFIGURE:
  1923. {
  1924. UINT_PTR uRet;
  1925. TCHAR szOld[MAX_ALIAS];
  1926. #ifdef DEBUG
  1927. AuxDebugEx (2, DEBUGLINE TEXT ("Launching Config Dialog\r\n"));
  1928. #endif
  1929. lstrcpy (szOld, pmcl->szScheme);
  1930. uRet = DialogBoxParam (ghInstance,
  1931. MAKEINTRESOURCE(IDD_MIDICONFIG),
  1932. hWnd,
  1933. MidiConfigDlgProc,
  1934. (LPARAM)pmcl);
  1935. if (uRet != IDOK)
  1936. lstrcpy (pmcl->szScheme, szOld);
  1937. else
  1938. PropSheet_Changed(GetParent(hWnd), hWnd);
  1939. LoadSchemesIntoCombo (hWnd, IDC_SCHEMES, pmcl->szScheme, &pmcl->ms);
  1940. }
  1941. break;
  1942. case IDC_ABOUTSYNTH:
  1943. {
  1944. HandleSynthAboutBox(hWnd);
  1945. }
  1946. break;
  1947. case IDB_ADDWIZ:
  1948. #ifdef DEBUG
  1949. AuxDebugEx (2, DEBUGLINE TEXT ("Launching Midi Wizard\r\n"));
  1950. #endif
  1951. MidiInstrumentsWizard (hWnd, &pmcl->mcm, NULL);
  1952. LoadInstruments (&pmcl->mcm, FALSE);
  1953. #ifdef DEBUG
  1954. if (mmdebug_OutputLevel >= 3)
  1955. DumpInstruments (&pmcl->mcm);
  1956. #endif
  1957. if (pmcl->bDlgType2)
  1958. {
  1959. LoadInstrumentsIntoTree (hWnd, IDL_INSTRUMENTS, IDC_INSTRUMENTS,
  1960. pmcl->piSingle, pmcl);
  1961. }
  1962. else
  1963. {
  1964. LoadInstrumentsIntoCombo (hWnd, IDC_INSTRUMENTS,
  1965. pmcl->piSingle, &pmcl->mcm);
  1966. }
  1967. MMExtPropSheetCallback(MM_EPS_BLIND_TREECHANGE, 0,0,0);
  1968. break;
  1969. case IDC_SCHEMES:
  1970. if (wNotify == CBN_SELCHANGE)
  1971. {
  1972. int ix;
  1973. ix = ComboBox_GetCurSel (hWndCtl);
  1974. if (ix >= 0)
  1975. ComboBox_GetLBText (hWndCtl, ix, pmcl->szScheme);
  1976. PropSheet_Changed(GetParent(hWnd), hWnd);
  1977. }
  1978. break;
  1979. case IDC_INSTRUMENTS:
  1980. if (wNotify == CBN_SELCHANGE)
  1981. {
  1982. int ix;
  1983. assert (!pmcl->bDlgType2);
  1984. ix = ComboBox_GetCurSel (hWndCtl);
  1985. if (ix >= 0)
  1986. {
  1987. pmcl->piSingle = (LPVOID)ComboBox_GetItemData (hWndCtl, ix);
  1988. }
  1989. PropSheet_Changed(GetParent(hWnd), hWnd);
  1990. }
  1991. break;
  1992. case IDC_RADIO_CUSTOM:
  1993. case IDC_RADIO_SINGLE:
  1994. {
  1995. BOOL bUseScheme = pmcl->bUseScheme;
  1996. pmcl->bUseScheme = IsDlgButtonChecked (hWnd, IDC_RADIO_CUSTOM);
  1997. if (bUseScheme != pmcl->bUseScheme)
  1998. PropSheet_Changed(GetParent(hWnd), hWnd);
  1999. if (pmcl->bDlgType2)
  2000. {
  2001. HWND hWndCtl;
  2002. EnableWindow(GetDlgItem (hWnd, IDL_INSTRUMENTS), !pmcl->bUseScheme);
  2003. if (hWndCtl = GetDlgItem (hWnd, IDB_DETAILS))
  2004. EnableWindow(hWndCtl, !pmcl->bUseScheme);
  2005. }
  2006. EnableWindow(GetDlgItem (hWnd, IDC_INSTRUMENTS), !pmcl->bUseScheme);
  2007. EnableWindow(GetDlgItem (hWnd, IDC_SCHEMES), pmcl->bUseScheme);
  2008. EnableWindow(GetDlgItem (hWnd, IDC_SCHEMESLABEL), pmcl->bUseScheme);
  2009. EnableWindow(GetDlgItem (hWnd, IDB_CONFIGURE), pmcl->bUseScheme);
  2010. }
  2011. break;
  2012. #if 1 //def DETAILS_FROM_MAIN_CPL
  2013. case IDB_DETAILS:
  2014. assert (pmcl->bDlgType2);
  2015. if (pmcl->bDlgType2)
  2016. {
  2017. TCHAR szSingle[MAX_PATH];
  2018. int ix;
  2019. ix = ComboBox_GetCurSel (hWndCtl);
  2020. if (ix >= 0)
  2021. pmcl->piSingle = (LPVOID)ComboBox_GetItemData (hWndCtl, ix);
  2022. szSingle[0] = 0;
  2023. if (pmcl->piSingle)
  2024. lstrcpy (szSingle, pmcl->piSingle->szKey);
  2025. if (ShowDetails (hWnd, pmcl))
  2026. {
  2027. LoadInstruments (&pmcl->mcm, FALSE);
  2028. pmcl->piSingle = FindInstrumentFromKey (&pmcl->mcm, szSingle);
  2029. LoadInstrumentsIntoTree (hWnd, IDL_INSTRUMENTS,
  2030. IDC_INSTRUMENTS, pmcl->piSingle,
  2031. pmcl);
  2032. }
  2033. }
  2034. break;
  2035. #endif
  2036. case ID_INIT:
  2037. LoadInstruments (&pmcl->mcm, FALSE);
  2038. #ifdef DEBUG
  2039. if (mmdebug_OutputLevel >= 3)
  2040. DumpInstruments (&pmcl->mcm);
  2041. #endif
  2042. if (pmcl->bDlgType2)
  2043. {
  2044. LoadInstrumentsIntoTree (hWnd, IDL_INSTRUMENTS, IDC_INSTRUMENTS,
  2045. pmcl->piSingle, pmcl);
  2046. }
  2047. else
  2048. {
  2049. LoadInstrumentsIntoCombo (hWnd, IDC_INSTRUMENTS,
  2050. pmcl->piSingle, &pmcl->mcm);
  2051. }
  2052. break;
  2053. case ID_APPLY:
  2054. pmcl->bUseScheme = IsDlgButtonChecked (hWnd, IDC_RADIO_CUSTOM);
  2055. SaveLocal (pmcl, TRUE, hWnd);
  2056. break;
  2057. case IDOK:
  2058. pmcl->bUseScheme = IsDlgButtonChecked (hWnd, IDC_RADIO_CUSTOM);
  2059. break;
  2060. case IDCANCEL:
  2061. break;
  2062. //
  2063. //case ID_INIT:
  2064. // break;
  2065. }
  2066. return FALSE;
  2067. }
  2068. /*+ HandleInstrumentsSelChange
  2069. *
  2070. *-=================================================================*/
  2071. STATICFN BOOL WINAPI HandleInstrumentsSelChange (
  2072. HWND hWnd,
  2073. LPNMHDR lpnm)
  2074. {
  2075. PMCLOCAL pmcl = GetDlgData(hWnd);
  2076. LPNM_TREEVIEW pntv = (LPVOID)lpnm;
  2077. LPTV_ITEM pti = &pntv->itemNew;
  2078. TV_ITEM ti;
  2079. PINSTRUM pi;
  2080. TCHAR szSingle[MAX_ALIAS];
  2081. BOOL bChange = FALSE;
  2082. if (!pmcl || pmcl->bIgnoreSelChange)
  2083. return FALSE;
  2084. // setup ti to get text & # of children
  2085. // from the IDF filename entry.
  2086. //
  2087. ti.mask = TVIF_TEXT | TVIF_PARAM;
  2088. ti.pszText = szSingle;
  2089. ti.cchTextMax = NUMELMS(szSingle);
  2090. ti.hItem = pti->hItem;
  2091. TreeView_GetItem (lpnm->hwndFrom, &ti);
  2092. pi = (LPVOID)ti.lParam; // FindInstrument (&pmcl->mcm, szSingle);
  2093. #ifdef DEBUG
  2094. AuxDebugEx (2, DEBUGLINE TEXT ("HandInstSelChg(%X,...) %X %X Init=%d\r\n"),
  2095. hWnd, pmcl->piSingle, pi, !pmcl->bPastInit);
  2096. #endif
  2097. SetDlgItemText (hWnd, IDC_INSTRUMENTS, szSingle);
  2098. if (pmcl->piSingle != pi)
  2099. {
  2100. EnableWindow(GetDlgItem(hWnd,IDC_ABOUTSYNTH),pi->fGSSynth);
  2101. bChange = TRUE;
  2102. pmcl->piSingle = pi;
  2103. }
  2104. return (bChange && pmcl->bPastInit);
  2105. }
  2106. /*+ MidiCplDlgProc
  2107. *
  2108. *-=================================================================*/
  2109. const static DWORD aKeyWordIds[] = { // Context Help IDs
  2110. IDC_GROUPBOX, IDH_COMM_GROUPBOX,
  2111. IDC_RADIO_SINGLE, IDH_MIDI_SINGLE_INST_BUTTON,
  2112. IDC_INSTRUMENTS, IDH_MIDI_SINGLE_INST,
  2113. IDL_INSTRUMENTS, IDH_MIDI_SINGLE_INST_LIST,
  2114. IDC_RADIO_CUSTOM, IDH_MIDI_CUST_CONFIG,
  2115. IDC_SCHEMESLABEL, IDH_MIDI_SCHEME,
  2116. IDC_SCHEMES, IDH_MIDI_SCHEME,
  2117. IDC_ABOUTSYNTH, IDH_ABOUT,
  2118. //IDB_DETAILS, IDH_MIDI_SINGLE_INST_PROP,
  2119. IDB_CONFIGURE, IDH_MIDI_CONFIG_SCHEME,
  2120. IDB_ADDWIZ, IDH_MIDI_ADD_NEW,
  2121. 0, 0
  2122. };
  2123. INT_PTR CALLBACK MidiCplDlgProc (
  2124. HWND hWnd,
  2125. UINT uMsg,
  2126. WPARAM wParam,
  2127. LPARAM lParam)
  2128. {
  2129. #ifdef DEBUG
  2130. AuxDebugEx (5, DEBUGLINE TEXT ("MidiCplDlgProc(%08X,%X,%08X,%08X)\r\n"),
  2131. hWnd, uMsg, wParam, lParam);
  2132. #endif
  2133. switch (uMsg)
  2134. {
  2135. case WM_COMMAND:
  2136. HANDLE_WM_COMMAND (hWnd, wParam, lParam, MidiCplCommands);
  2137. break;
  2138. case WM_NOTIFY:
  2139. {
  2140. LPNMHDR lpnm = (LPVOID)lParam;
  2141. if (lpnm->idFrom == (UINT)IDL_INSTRUMENTS &&
  2142. lpnm->code == TVN_SELCHANGED)
  2143. {
  2144. if (HandleInstrumentsSelChange (hWnd, lpnm))
  2145. PropSheet_Changed(GetParent(hWnd), hWnd);
  2146. }
  2147. else
  2148. ForwardBillNotify(hWnd, (NMHDR FAR *)lParam);
  2149. }
  2150. break;
  2151. case WM_INITDIALOG:
  2152. {
  2153. PMCLOCAL pmcl;
  2154. pmcl = (LPVOID)LocalAlloc(LPTR, sizeof(*pmcl));
  2155. SetDlgData (hWnd, pmcl);
  2156. if (!pmcl)
  2157. {
  2158. break;
  2159. }
  2160. pmcl->bPastInit = FALSE;
  2161. InitLocal (pmcl, lParam, FALSE);
  2162. EnableWindow (GetDlgItem (hWnd, IDB_ADDWIZ), pmcl->mcm.bHasExternal & AccessServiceController());
  2163. EnableWindow(GetDlgItem(hWnd, IDC_ABOUTSYNTH), FALSE);
  2164. if (GetDlgItem(hWnd, IDL_INSTRUMENTS))
  2165. {
  2166. pmcl->bDlgType2 = TRUE;
  2167. LoadInstrumentsIntoTree (hWnd, IDL_INSTRUMENTS,
  2168. IDC_INSTRUMENTS, pmcl->piSingle,
  2169. pmcl);
  2170. }
  2171. else
  2172. {
  2173. pmcl->bDlgType2 = FALSE;
  2174. LoadInstrumentsIntoCombo (hWnd, IDC_INSTRUMENTS,
  2175. pmcl->piSingle, &pmcl->mcm);
  2176. }
  2177. CheckRadioButton (hWnd,
  2178. IDC_RADIO_SINGLE,
  2179. IDC_RADIO_CUSTOM,
  2180. pmcl->bUseScheme ? IDC_RADIO_CUSTOM
  2181. : IDC_RADIO_SINGLE);
  2182. LoadSchemesIntoCombo (hWnd, IDC_SCHEMES,
  2183. pmcl->szScheme, &pmcl->ms);
  2184. if (pmcl->mcm.nInstr > 1)
  2185. {
  2186. if (pmcl->bDlgType2)
  2187. {
  2188. HWND hWndCtl;
  2189. EnableWindow(GetDlgItem (hWnd, IDL_INSTRUMENTS), !pmcl->bUseScheme);
  2190. if (hWndCtl = GetDlgItem (hWnd, IDB_DETAILS))
  2191. EnableWindow (hWndCtl, !pmcl->bUseScheme);
  2192. }
  2193. EnableWindow(GetDlgItem (hWnd, IDC_INSTRUMENTS), !pmcl->bUseScheme);
  2194. EnableWindow(GetDlgItem (hWnd, IDC_SCHEMES), pmcl->bUseScheme);
  2195. EnableWindow(GetDlgItem (hWnd, IDC_SCHEMESLABEL), pmcl->bUseScheme);
  2196. EnableWindow(GetDlgItem (hWnd, IDB_CONFIGURE), pmcl->bUseScheme);
  2197. }
  2198. else
  2199. {
  2200. UINT aid[] = { IDL_INSTRUMENTS, IDC_INSTRUMENTS, IDC_SCHEMES,
  2201. IDC_RADIO_SINGLE, IDC_RADIO_CUSTOM,
  2202. IDB_CONFIGURE, IDB_DETAILS, IDB_ADDWIZ };
  2203. UINT ii;
  2204. for (ii = 0; ii < NUMELMS(aid); ++ii)
  2205. {
  2206. HWND hWndCtl = GetDlgItem (hWnd, aid[ii]);
  2207. if (hWndCtl)
  2208. EnableWindow (hWndCtl, FALSE);
  2209. }
  2210. }
  2211. pmcl->bPastInit = TRUE;
  2212. break;
  2213. }
  2214. case WM_DESTROY:
  2215. {
  2216. PMCLOCAL pmcl = GetDlgData(hWnd);
  2217. #ifdef DEBUG
  2218. AuxDebugEx (5, DEBUGLINE TEXT ("MidiCPL - begin WM_DESTROY\r\n"));
  2219. #endif
  2220. if (pmcl)
  2221. {
  2222. if (pmcl->mcm.hkMidi)
  2223. RegCloseKey (pmcl->mcm.hkMidi);
  2224. if (pmcl->ms.hkSchemes)
  2225. RegCloseKey (pmcl->ms.hkSchemes);
  2226. FreeInstruments (&pmcl->mcm);
  2227. SetDlgData (hWnd, 0);
  2228. LocalFree ((HLOCAL)(UINT_PTR)(DWORD_PTR)pmcl);
  2229. }
  2230. #ifdef DEBUG
  2231. AuxDebugEx (5, DEBUGLINE TEXT ("MidiCPL - done with WM_DESTROY\r\n"));
  2232. #endif
  2233. break;
  2234. }
  2235. //case WM_DROPFILES:
  2236. // break;
  2237. case WM_CONTEXTMENU:
  2238. WinHelp ((HWND) wParam, NULL, HELP_CONTEXTMENU,
  2239. (UINT_PTR) (LPTSTR) aKeyWordIds);
  2240. return TRUE;
  2241. case WM_HELP:
  2242. {
  2243. LPHELPINFO lphi = (LPVOID) lParam;
  2244. WinHelp (lphi->hItemHandle, NULL, HELP_WM_HELP,
  2245. (UINT_PTR) (LPTSTR) aKeyWordIds);
  2246. return TRUE;
  2247. }
  2248. #if 0
  2249. default:
  2250. if (uMsg == wHelpMessage)
  2251. {
  2252. WinHelp (hWnd, gszWindowsHlp, HELP_CONTEXT, ID_SND_HELP);
  2253. return TRUE;
  2254. }
  2255. break;
  2256. #endif
  2257. }
  2258. return FALSE;
  2259. }
  2260. /*+ MidiClassCommands
  2261. *
  2262. *-=================================================================*/
  2263. BOOL WINAPI MidiClassCommands (
  2264. HWND hWnd,
  2265. UINT wId,
  2266. HWND hWndCtl,
  2267. UINT wNotify)
  2268. {
  2269. PMCLOCAL pmcl = GetDlgData(hWnd);
  2270. if (!pmcl) return FALSE;
  2271. #ifdef DEBUG
  2272. AuxDebugEx (5, DEBUGLINE TEXT ("MidiClassCommands(%08X,%d,%08X,%d)\r\n"),
  2273. hWnd, wId, hWndCtl, wNotify);
  2274. #endif
  2275. switch (wId)
  2276. {
  2277. case IDB_ADDWIZ:
  2278. MidiInstrumentsWizard (hWnd, &pmcl->mcm, NULL);
  2279. LoadInstruments (&pmcl->mcm, FALSE);
  2280. LoadInstrumentsIntoTree (hWnd, IDL_INSTRUMENTS, 0, NULL, pmcl);
  2281. // flog the parent property sheet to let it know that we have
  2282. // made changes to the advanced midi page structures
  2283. //
  2284. {
  2285. PMPSARGS pmpsa = (LPVOID)pmcl->ppsp->lParam;
  2286. if (pmpsa && pmpsa->lpfnMMExtPSCallback)
  2287. pmpsa->lpfnMMExtPSCallback (MM_EPS_TREECHANGE, 0, 0, pmpsa->lParam);
  2288. }
  2289. break;
  2290. //case ID_APPLY:
  2291. // return TRUE;
  2292. //
  2293. //case IDCANCEL:
  2294. // break;
  2295. }
  2296. return FALSE;
  2297. }
  2298. /*+ MidiClassDlgProc
  2299. *
  2300. *-=================================================================*/
  2301. const static DWORD aMidiClassHelpIds[] = { // Context Help IDs
  2302. IDB_ADDWIZ, IDH_MIDI_ADD_NEW,
  2303. IDC_CLASS_ICON, NO_HELP,
  2304. IDC_CLASS_LABEL, NO_HELP,
  2305. IDL_INSTRUMENTS, IDH_MMCPL_DEVPROP_INST_LIST,
  2306. 0, 0
  2307. };
  2308. INT_PTR CALLBACK MidiClassDlgProc (
  2309. HWND hWnd,
  2310. UINT uMsg,
  2311. WPARAM wParam,
  2312. LPARAM lParam)
  2313. {
  2314. switch (uMsg)
  2315. {
  2316. case WM_COMMAND:
  2317. HANDLE_WM_COMMAND (hWnd, wParam, lParam, MidiClassCommands);
  2318. break;
  2319. case WM_NOTIFY:
  2320. ForwardBillNotify (hWnd, (NMHDR FAR *)lParam);
  2321. break;
  2322. case WM_INITDIALOG:
  2323. {
  2324. PMCLOCAL pmcl;
  2325. TCHAR sz[MAX_ALIAS];
  2326. pmcl = (LPVOID)LocalAlloc(LPTR, sizeof(*pmcl));
  2327. SetDlgData (hWnd, pmcl);
  2328. if (!pmcl)
  2329. {
  2330. break;
  2331. }
  2332. InitLocal (pmcl, lParam, FALSE);
  2333. #ifdef DEBUG
  2334. AuxDebugEx (5, DEBUGLINE TEXT ("midiClass.WM_INITDLG ppsp=%08X\r\n"), pmcl->ppsp);
  2335. #endif
  2336. //AuxDebugDump (8, pmcl->ppsp, sizeof(*pmcl->ppsp));
  2337. LoadString (ghInstance, IDS_MIDI_DEV_AND_INST, sz, NUMELMS(sz));
  2338. SetDlgItemText (hWnd, IDC_CLASS_LABEL, sz);
  2339. Static_SetIcon(GetDlgItem (hWnd, IDC_CLASS_ICON),
  2340. LoadIcon (ghInstance, MAKEINTRESOURCE(IDI_INSTRUMENT)));
  2341. LoadInstrumentsIntoTree (hWnd, IDL_INSTRUMENTS, 0, NULL, pmcl);
  2342. EnableWindow (GetDlgItem (hWnd, IDB_ADDWIZ), pmcl->mcm.bHasExternal & AccessServiceController());
  2343. break;
  2344. }
  2345. case WM_DESTROY:
  2346. {
  2347. PMCLOCAL pmcl = GetDlgData(hWnd);
  2348. if (pmcl)
  2349. {
  2350. if (pmcl->mcm.hkMidi)
  2351. RegCloseKey (pmcl->mcm.hkMidi);
  2352. if (pmcl->ms.hkSchemes)
  2353. RegCloseKey (pmcl->ms.hkSchemes);
  2354. FreeInstruments (&pmcl->mcm);
  2355. LocalFree ((HLOCAL)(UINT_PTR)(DWORD_PTR)pmcl);
  2356. }
  2357. break;
  2358. }
  2359. case WM_CONTEXTMENU:
  2360. WinHelp ((HWND) wParam, NULL, HELP_CONTEXTMENU,
  2361. (UINT_PTR) (LPTSTR) aMidiClassHelpIds);
  2362. return TRUE;
  2363. case WM_HELP:
  2364. {
  2365. LPHELPINFO lphi = (LPVOID) lParam;
  2366. WinHelp (lphi->hItemHandle, NULL, HELP_WM_HELP,
  2367. (UINT_PTR) (LPTSTR) aMidiClassHelpIds);
  2368. return TRUE;
  2369. }
  2370. }
  2371. return FALSE;
  2372. }
  2373. /*+ PropPageCallback
  2374. *
  2375. * add a property page
  2376. *
  2377. *-=================================================================*/
  2378. UINT CALLBACK PropPageCallback (
  2379. HWND hwnd,
  2380. UINT uMsg,
  2381. LPPROPSHEETPAGE ppsp)
  2382. {
  2383. if (uMsg == PSPCB_RELEASE) {
  2384. //LocalFree ((HLOCAL)(UINT)(DWORD)ppsp->pszTitle);
  2385. LocalFree ((HLOCAL)ppsp->lParam);
  2386. }
  2387. return 1;
  2388. }
  2389. /*+ AddPropPage
  2390. *
  2391. * add a property page
  2392. *
  2393. *-=================================================================*/
  2394. STATICFN HPROPSHEETPAGE WINAPI AddPropPage (
  2395. LPCTSTR pszTitle,
  2396. LPFNMMEXTPROPSHEETCALLBACK lpfnAddPropSheetPage,
  2397. DLGPROC fnDlgProc,
  2398. UINT idTemplate,
  2399. LPARAM lParam)
  2400. {
  2401. PROPSHEETPAGE psp;
  2402. PMPSARGS pmpsa;
  2403. UINT cbSize;
  2404. cbSize = sizeof(MPSARGS) + lstrlen (pszTitle) * sizeof(TCHAR);
  2405. if (pmpsa = (PVOID) LocalAlloc (LPTR, cbSize))
  2406. {
  2407. HPROPSHEETPAGE hpsp;
  2408. lstrcpy (pmpsa->szTitle, pszTitle);
  2409. pmpsa->lpfnMMExtPSCallback = lpfnAddPropSheetPage;
  2410. pmpsa->lParam = lParam;
  2411. psp.dwSize = sizeof(psp);
  2412. psp.dwFlags = PSP_USETITLE | PSP_USECALLBACK;
  2413. psp.hInstance = ghInstance;
  2414. psp.pszTemplate = MAKEINTRESOURCE(idTemplate);
  2415. psp.pszIcon = NULL;
  2416. psp.pszTitle = pmpsa->szTitle;
  2417. psp.pfnDlgProc = fnDlgProc;
  2418. psp.lParam = (LPARAM)pmpsa;
  2419. psp.pfnCallback = PropPageCallback;
  2420. psp.pcRefParent = NULL;
  2421. if (hpsp = CreatePropertySheetPage (&psp))
  2422. {
  2423. if ( ! lpfnAddPropSheetPage ||
  2424. lpfnAddPropSheetPage (MM_EPS_ADDSHEET, (DWORD_PTR)hpsp, 0, lParam))
  2425. {
  2426. return hpsp;
  2427. }
  2428. DestroyPropertySheetPage (hpsp);
  2429. LocalFree ((HLOCAL) pmpsa);
  2430. }
  2431. }
  2432. return NULL;
  2433. }
  2434. /*+ AddInstrumentPages
  2435. *
  2436. * add a midi page to a property sheet. Invoked from Advanced tab
  2437. * of Muitimedia control panel when class midi is selected from
  2438. * the list.
  2439. *
  2440. *-=================================================================*/
  2441. BOOL CALLBACK AddInstrumentPages (
  2442. LPCTSTR pszTitle,
  2443. LPFNMMEXTPROPSHEETCALLBACK lpfnAddPropSheetPage,
  2444. LPARAM lParam)
  2445. {
  2446. HPROPSHEETPAGE hpsp;
  2447. TCHAR sz[MAX_ALIAS];
  2448. #ifdef DEBUG
  2449. AuxDebugEx (3, DEBUGLINE TEXT ("AddInstrumentPages(%08X,%08X,%08X)\r\n"),
  2450. pszTitle, lpfnAddPropSheetPage, lParam);
  2451. #endif
  2452. LoadString (ghInstance, IDS_GENERAL, sz, NUMELMS(sz));
  2453. hpsp = AddPropPage (sz,
  2454. lpfnAddPropSheetPage,
  2455. MidiInstrumentDlgProc,
  2456. IDD_INSTRUMENT_GEN,
  2457. lParam);
  2458. if ( ! hpsp)
  2459. return FALSE;
  2460. LoadString (ghInstance, IDS_MIDIDETAILS, sz, NUMELMS(sz));
  2461. hpsp = AddPropPage (sz,
  2462. lpfnAddPropSheetPage,
  2463. MidiInstrumentDlgProc,
  2464. IDD_INSTRUMENT_DETAIL,
  2465. lParam);
  2466. return (hpsp != NULL);
  2467. }
  2468. /*+ AddDevicePages
  2469. *
  2470. * add a midi page to a property sheet. Invoked from Advanced tab
  2471. * of Multimedia control panel when class midi is selected from
  2472. * the list.
  2473. *
  2474. *-=================================================================*/
  2475. BOOL CALLBACK AddDevicePages (
  2476. LPCTSTR pszTitle,
  2477. LPFNMMEXTPROPSHEETCALLBACK lpfnAddPropSheetPage,
  2478. LPARAM lParam)
  2479. {
  2480. HPROPSHEETPAGE hpsp;
  2481. TCHAR sz[MAX_ALIAS];
  2482. #ifdef DEBUG
  2483. AuxDebugEx (3, DEBUGLINE TEXT ("AddInstrumentPages(%08X,%08X,%08X)\r\n"),
  2484. pszTitle, lpfnAddPropSheetPage, lParam);
  2485. #endif
  2486. LoadString (ghInstance, IDS_MIDIDETAILS, sz, NUMELMS(sz));
  2487. hpsp = AddPropPage (sz,
  2488. lpfnAddPropSheetPage,
  2489. MidiInstrumentDlgProc,
  2490. IDD_DEVICE_DETAIL,
  2491. lParam);
  2492. return (hpsp != NULL);
  2493. }
  2494. /*+ ShowDetails
  2495. *
  2496. * Show Instrument or device details sheet and allow edits
  2497. * return TRUE if changes were made
  2498. *
  2499. *-=================================================================*/
  2500. struct _show_details_args {
  2501. PMCLOCAL pmcl;
  2502. BOOL bChanged;
  2503. PROPSHEETHEADER psh;
  2504. HPROPSHEETPAGE hpsp[2];
  2505. };
  2506. BOOL CALLBACK fnPropCallback (
  2507. DWORD dwFunc,
  2508. DWORD_PTR dwParam1,
  2509. DWORD_PTR dwParam2,
  2510. DWORD_PTR dwInstance)
  2511. {
  2512. struct _show_details_args * psda = (LPVOID)dwInstance;
  2513. assert (psda);
  2514. if (!psda)
  2515. return FALSE;
  2516. switch (dwFunc)
  2517. {
  2518. case MM_EPS_GETNODEDESC:
  2519. *(LPTSTR)dwParam1 = 0;
  2520. if (psda->pmcl->piSingle)
  2521. lstrcpyn ((LPTSTR)dwParam1, psda->pmcl->piSingle->szFriendly, (int)(dwParam2/sizeof(TCHAR)));
  2522. break;
  2523. case MM_EPS_GETNODEID:
  2524. *(LPTSTR)dwParam1 = 0;
  2525. if (psda->pmcl->piSingle)
  2526. {
  2527. lstrcpy ((LPTSTR)dwParam1, cszMidiSlash);
  2528. lstrcat ((LPTSTR)dwParam1, psda->pmcl->piSingle->szKey);
  2529. }
  2530. break;
  2531. case MM_EPS_ADDSHEET:
  2532. if (psda->psh.nPages >= NUMELMS(psda->hpsp)-1)
  2533. return FALSE;
  2534. psda->psh.phpage[psda->psh.nPages++] = (HPROPSHEETPAGE)dwParam1;
  2535. break;
  2536. case MM_EPS_TREECHANGE:
  2537. psda->bChanged = TRUE;
  2538. break;
  2539. default:
  2540. return FALSE;
  2541. }
  2542. return TRUE;
  2543. }
  2544. BOOL WINAPI ShowDetails (
  2545. HWND hWnd,
  2546. PMCLOCAL pmcl)
  2547. {
  2548. struct _show_details_args sda;
  2549. TCHAR szTitle[MAX_ALIAS];
  2550. HPROPSHEETPAGE hpsp;
  2551. UINT idDlg;
  2552. idDlg = IDD_DEVICE_DETAIL;
  2553. if (pmcl->piSingle && pmcl->piSingle->piParent)
  2554. idDlg = IDD_INSTRUMENT_DETAIL;
  2555. ZeroMemory (&sda, sizeof(sda));
  2556. sda.pmcl = pmcl;
  2557. sda.psh.dwSize = sizeof(sda.psh);
  2558. sda.psh.dwFlags = PSH_PROPTITLE;
  2559. sda.psh.hwndParent = hWnd;
  2560. sda.psh.hInstance = ghInstance;
  2561. sda.psh.pszCaption = MAKEINTRESOURCE (IDS_MMPROP);
  2562. sda.psh.nPages = 0;
  2563. sda.psh.nStartPage = 0;
  2564. sda.psh.phpage = sda.hpsp;
  2565. LoadString (ghInstance, IDS_MIDIDETAILS, szTitle, NUMELMS(szTitle));
  2566. hpsp = AddPropPage (szTitle,
  2567. fnPropCallback,
  2568. MidiInstrumentDlgProc,
  2569. idDlg,
  2570. (LPARAM)&sda);
  2571. if (hpsp)
  2572. sda.psh.nPages = 1;
  2573. PropertySheet (&sda.psh);
  2574. return sda.bChanged;
  2575. }
  2576. /*+ AddMidiPages
  2577. *
  2578. * add a midi page to a property sheet. Invoked from Advanced tab
  2579. * of Muitimedia control panel when class midi is selected from
  2580. * the list.
  2581. *
  2582. *-=================================================================*/
  2583. BOOL CALLBACK AddMidiPages (
  2584. LPCTSTR pszTitle,
  2585. LPFNMMEXTPROPSHEETCALLBACK lpfnAddPropSheetPage,
  2586. LPARAM lParam)
  2587. {
  2588. HPROPSHEETPAGE hpsp;
  2589. TCHAR sz[MAX_ALIAS];
  2590. LoadString (ghInstance, IDS_GENERAL, sz, NUMELMS(sz));
  2591. hpsp = AddPropPage (sz,
  2592. lpfnAddPropSheetPage,
  2593. MidiClassDlgProc,
  2594. IDD_MIDICLASS_GEN,
  2595. lParam);
  2596. return (hpsp != NULL);
  2597. }
  2598. /*+ AddSimpleMidiPages
  2599. *
  2600. * add a midi page to a MM control panel.
  2601. *
  2602. *-=================================================================*/
  2603. BOOL CALLBACK AddSimpleMidiPages (
  2604. LPTSTR pszTitle,
  2605. LPFNMMEXTPROPSHEETCALLBACK lpfnAddPropSheetPage,
  2606. LPARAM lParam)
  2607. {
  2608. HPROPSHEETPAGE hpsp;
  2609. //static CONST TCHAR sz[13] = TEXT (" ");
  2610. //UINT cch = lstrlen (pszTitle);
  2611. DebugSetOutputLevel (GetProfileInt(TEXT ("Debug"), TEXT ("midiprop"), 0));
  2612. // pad my tab to 12 spaces so it looks nice with the
  2613. // other simple tabls (as per request of vijr)
  2614. //
  2615. //if (cch < NUMELMS(sz)-2)
  2616. //{
  2617. // lstrcpy (sz + NUMELMS(sz)/2 - cch/2, pszTitle);
  2618. // pszTitle = sz;
  2619. // pszTitle[lstrlen(pszTitle)] = TEXT (' ');
  2620. //}
  2621. hpsp = AddPropPage (pszTitle,
  2622. lpfnAddPropSheetPage,
  2623. MidiCplDlgProc,
  2624. IDD_CPL_MIDI2,
  2625. lParam);
  2626. return (hpsp != NULL);
  2627. }
  2628. /*
  2629. ***************************************************************
  2630. * BOOL PASCAL LoadDesc(LPCTSTR pszFile, LPCTSTR pszDesc)
  2631. * This function gets the description string from the executable
  2632. * file specified. We first try to get the string from the version info
  2633. * If that fails then we try to get the string from the exehdr.
  2634. * If that fails we return a NULL string.
  2635. * Return TRUE on success, else FALSE.
  2636. ***************************************************************
  2637. */
  2638. BOOL PASCAL LoadDesc(LPCTSTR pszFile, LPTSTR pszDesc)
  2639. {
  2640. LPTSTR psz;
  2641. static TCHAR szProfile[MAXSTR];
  2642. UINT cchSize;
  2643. HANDLE hFind;
  2644. WIN32_FIND_DATA wfd;
  2645. DPF (TEXT ("LoadDesc: %s\r\n"), pszFile);
  2646. // Make sure file exists
  2647. hFind = FindFirstFile (pszFile, &wfd);
  2648. if (hFind == INVALID_HANDLE_VALUE)
  2649. return(FALSE);
  2650. FindClose (hFind);
  2651. // Get User Friendly name from Version Info
  2652. if (GetVerDesc (wfd.cFileName, pszDesc))
  2653. return TRUE;
  2654. //
  2655. // As a last resort, look at the description in the Executable Header
  2656. //
  2657. cchSize = sizeof(szProfile)/sizeof(TCHAR);
  2658. if ((! GetExeDesc (wfd.cFileName, szProfile, cchSize)) ||
  2659. (lstrlen (szProfile) < 3))
  2660. {
  2661. *pszDesc = 0;
  2662. return(FALSE);
  2663. }
  2664. else
  2665. {
  2666. // There is EXEHDR information Parse according to driver spec
  2667. psz = szProfile;
  2668. while (*psz && *psz++ != TEXT (':'))
  2669. {
  2670. ; // skip type information
  2671. }
  2672. if (!(*psz))
  2673. psz = szProfile;
  2674. lstrcpy (pszDesc, psz);
  2675. return(TRUE);
  2676. }
  2677. }
  2678. /* BOOL FAR PASCAL GetExeDesc(szFile, szBuff, cchBuff)
  2679. *
  2680. * Function will return the an executable's description
  2681. *
  2682. * szFile - Path Name a new exe
  2683. * pszBuf - Buffer to place returned info
  2684. * cchBuf - Size of buffer (in characters
  2685. *
  2686. * returns: TRUE if successful, FALSE otherwise.
  2687. */
  2688. STATIC BOOL FAR PASCAL GetExeDesc(
  2689. LPTSTR szFile,
  2690. LPTSTR pszBuff,
  2691. int cchBuff)
  2692. {
  2693. DWORD dwSig;
  2694. WORD wSig;
  2695. HANDLE hFile;
  2696. DWORD offset;
  2697. BYTE cbLen;
  2698. DWORD cbRead;
  2699. IMAGE_DOS_HEADER doshdr; // Original EXE Header
  2700. // Open File
  2701. hFile = CreateFile (szFile, GENERIC_READ, FILE_SHARE_READ, NULL,
  2702. OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
  2703. if (hFile == INVALID_HANDLE_VALUE)
  2704. return FALSE;
  2705. // Get Original Dos Header
  2706. if ((! ReadFile (hFile, (LPVOID)&doshdr, sizeof(doshdr), &cbRead, NULL)) ||
  2707. (cbRead != sizeof(doshdr)) || // Read Error
  2708. (doshdr.e_magic != IMAGE_DOS_SIGNATURE)) // Invalid DOS Header
  2709. {
  2710. goto error; /* Abort("Not an exe",h); */
  2711. }
  2712. // Seek to new header
  2713. offset = doshdr.e_lfanew;
  2714. SetFilePointer (hFile, offset, NULL, FILE_BEGIN);
  2715. // Read in signature
  2716. if ((! ReadFile (hFile, (LPVOID)&dwSig, sizeof(dwSig), &cbRead, NULL)) ||
  2717. (cbRead != sizeof(dwSig))) // Read Error
  2718. {
  2719. goto error; /* Abort("Not an exe",h); */
  2720. }
  2721. wSig = LOWORD (dwSig);
  2722. if (dwSig == IMAGE_NT_SIGNATURE)
  2723. {
  2724. DPF (TEXT ("GetExeDesc: NT Portable Executable Format\r\n"));
  2725. // NOTE - The NT Portatble Executable Format does not store
  2726. // the executable's user friendly name.
  2727. goto error;
  2728. }
  2729. else if (wSig == IMAGE_OS2_SIGNATURE)
  2730. {
  2731. IMAGE_OS2_HEADER winhdr; // New Windows/OS2 header
  2732. TCHAR szInfo[256];
  2733. DPF (TEXT ("GetExeDesc: Windows or OS2 Executable Format\r\n"));
  2734. // Seek to Windows Header
  2735. offset = doshdr.e_lfanew;
  2736. SetFilePointer (hFile, offset, NULL, FILE_BEGIN);
  2737. // Read Windows Header
  2738. if ((! ReadFile (hFile, (LPVOID)&winhdr, sizeof(winhdr),
  2739. &cbRead, NULL)) ||
  2740. (cbRead != sizeof(winhdr)) || // Read Error
  2741. (winhdr.ne_magic != IMAGE_OS2_SIGNATURE)) // Invalid Windows Header
  2742. {
  2743. goto error;
  2744. }
  2745. // Seek to module name which is the first entry in the non-resident name table
  2746. offset = winhdr.ne_nrestab;
  2747. SetFilePointer (hFile, offset, NULL, FILE_BEGIN);
  2748. // Get Size of Module Name
  2749. if ((! ReadFile (hFile, (LPVOID)&cbLen, sizeof(BYTE),
  2750. &cbRead, NULL)) ||
  2751. (cbRead != sizeof(BYTE)))
  2752. {
  2753. goto error;
  2754. }
  2755. cchBuff--; // leave room for a \0
  2756. if (cbLen > (BYTE)cchBuff)
  2757. cbLen = (BYTE)cchBuff;
  2758. // Read Module Name
  2759. if ((! ReadFile (hFile, (LPVOID)szInfo, cbLen,
  2760. &cbRead, NULL)) ||
  2761. (cbRead != cbLen))
  2762. {
  2763. goto error;
  2764. }
  2765. szInfo[cbLen] = 0;
  2766. // Copy to Buffer
  2767. lstrcpy (pszBuff, szInfo);
  2768. }
  2769. else if (wSig == IMAGE_VXD_SIGNATURE)
  2770. {
  2771. IMAGE_VXD_HEADER vxdhdr; // New Windows/OS2 VXD Header
  2772. TCHAR szInfo[256];
  2773. DPF (TEXT ("GetExeDesc: Windows or OS2 VXD Executable Format\r\n"));
  2774. // Seek to VXD Header
  2775. offset = doshdr.e_lfanew;
  2776. SetFilePointer (hFile, offset, NULL, FILE_BEGIN);
  2777. // Read VXD Header
  2778. if ((! ReadFile (hFile, (LPVOID)&vxdhdr, sizeof(vxdhdr),
  2779. &cbRead, NULL)) ||
  2780. (cbRead != sizeof(vxdhdr)) || // Read Error
  2781. (vxdhdr.e32_magic != IMAGE_VXD_SIGNATURE)) // Invalid VXD Header
  2782. {
  2783. goto error;
  2784. }
  2785. // Seek to module name which is the first entry in the non-resident name table
  2786. offset = vxdhdr.e32_nrestab;
  2787. SetFilePointer (hFile, offset, NULL, FILE_BEGIN);
  2788. // Get Size of Module Name
  2789. if ((! ReadFile (hFile, (LPVOID)&cbLen, sizeof(BYTE),
  2790. &cbRead, NULL)) ||
  2791. (cbRead != sizeof(BYTE)))
  2792. {
  2793. goto error;
  2794. }
  2795. cchBuff--; // leave room for a \0
  2796. if (cbLen > (BYTE)cchBuff)
  2797. cbLen = (BYTE)cchBuff;
  2798. // Read Module Name
  2799. if ((! ReadFile (hFile, (LPVOID)szInfo, cbLen,
  2800. &cbRead, NULL)) ||
  2801. (cbRead != cbLen))
  2802. {
  2803. goto error;
  2804. }
  2805. szInfo[cbLen] = 0;
  2806. // Copy to Buffer
  2807. lstrcpy (pszBuff, szInfo);
  2808. }
  2809. else
  2810. {
  2811. DPF (TEXT ("GetExeDesc: Unknown Executable\r\n"));
  2812. goto error; /* Abort("Not an exe",h); */
  2813. }
  2814. CloseHandle (hFile);
  2815. return TRUE;
  2816. error:
  2817. CloseHandle (hFile);
  2818. return FALSE;
  2819. }
  2820. /*
  2821. ***************************************************************
  2822. * STATIC INT_PTR GetVerDesc
  2823. * Loads the version DLL and uses it to get Version Description string
  2824. * from the specified file.
  2825. ***************************************************************
  2826. */
  2827. STATIC INT_PTR PASCAL GetVerDesc (LPCTSTR pstrFile, LPTSTR pstrDesc)
  2828. {
  2829. DWORD_PTR dwVerInfoSize;
  2830. DWORD dwVerHnd;
  2831. INT_PTR bRetCode;
  2832. bRetCode = FALSE;
  2833. DPF( TEXT ("Getting VERSION string for %s \r\n"), pstrFile);
  2834. dwVerInfoSize = GetFileVersionInfoSize (pstrFile, &dwVerHnd);
  2835. if (dwVerInfoSize)
  2836. {
  2837. LPBYTE lpVffInfo; // Pointer to block to hold info
  2838. // Get a block big enough to hold version info
  2839. if (lpVffInfo = (LPBYTE) GlobalAllocPtr(GMEM_MOVEABLE, dwVerInfoSize))
  2840. {
  2841. // Get the File Version first
  2842. if (GetFileVersionInfo (pstrFile, 0L,
  2843. dwVerInfoSize, lpVffInfo))
  2844. {
  2845. static SZCODE cszFileDescr[] = TEXT ("\\StringFileInfo\\040904E4\\FileDescription");
  2846. TCHAR szBuf[MAX_PATH];
  2847. LPTSTR lpVersion;
  2848. WORD wVersionLen;
  2849. // Now try to get the FileDescription
  2850. // First try this for the "Translation" entry, and then
  2851. // try the American english translation.
  2852. // Keep track of the string length for easy updating.
  2853. // 040904E4 represents the language ID and the four
  2854. // least significant digits represent the codepage for
  2855. // which the data is formatted. The language ID is
  2856. // composed of two parts: the low ten bits represent
  2857. // the major language and the high six bits represent
  2858. // the sub language.
  2859. lstrcpy(szBuf, cszFileDescr);
  2860. wVersionLen = 0;
  2861. lpVersion = NULL;
  2862. // Look for the corresponding string.
  2863. bRetCode = VerQueryValue((LPVOID)lpVffInfo,
  2864. (LPTSTR)szBuf,
  2865. (void FAR* FAR*)&lpVersion,
  2866. (UINT FAR *) &wVersionLen);
  2867. if (bRetCode && wVersionLen > 2 && lpVersion)
  2868. {
  2869. lstrcpy (pstrDesc, lpVersion);
  2870. }
  2871. else
  2872. bRetCode = FALSE;
  2873. // Let go of the memory
  2874. GlobalFreePtr(lpVffInfo);
  2875. }
  2876. }
  2877. } else
  2878. bRetCode = FALSE;
  2879. return bRetCode;
  2880. }
  2881. LONG SHRegDeleteKey(HKEY hKey, LPCTSTR lpSubKey)
  2882. {
  2883. LONG lResult;
  2884. HKEY hkSubKey;
  2885. DWORD dwIndex;
  2886. TCHAR szSubKeyName[MAX_PATH + 1];
  2887. DWORD cchSubKeyName = ARRAYSIZE(szSubKeyName);
  2888. TCHAR szClass[MAX_PATH];
  2889. DWORD cchClass = ARRAYSIZE(szClass);
  2890. DWORD dwDummy1, dwDummy2, dwDummy3, dwDummy4, dwDummy5, dwDummy6;
  2891. FILETIME ft;
  2892. // Open the subkey so we can enumerate any children
  2893. lResult = RegOpenKeyEx(hKey, lpSubKey, 0, KEY_ALL_ACCESS, &hkSubKey);
  2894. if (ERROR_SUCCESS == lResult)
  2895. {
  2896. // I can't just call RegEnumKey with an ever-increasing index, because
  2897. // I'm deleting the subkeys as I go, which alters the indices of the
  2898. // remaining subkeys in an implementation-dependent way. In order to
  2899. // be safe, I have to count backwards while deleting the subkeys.
  2900. // Find out how many subkeys there are
  2901. lResult = RegQueryInfoKey(hkSubKey,
  2902. szClass,
  2903. &cchClass,
  2904. NULL,
  2905. &dwIndex, // The # of subkeys -- all we need
  2906. &dwDummy1,
  2907. &dwDummy2,
  2908. &dwDummy3,
  2909. &dwDummy4,
  2910. &dwDummy5,
  2911. &dwDummy6,
  2912. &ft);
  2913. if (ERROR_SUCCESS == lResult)
  2914. {
  2915. // dwIndex is now the count of subkeys, but it needs to be
  2916. // zero-based for RegEnumKey, so I'll pre-decrement, rather
  2917. // than post-decrement.
  2918. while (ERROR_SUCCESS == RegEnumKey(hkSubKey, --dwIndex, szSubKeyName, cchSubKeyName))
  2919. {
  2920. SHRegDeleteKey(hkSubKey, szSubKeyName);
  2921. }
  2922. }
  2923. RegCloseKey(hkSubKey);
  2924. lResult = RegDeleteKey(hKey, lpSubKey);
  2925. }
  2926. return lResult;
  2927. } // End SHRegDeleteKey
  2928. /* DeviceIDFromDriverName
  2929. *
  2930. * Query MMSYSTEM to find the given device. Return its base device ID.
  2931. * Return -1 if we cannot find the driver
  2932. */
  2933. static UINT
  2934. DeviceIDFromDriverName(
  2935. PTSTR pstrDriverName)
  2936. {
  2937. UINT idxDev;
  2938. UINT cPorts;
  2939. DWORD cPort;
  2940. PTSTR pstrDriver;
  2941. MMRESULT mmr;
  2942. if (NULL == (pstrDriver = LocalAlloc(LPTR, MAX_ALIAS*sizeof(TCHAR))))
  2943. {
  2944. AuxDebugEx(3, DEBUGLINE TEXT("DN->ID: LocalAlloc() failed.\r\n"));
  2945. return (UINT)-1;
  2946. }
  2947. // Walk through the base device ID of each driver. Use MMSYSTEM's
  2948. // driver query messages to find out how many ports & the driver name
  2949. //
  2950. cPorts = midiOutGetNumDevs();
  2951. for (idxDev = 0; idxDev < cPorts; idxDev++)
  2952. {
  2953. if (MMSYSERR_NOERROR != (mmr = midiOutMessage(HMIDIOUT_INDEX(idxDev),
  2954. DRV_QUERYNUMPORTS,
  2955. (DWORD_PTR)(LPDWORD)&cPort,
  2956. 0)))
  2957. {
  2958. // Something is wrong with this driver. Skip it
  2959. //
  2960. AuxDebugEx(3, DEBUGLINE TEXT("DN->ID: DRV_QUERYNUMPORTS(%u)->%u\r\n"),
  2961. (UINT)idxDev,
  2962. (UINT)mmr);
  2963. continue;
  2964. }
  2965. if (MMSYSERR_NOERROR != (mmr = midiOutMessage(HMIDIOUT_INDEX(idxDev),
  2966. DRV_QUERYDRVENTRY,
  2967. (DWORD_PTR)(LPTSTR)pstrDriver,
  2968. MAX_ALIAS)))
  2969. {
  2970. AuxDebugEx(3, DEBUGLINE TEXT("DN->ID: DRV_QUERYDRVENTRY(%u)->%u\r\n"),
  2971. (UINT)idxDev,
  2972. (UINT)mmr);
  2973. continue;
  2974. }
  2975. if (!_tcscmp(pstrDriver, pstrDriverName))
  2976. break;
  2977. }
  2978. if (idxDev >= cPorts)
  2979. {
  2980. AuxDebugEx(3, DEBUGLINE TEXT("DN->ID: No match for [%s]\r\n"),
  2981. (LPTSTR)pstrDriverName);
  2982. idxDev = (UINT)-1;
  2983. }
  2984. else
  2985. AuxDebugEx(3, DEBUGLINE TEXT("DN->ID: [%s] at %d\r\n"),
  2986. (LPTSTR)pstrDriverName,
  2987. (int)idxDev);
  2988. LocalFree(pstrDriver);
  2989. return (int)idxDev;
  2990. }