Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1618 lines
52 KiB

  1. /*
  2. ***************************************************************
  3. * sndsel.c
  4. *
  5. * This file contains the dialogproc and the dialog initialization code
  6. *
  7. * Copyright 1993, Microsoft Corporation
  8. *
  9. * History:
  10. *
  11. * 07/94 - VijR (Created)
  12. *
  13. ***************************************************************
  14. */
  15. #include <windows.h>
  16. #include <mmsystem.h>
  17. #include <string.h>
  18. #include <cpl.h>
  19. #include <shellapi.h>
  20. #include <ole2.h>
  21. #include <commdlg.h>
  22. #define NOSTATUSBAR
  23. #include <commctrl.h>
  24. #include <prsht.h>
  25. #include <regstr.h>
  26. #include <dbt.h>
  27. #include <mmddkp.h>
  28. #include <ks.h>
  29. #include <ksmedia.h>
  30. #include "mmcpl.h"
  31. #include "medhelp.h"
  32. #include "sound.h"
  33. #include "utils.h"
  34. #include "rcids.h"
  35. /*
  36. ***************************************************************
  37. * Defines
  38. ***************************************************************
  39. */
  40. #define DF_PM_SETBITMAP (WM_USER+1)
  41. /*
  42. ***************************************************************
  43. * Globals
  44. ***************************************************************
  45. */
  46. SZCODE gszWindowsHlp[] = TEXT("windows.hlp");
  47. SZCODE gszNull[2] = TEXT("\0");
  48. SZCODE gszNullScheme[] = TEXT(".none");
  49. TCHAR gszCurDir[MAXSTR] = TEXT("\0");
  50. TCHAR gszNone[32];
  51. TCHAR gszRemoveScheme[MAXSTR];
  52. TCHAR gszChangeScheme[MAXSTR];
  53. TCHAR gszMediaDir[MAXSTR];
  54. TCHAR gszDefaultApp[32];
  55. int giScheme;
  56. BOOL gfChanged; //set to TRUE if sound info change
  57. BOOL gfNewScheme;
  58. BOOL gfDeletingTree;
  59. HWND ghWnd;
  60. OPENFILENAME ofn;
  61. /*
  62. ***************************************************************
  63. * Globals used in painting disp chunk display.
  64. ***************************************************************
  65. */
  66. BOOL gfWaveExists = FALSE; // indicates wave device in system.
  67. HTREEITEM ghOldItem = NULL;
  68. /*
  69. ***************************************************************
  70. * File Globals
  71. ***************************************************************
  72. */
  73. static TCHAR aszFileName[MAXSTR] = TEXT("\0");
  74. static TCHAR aszPath[MAXSTR] = TEXT("\0");
  75. static TCHAR aszBrowse[MAXSTR];
  76. static TCHAR aszBrowseStr[64];
  77. static TCHAR aszNullSchemeLabel[MAXSTR];
  78. static TCHAR aszFilter[MAXSTR];
  79. static TCHAR aszNullChar[2];
  80. static SZCODE aszLnk[] = TEXT(".lnk");
  81. static SZCODE aszWavFilter[] = TEXT("*.wav");
  82. static SZCODE aszDefaultScheme[] = TEXT("Appevents\\schemes");
  83. static SZCODE aszNames[] = TEXT("Appevents\\schemes\\Names");
  84. static SZCODE aszDefault[] = TEXT(".default");
  85. static SZCODE aszCurrent[] = TEXT(".current");
  86. static INTCODE aKeyWordIds[] =
  87. {
  88. CB_SCHEMES, IDH_EVENT_SCHEME,
  89. IDC_TEXT_14, IDH_EVENT_SCHEME,
  90. ID_SAVE_SCHEME, IDH_EVENT_SAVEAS_BUTTON,
  91. ID_REMOVE_SCHEME, IDH_EVENT_DELETE_BUTTON,
  92. IDC_EVENT_TREE, IDH_EVENT_EVENT,
  93. IDC_SOUNDGRP, IDH_COMM_GROUPBOX,
  94. ID_PLAY, IDH_EVENT_PLAY,
  95. IDC_STATIC_EVENT, IDH_COMM_GROUPBOX,
  96. IDC_STATIC_NAME, IDH_EVENT_FILE,
  97. IDC_SOUND_FILES, IDH_EVENT_FILE,
  98. ID_BROWSE, IDH_EVENT_BROWSE,
  99. 0,0
  100. };
  101. BOOL gfEditBoxChanged;
  102. BOOL gfSubClassedEditWindow;
  103. BOOL gfSoundPlaying;
  104. HBITMAP hBitmapPlay;
  105. HBITMAP hBitmapStop;
  106. HIMAGELIST hSndImagelist;
  107. /*
  108. ***************************************************************
  109. * extern
  110. ***************************************************************
  111. */
  112. extern HSOUND ghse;
  113. extern BOOL gfNukeExt;
  114. /*
  115. ***************************************************************
  116. * Prototypes
  117. ***************************************************************
  118. */
  119. BOOL PASCAL DoCommand (HWND, int, HWND, UINT);
  120. BOOL PASCAL InitDialog (HWND);
  121. BOOL PASCAL InitStringTable (void);
  122. BOOL PASCAL InitFileOpen (HWND, LPOPENFILENAME);
  123. BOOL PASCAL SoundCleanup (HWND);
  124. LPTSTR PASCAL NiceName (LPTSTR, BOOL);
  125. BOOL ResolveLink (LPTSTR, LPTSTR, LONG);
  126. void CreateTooltip (HWND hwnd, LPTSTR lpszTip);
  127. // stuff in sndfile.c
  128. //
  129. BOOL PASCAL ShowSoundMapping (HWND, PEVENT);
  130. BOOL PASCAL ChangeSoundMapping (HWND, LPTSTR, PEVENT);
  131. BOOL PASCAL PlaySoundFile (HWND, LPTSTR);
  132. BOOL PASCAL QualifyFileName (LPTSTR, LPTSTR, int, BOOL);
  133. // Stuff in scheme.c
  134. //
  135. INT_PTR CALLBACK SaveSchemeDlg(HWND, UINT, WPARAM, LPARAM);
  136. BOOL PASCAL RegNewScheme (HWND, LPTSTR, LPTSTR, BOOL);
  137. BOOL PASCAL RegSetDefault (LPTSTR);
  138. BOOL PASCAL ClearModules (HWND, HWND, BOOL);
  139. BOOL PASCAL LoadModules (HWND, LPTSTR);
  140. BOOL PASCAL RemoveScheme (HWND);
  141. BOOL PASCAL AddScheme (HWND, LPTSTR, LPTSTR, BOOL, int);
  142. BOOL PASCAL RegDeleteScheme(HWND hWndC, int iIndex);
  143. /*
  144. ***************************************************************
  145. ***************************************************************
  146. */
  147. void AddExt(LPTSTR sz, LPCTSTR x)
  148. {
  149. UINT cb;
  150. for (cb = lstrlen(sz); cb; --cb)
  151. {
  152. if (TEXT('.') == sz[cb])
  153. return;
  154. if (TEXT('\\') == sz[cb])
  155. break;
  156. }
  157. lstrcat (sz, x);
  158. }
  159. static void AddFilesToLB(HWND hwndList, LPTSTR pszDir, LPCTSTR szSpec)
  160. {
  161. WIN32_FIND_DATA fd;
  162. HANDLE h;
  163. TCHAR szBuf[MAXSTR];
  164. ComboBox_ResetContent(hwndList);
  165. if ((lstrlen(pszDir)+ lstrlen(cszSlash)+ lstrlen(szSpec)) < ARRAYSIZE(szBuf))
  166. {
  167. lstrcpyn(szBuf, pszDir, ARRAYSIZE(szBuf));
  168. lstrcat(szBuf, cszSlash);
  169. lstrcat(szBuf, szSpec);
  170. h = FindFirstFile(szBuf, &fd);
  171. if (h != INVALID_HANDLE_VALUE)
  172. {
  173. // If we have only a short name, make it pretty.
  174. do
  175. {
  176. NiceName(fd.cFileName, TRUE);
  177. SendMessage(hwndList, CB_ADDSTRING, 0, (LPARAM)(LPTSTR)fd.cFileName);
  178. }
  179. while (FindNextFile(h, &fd));
  180. FindClose(h);
  181. }
  182. }
  183. ComboBox_InsertString(hwndList, 0, (LPARAM)(LPTSTR)gszNone);
  184. }
  185. static void SetCurDir(HWND hDlg, LPTSTR lpszPath, BOOL fParse, BOOL fChangeDir)
  186. {
  187. TCHAR szTmp[MAX_PATH];
  188. TCHAR szOldDir[MAXSTR];
  189. LPTSTR lpszTmp;
  190. lstrcpy (szOldDir, gszCurDir);
  191. if (!fParse)
  192. {
  193. lstrcpy(gszCurDir, lpszPath);
  194. goto AddFiles;
  195. }
  196. lstrcpy(szTmp, lpszPath);
  197. for (lpszTmp = (LPTSTR)(szTmp + lstrlen(szTmp)); lpszTmp > szTmp; lpszTmp = CharPrev(szTmp, lpszTmp))
  198. {
  199. if (*lpszTmp == TEXT('\\'))
  200. {
  201. *lpszTmp = TEXT('\0');
  202. lstrcpy(gszCurDir, szTmp);
  203. break;
  204. }
  205. }
  206. if (lpszTmp <= szTmp)
  207. lstrcpy(gszCurDir, gszMediaDir);
  208. AddFiles:
  209. if (fChangeDir)
  210. {
  211. if (!SetCurrentDirectory(gszCurDir))
  212. {
  213. if (lstrcmp (gszMediaDir, lpszPath))
  214. SetCurrentDirectory (gszMediaDir);
  215. else
  216. {
  217. if (GetWindowsDirectory (gszCurDir, sizeof(gszCurDir)/sizeof(TCHAR)))
  218. SetCurrentDirectory (gszCurDir);
  219. }
  220. }
  221. }
  222. if (lstrcmpi (szOldDir, gszCurDir))
  223. {
  224. AddFilesToLB(GetDlgItem(hDlg, IDC_SOUND_FILES),gszCurDir, aszWavFilter);
  225. }
  226. }
  227. static BOOL TranslateDir(HWND hDlg, LPTSTR pszPath)
  228. {
  229. TCHAR szCurDir[MAX_PATH];
  230. int nFileOffset = lstrlen(pszPath);
  231. lstrcpy(szCurDir, pszPath);
  232. if (szCurDir[nFileOffset - 1] == TEXT('\\'))
  233. szCurDir[--nFileOffset] = 0;
  234. if (SetCurrentDirectory(szCurDir))
  235. {
  236. if (GetCurrentDirectory(sizeof(szCurDir)/sizeof(TCHAR), szCurDir))
  237. {
  238. SetCurDir(hDlg, szCurDir, FALSE, FALSE);
  239. return TRUE;
  240. }
  241. }
  242. return FALSE;
  243. }
  244. ///HACK ALERT!!!! HACK ALERT !!! HACK ALERT !!!!
  245. // BEGIN (HACKING)
  246. HHOOK gfnKBHookScheme = NULL;
  247. HWND ghwndDlg = NULL;
  248. WNDPROC gfnEditWndProc = NULL;
  249. #define WM_NEWEVENTFILE (WM_USER + 1000)
  250. #define WM_RESTOREEVENTFILE (WM_USER + 1001)
  251. LRESULT CALLBACK SchemeKBHookProc(int code, WPARAM wParam, LPARAM lParam)
  252. {
  253. if (wParam == VK_RETURN || wParam == VK_ESCAPE)
  254. {
  255. HWND hwndFocus = GetFocus();
  256. if (IsWindow(hwndFocus))
  257. {
  258. if (lParam & 0x80000000) //Key Up
  259. {
  260. DPF("*****WM_KEYUP for VK_RETURN/ESC\r\n");
  261. if (wParam == VK_RETURN)
  262. {
  263. if (SendMessage(ghwndDlg, WM_NEWEVENTFILE, 0, 0L))
  264. {
  265. SetFocus(hwndFocus);
  266. gfEditBoxChanged = TRUE;
  267. return 1;
  268. }
  269. }
  270. else
  271. SendMessage(ghwndDlg, WM_RESTOREEVENTFILE, 0, 0L);
  272. }
  273. }
  274. if (gfnKBHookScheme && (lParam & 0x80000000))
  275. {
  276. UnhookWindowsHookEx(gfnKBHookScheme);
  277. gfnKBHookScheme = NULL;
  278. }
  279. return 1; //remove message
  280. }
  281. return CallNextHookEx(gfnKBHookScheme, code, wParam, lParam);
  282. }
  283. STATIC void SetSchemesKBHook(HWND hwnd)
  284. {
  285. if (gfnKBHookScheme)
  286. return;
  287. gfnKBHookScheme = SetWindowsHookEx(WH_KEYBOARD, (HOOKPROC)SchemeKBHookProc, ghInstance,0);
  288. }
  289. LRESULT CALLBACK SubClassedEditWndProc(HWND hwnd, UINT wMsg, WPARAM wParam, LPARAM lParam)
  290. {
  291. switch(wMsg)
  292. {
  293. case WM_SETFOCUS:
  294. DPF("*****WM_SETFOCUS\r\n");
  295. SetSchemesKBHook(hwnd);
  296. gfEditBoxChanged = FALSE;
  297. break;
  298. case WM_KILLFOCUS:
  299. if (gfnKBHookScheme)
  300. {
  301. DPF("*****WM_KILLFOCUS\r\n");
  302. UnhookWindowsHookEx(gfnKBHookScheme);
  303. gfnKBHookScheme = NULL;
  304. if (gfEditBoxChanged)
  305. SendMessage(ghwndDlg, WM_NEWEVENTFILE, 0, 1L);
  306. }
  307. break;
  308. }
  309. return CallWindowProc((WNDPROC)gfnEditWndProc, hwnd, wMsg, wParam, lParam);
  310. }
  311. STATIC void SubClassEditWindow(HWND hwndEdit)
  312. {
  313. gfnEditWndProc = (WNDPROC)GetWindowLongPtr(hwndEdit, GWLP_WNDPROC);
  314. SetWindowLongPtr(hwndEdit, GWLP_WNDPROC, (LONG_PTR)SubClassedEditWndProc);
  315. }
  316. // END (HACKING)
  317. STATIC void EndSound(HSOUND * phse)
  318. {
  319. if (*phse)
  320. {
  321. HSOUND hse = *phse;
  322. *phse = NULL;
  323. soundStop(hse);
  324. soundOnDone(hse);
  325. soundClose(hse);
  326. }
  327. }
  328. // Create a tooltip for the passed window
  329. void CreateTooltip (HWND hwnd, LPTSTR lpszTip)
  330. {
  331. HWND hwndTT;
  332. TOOLINFO ti;
  333. INITCOMMONCONTROLSEX iccex;
  334. // Init Common Controls
  335. iccex.dwICC = ICC_WIN95_CLASSES;
  336. iccex.dwSize = sizeof (INITCOMMONCONTROLSEX);
  337. InitCommonControlsEx (&iccex);
  338. // Create Window
  339. hwndTT = CreateWindowEx (WS_EX_TOPMOST, TOOLTIPS_CLASS, NULL,
  340. WS_POPUP | TTS_NOPREFIX | TTS_ALWAYSTIP, CW_USEDEFAULT,
  341. CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, hwnd,
  342. NULL, ghInstance, NULL);
  343. SetWindowPos (hwndTT, HWND_TOPMOST, 0, 0, 0, 0,
  344. SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
  345. // Get Tip Area (entire window)
  346. GetClientRect (hwnd, &(ti.rect));
  347. // Init Tip
  348. ti.cbSize = sizeof(TOOLINFO);
  349. ti.uFlags = TTF_SUBCLASS;
  350. ti.hwnd = hwnd;
  351. ti.hinst = ghInstance;
  352. ti.uId = 0;
  353. ti.lpszText = lpszTip;
  354. // Add Tip
  355. SendMessage (hwndTT, TTM_ADDTOOL, 0, (LPARAM) (LPTOOLINFO) &ti);
  356. }
  357. /*
  358. ***************************************************************
  359. * SoundDlg
  360. *
  361. * Description:
  362. * DialogProc for sound control panel applet.
  363. *
  364. * Parameters:
  365. * HWND hDlg window handle of dialog window
  366. * UINT uiMessage message number
  367. * WPARAM wParam message-dependent
  368. * LPARAM lParam message-dependent
  369. *
  370. * Returns: BOOL
  371. * TRUE if message has been processed, else FALSE
  372. *
  373. ***************************************************************
  374. */
  375. BOOL CALLBACK SoundDlg(HWND hDlg, UINT uMsg, WPARAM wParam,LPARAM lParam)
  376. {
  377. NMHDR FAR *lpnm;
  378. TCHAR szBuf[MAXSTR];
  379. static BOOL fClosingDlg = FALSE;
  380. PEVENT pEvent;
  381. switch (uMsg)
  382. {
  383. case WM_NOTIFY:
  384. lpnm = (NMHDR FAR *)lParam;
  385. switch(lpnm->code)
  386. {
  387. case PSN_KILLACTIVE:
  388. FORWARD_WM_COMMAND(hDlg, IDOK, 0, 0, SendMessage);
  389. break;
  390. case PSN_APPLY:
  391. FORWARD_WM_COMMAND(hDlg, ID_APPLY, 0, 0, SendMessage);
  392. break;
  393. case PSN_RESET:
  394. FORWARD_WM_COMMAND(hDlg, IDCANCEL, 0, 0, SendMessage);
  395. break;
  396. case TVN_SELCHANGED:
  397. {
  398. TV_ITEM tvi;
  399. LPNM_TREEVIEW lpnmtv = (LPNM_TREEVIEW)lParam;
  400. if (fClosingDlg || gfDeletingTree)
  401. break;
  402. if (gfnKBHookScheme)
  403. {
  404. UnhookWindowsHookEx(gfnKBHookScheme);
  405. gfnKBHookScheme = NULL;
  406. if (gfEditBoxChanged)
  407. {
  408. ghOldItem = lpnmtv->itemOld.hItem;
  409. SendMessage(ghwndDlg, WM_NEWEVENTFILE, 0, 1L);
  410. ghOldItem = NULL;
  411. }
  412. }
  413. tvi = lpnmtv->itemNew;
  414. if (tvi.lParam)
  415. {
  416. if (*((short NEAR *)tvi.lParam) == 2)
  417. {
  418. pEvent = (PEVENT)tvi.lParam;
  419. ShowSoundMapping(hDlg, pEvent);
  420. SetWindowLongPtr(hDlg, DWLP_USER, (LONG_PTR)tvi.lParam);
  421. }
  422. else
  423. {
  424. ShowSoundMapping(hDlg, NULL);
  425. SetWindowLongPtr(hDlg, DWLP_USER, 0L);
  426. }
  427. }
  428. else
  429. {
  430. ShowSoundMapping(hDlg, NULL);
  431. SetWindowLongPtr(hDlg, DWLP_USER, 0L);
  432. }
  433. break;
  434. }
  435. case TVN_ITEMEXPANDING:
  436. {
  437. LPNM_TREEVIEW lpnmtv = (LPNM_TREEVIEW)lParam;
  438. if (lpnmtv->action == TVE_COLLAPSE)
  439. {
  440. SetWindowLongPtr(hDlg, DWLP_MSGRESULT, (LPARAM)(LRESULT)TRUE);
  441. return TRUE;
  442. }
  443. break;
  444. }
  445. }
  446. break;
  447. case WM_INITDIALOG:
  448. {
  449. InitStringTable();
  450. giScheme = 0;
  451. ghWnd = hDlg;
  452. gfChanged = FALSE;
  453. gfNewScheme = FALSE;
  454. hBitmapStop = LoadBitmap(ghInstance, MAKEINTRESOURCE(IDB_STOP));
  455. if (!hBitmapStop)
  456. DPF("loadbitmap failed\n");
  457. hBitmapPlay = LoadBitmap(ghInstance, MAKEINTRESOURCE(IDB_PLAY));
  458. if (!hBitmapPlay)
  459. DPF("loadbitmap failed\n");
  460. SendMessage(GetDlgItem(hDlg, ID_PLAY), BM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hBitmapPlay);
  461. ShowSoundMapping(hDlg, NULL);
  462. gfSoundPlaying = FALSE;
  463. // Add tool tip
  464. LoadString (ghInstance, IDS_TIP_PLAY, szBuf, sizeof(szBuf)/sizeof(TCHAR));
  465. CreateTooltip (GetDlgItem (hDlg, ID_PLAY), szBuf);
  466. /* Determine if there is a wave device
  467. */
  468. FORWARD_WM_COMMAND(hDlg, ID_INIT, 0, 0, SendMessage);
  469. InitFileOpen(hDlg, &ofn);
  470. ghwndDlg = hDlg;
  471. DragAcceptFiles(hDlg, TRUE);
  472. gfSubClassedEditWindow = FALSE;
  473. fClosingDlg = FALSE;
  474. gfDeletingTree = FALSE;
  475. }
  476. break;
  477. case WM_DESTROY:
  478. {
  479. DWORD i = 0;
  480. LPTSTR pszKey = NULL;
  481. fClosingDlg = TRUE;
  482. if (gfnKBHookScheme)
  483. {
  484. UnhookWindowsHookEx(gfnKBHookScheme);
  485. gfnKBHookScheme = NULL;
  486. }
  487. SoundCleanup(hDlg);
  488. //delete item data in tree
  489. ClearModules(hDlg,GetDlgItem(hDlg, IDC_EVENT_TREE),TRUE);
  490. //delete item data in combobox
  491. for (i = 0; i < ComboBox_GetCount(GetDlgItem(hDlg, CB_SCHEMES)); i++)
  492. {
  493. pszKey = (LPTSTR)ComboBox_GetItemData(GetDlgItem(hDlg, CB_SCHEMES), i);
  494. if (pszKey)
  495. {
  496. //can't free a couple of these, as they point to static mem
  497. if ((pszKey != aszDefault) && (pszKey != aszCurrent))
  498. {
  499. LocalFree(pszKey);
  500. }
  501. }
  502. }
  503. break;
  504. }
  505. case WM_DROPFILES:
  506. {
  507. TV_HITTESTINFO ht;
  508. HWND hwndTree = GetDlgItem(hDlg, IDC_EVENT_TREE);
  509. DragQueryFile((HDROP)wParam, 0, szBuf, MAXSTR - 1);
  510. if (IsLink(szBuf, aszLnk))
  511. if (!ResolveLink(szBuf, szBuf, sizeof(szBuf)))
  512. goto EndDrag;
  513. if (lstrcmpi((LPTSTR)(szBuf+lstrlen(szBuf)-4), cszWavExt))
  514. goto EndDrag;
  515. GetCursorPos((LPPOINT)&ht.pt);
  516. MapWindowPoints(NULL, hwndTree,(LPPOINT)&ht.pt, 2);
  517. TreeView_HitTest( hwndTree, &ht);
  518. if (ht.hItem && (ht.flags & TVHT_ONITEM))
  519. {
  520. TV_ITEM tvi;
  521. tvi.mask = TVIF_PARAM;
  522. tvi.hItem = ht.hItem;
  523. TreeView_GetItem(hwndTree, &tvi);
  524. if (*((short NEAR *)tvi.lParam) == 2)
  525. {
  526. TreeView_SelectItem(hwndTree, ht.hItem);
  527. pEvent = (PEVENT)(tvi.lParam);
  528. SetWindowLongPtr(hDlg, DWLP_USER, (LONG_PTR)tvi.lParam);
  529. SetFocus(hwndTree);
  530. }
  531. }
  532. pEvent = (PEVENT)(GetWindowLongPtr(hDlg, DWLP_USER));
  533. ChangeSoundMapping(hDlg, szBuf,pEvent);
  534. DragFinish((HDROP) wParam);
  535. break;
  536. EndDrag:
  537. ErrorBox(hDlg, IDS_ISNOTSNDFILE, szBuf);
  538. DragFinish((HDROP) wParam);
  539. break;
  540. }
  541. case WM_NEWEVENTFILE:
  542. {
  543. DPF("*****WM_NEWEVENT\r\n");
  544. gfEditBoxChanged = FALSE;
  545. ComboBox_GetText(GetDlgItem(hDlg, IDC_SOUND_FILES), szBuf, sizeof(szBuf)/sizeof(TCHAR));
  546. pEvent = (PEVENT)(GetWindowLongPtr(hDlg, DWLP_USER));
  547. if (!lstrcmp (szBuf, gszNone)) // Selected "(None)" with keyboard?
  548. {
  549. lstrcpy(szBuf, gszNull);
  550. ChangeSoundMapping(hDlg, szBuf, pEvent);
  551. goto ReturnFocus;
  552. }
  553. if (TranslateDir(hDlg, szBuf))
  554. {
  555. ShowSoundMapping(hDlg, pEvent);
  556. goto ReturnFocus;
  557. }
  558. if (QualifyFileName((LPTSTR)szBuf, (LPTSTR)szBuf, sizeof(szBuf), TRUE))
  559. {
  560. SetCurDir(hDlg, szBuf, TRUE, TRUE);
  561. ChangeSoundMapping(hDlg, szBuf,pEvent);
  562. }
  563. else
  564. {
  565. if (lParam)
  566. {
  567. ErrorBox(hDlg, IDS_INVALIDFILE, NULL);
  568. ShowSoundMapping(hDlg, pEvent);
  569. goto ReturnFocus;
  570. }
  571. if (DisplayMessage(hDlg, IDS_NOSNDFILETITLE, IDS_INVALIDFILEQUERY, MB_YESNO) == IDYES)
  572. {
  573. ShowSoundMapping(hDlg, pEvent);
  574. }
  575. else
  576. {
  577. SetWindowLongPtr(hDlg, DWLP_MSGRESULT, (LPARAM)(LRESULT)TRUE);
  578. return TRUE;
  579. }
  580. }
  581. ReturnFocus:
  582. SetFocus(GetDlgItem(hDlg,IDC_EVENT_TREE));
  583. SetWindowLongPtr(hDlg, DWLP_MSGRESULT, (LPARAM)(LRESULT)FALSE);
  584. return TRUE;
  585. }
  586. case WM_RESTOREEVENTFILE:
  587. {
  588. DPF("*****WM_RESTOREEVENT\r\n");
  589. pEvent = (PEVENT)(GetWindowLongPtr(hDlg, DWLP_USER));
  590. ShowSoundMapping(hDlg, pEvent);
  591. if (lParam == 0) //Don't keep focus
  592. SetFocus(GetDlgItem(hDlg,IDC_EVENT_TREE));
  593. break;
  594. }
  595. case WM_CONTEXTMENU:
  596. WinHelp((HWND)wParam, NULL, HELP_CONTEXTMENU,
  597. (UINT_PTR)(LPTSTR)aKeyWordIds);
  598. break;
  599. case WM_HELP:
  600. WinHelp(((LPHELPINFO)lParam)->hItemHandle, NULL, HELP_WM_HELP
  601. , (UINT_PTR)(LPTSTR)aKeyWordIds);
  602. break;
  603. case MM_WOM_DONE:
  604. {
  605. HWND hwndFocus = GetFocus();
  606. HWND hwndPlay = GetDlgItem(hDlg, ID_PLAY);
  607. gfSoundPlaying = FALSE;
  608. SendMessage(hwndPlay, BM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hBitmapPlay);
  609. if (ghse)
  610. {
  611. soundOnDone(ghse);
  612. soundClose(ghse);
  613. ghse = NULL;
  614. }
  615. pEvent = (PEVENT)(GetWindowLongPtr(hDlg, DWLP_USER));
  616. ShowSoundMapping(hDlg, pEvent);
  617. if (hwndFocus == hwndPlay)
  618. if (IsWindowEnabled(hwndPlay))
  619. SetFocus(hwndPlay);
  620. else
  621. SetFocus(GetDlgItem(hDlg, IDC_EVENT_TREE));
  622. break;
  623. }
  624. case WM_COMMAND:
  625. HANDLE_WM_COMMAND(hDlg, wParam, lParam, DoCommand);
  626. break;
  627. default:
  628. break;
  629. }
  630. return FALSE;
  631. }
  632. /*
  633. ***************************************************************
  634. * doCommand
  635. *
  636. * Description:
  637. * Processes Control commands for main sound
  638. * control panel dialog.
  639. *
  640. * Parameters:
  641. * HWND hDlg - window handle of dialog window
  642. * int id - Message ID
  643. * HWND hwndCtl - Handle of window control
  644. * UINT codeNotify - Notification code for window
  645. *
  646. * Returns: BOOL
  647. * TRUE if message has been processed, else FALSE
  648. *
  649. ***************************************************************
  650. */
  651. BOOL PASCAL DoCommand(HWND hDlg, int id, HWND hwndCtl, UINT codeNotify)
  652. {
  653. WAVEOUTCAPS woCaps;
  654. TCHAR szBuf[MAXSTR];
  655. LPTSTR pszKey;
  656. int iIndex;
  657. HCURSOR hcur;
  658. HWND hWndC = GetDlgItem(hDlg, CB_SCHEMES);
  659. HWND hWndF = GetDlgItem(hDlg, IDC_SOUND_FILES);
  660. HWND hwndTree = GetDlgItem(hDlg, IDC_EVENT_TREE);
  661. PEVENT pEvent;
  662. static BOOL fSchemeCBDroppedDown = FALSE;
  663. static BOOL fFilesCBDroppedDown = FALSE;
  664. static BOOL fSavingPrevScheme = FALSE;
  665. switch (id)
  666. {
  667. case ID_APPLY:
  668. {
  669. EndSound(&ghse);
  670. if (!gfChanged)
  671. break;
  672. hcur = SetCursor(LoadCursor(NULL,IDC_WAIT));
  673. if (gfNewScheme)
  674. {
  675. pszKey = (LPTSTR)ComboBox_GetItemData(hWndC, NONE_ENTRY);
  676. if (lstrcmpi(pszKey, aszCurrent))
  677. {
  678. ComboBox_InsertString(hWndC, NONE_ENTRY, gszNull);
  679. ComboBox_SetItemData(hWndC, NONE_ENTRY, aszCurrent);
  680. ComboBox_SetCurSel(hWndC, NONE_ENTRY);
  681. giScheme = NONE_ENTRY;
  682. }
  683. gfNewScheme = FALSE;
  684. }
  685. iIndex = ComboBox_GetCurSel(hWndC);
  686. if (iIndex != CB_ERR)
  687. {
  688. pszKey = (LPTSTR)ComboBox_GetItemData(hWndC, iIndex);
  689. if (pszKey)
  690. {
  691. RegNewScheme(hDlg, (LPTSTR)aszCurrent, NULL, FALSE);
  692. }
  693. RegSetDefault(pszKey);
  694. }
  695. gfChanged = FALSE;
  696. SetCursor(hcur);
  697. return TRUE;
  698. }
  699. break;
  700. case IDOK:
  701. {
  702. EndSound(&ghse);
  703. break;
  704. }
  705. case IDCANCEL:
  706. {
  707. EndSound(&ghse);
  708. WinHelp(hDlg, gszWindowsHlp, HELP_QUIT, 0L);
  709. break;
  710. }
  711. case ID_INIT:
  712. hcur = SetCursor(LoadCursor(NULL,IDC_WAIT));
  713. gfWaveExists = waveOutGetNumDevs() > 0 &&
  714. (waveOutGetDevCaps(WAVE_MAPPER,&woCaps,sizeof(woCaps)) == 0) &&
  715. woCaps.dwFormats != 0L;
  716. ComboBox_ResetContent(hWndC);
  717. ComboBox_SetText(hWndF, gszNone);
  718. InitDialog(hDlg);
  719. giScheme = ComboBox_GetCurSel(hWndC);
  720. ghWnd = hDlg;
  721. SetCursor(hcur);
  722. break;
  723. case ID_BROWSE:
  724. aszFileName[0] = aszPath[0] = TEXT('\0');
  725. pEvent = (PEVENT)(GetWindowLongPtr(hDlg, DWLP_USER));
  726. wsprintf((LPTSTR)aszBrowse, (LPTSTR)aszBrowseStr, (LPTSTR)pEvent->pszEventLabel);
  727. if (GetOpenFileName(&ofn))
  728. {
  729. SetCurDir(hDlg, ofn.lpstrFile,TRUE, TRUE);
  730. ChangeSoundMapping(hDlg, ofn.lpstrFile, pEvent);
  731. }
  732. break;
  733. case ID_PLAY:
  734. {
  735. if (!gfSoundPlaying)
  736. {
  737. pEvent = (PEVENT)(GetWindowLongPtr(hDlg, DWLP_USER));
  738. if (pEvent)
  739. {
  740. if (PlaySoundFile(hDlg, pEvent->pszPath))
  741. {
  742. SendMessage(GetDlgItem(hDlg, ID_PLAY), BM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hBitmapStop);
  743. gfSoundPlaying = TRUE;
  744. }
  745. }
  746. }
  747. else
  748. {
  749. SendMessage(GetDlgItem(hDlg, ID_PLAY), BM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hBitmapPlay);
  750. gfSoundPlaying = FALSE;
  751. EndSound(&ghse);
  752. SetFocus(GetDlgItem(hDlg, ID_PLAY));
  753. }
  754. }
  755. break;
  756. case CB_SCHEMES:
  757. switch (codeNotify)
  758. {
  759. case CBN_DROPDOWN:
  760. fSchemeCBDroppedDown = TRUE;
  761. break;
  762. case CBN_CLOSEUP:
  763. fSchemeCBDroppedDown = FALSE;
  764. break;
  765. case CBN_SELCHANGE:
  766. if (fSchemeCBDroppedDown)
  767. break;
  768. case CBN_SELENDOK:
  769. if (fSavingPrevScheme)
  770. break;
  771. iIndex = ComboBox_GetCurSel(hWndC);
  772. if (iIndex != giScheme)
  773. {
  774. TCHAR szScheme[MAXSTR];
  775. BOOL fDeletedCurrent = FALSE;
  776. ComboBox_GetLBText(hWndC, iIndex, (LPTSTR)szScheme);
  777. if (giScheme == NONE_ENTRY)
  778. {
  779. pszKey = (LPTSTR)ComboBox_GetItemData(hWndC, giScheme);
  780. if (!lstrcmpi(pszKey, aszCurrent))
  781. {
  782. int i;
  783. i = DisplayMessage(hDlg, IDS_SAVESCHEME, IDS_SCHEMENOTSAVED, MB_YESNOCANCEL);
  784. if (i == IDCANCEL)
  785. {
  786. ComboBox_SetCurSel(hWndC, giScheme);
  787. break;
  788. }
  789. if (i == IDYES)
  790. {
  791. fSavingPrevScheme = TRUE;
  792. if (DialogBoxParam(ghInstance, MAKEINTRESOURCE(SAVESCHEMEDLG),
  793. GetParent(hDlg), SaveSchemeDlg, (LPARAM)(LPTSTR)gszNull))
  794. {
  795. fSavingPrevScheme = FALSE;
  796. ComboBox_SetCurSel(hWndC, iIndex);
  797. }
  798. else
  799. {
  800. fSavingPrevScheme = FALSE;
  801. ComboBox_SetCurSel(hWndC, NONE_ENTRY);
  802. break;
  803. }
  804. }
  805. }
  806. }
  807. pszKey = (LPTSTR)ComboBox_GetItemData(hWndC, NONE_ENTRY);
  808. if (!lstrcmpi(pszKey, aszCurrent))
  809. {
  810. ComboBox_DeleteString(hWndC, NONE_ENTRY);
  811. fDeletedCurrent = TRUE;
  812. }
  813. iIndex = ComboBox_FindStringExact(hWndC, 0, szScheme);
  814. pszKey = (LPTSTR)ComboBox_GetItemData(hWndC, iIndex);
  815. giScheme = iIndex;
  816. EndSound(&ghse);
  817. ShowSoundMapping(hDlg, NULL);
  818. hcur = SetCursor(LoadCursor(NULL,IDC_WAIT));
  819. if (LoadModules(hDlg, pszKey))
  820. {
  821. EnableWindow(GetDlgItem(hDlg, ID_SAVE_SCHEME), TRUE);
  822. }
  823. SetCursor(hcur);
  824. if (!lstrcmpi((LPTSTR)pszKey, aszDefault) || !lstrcmpi((LPTSTR)pszKey, gszNullScheme))
  825. EnableWindow(GetDlgItem(hDlg, ID_REMOVE_SCHEME),
  826. FALSE);
  827. else
  828. EnableWindow(GetDlgItem(hDlg, ID_REMOVE_SCHEME),TRUE);
  829. gfChanged = TRUE;
  830. gfNewScheme = FALSE;
  831. if (fDeletedCurrent)
  832. ComboBox_SetCurSel(hWndC, giScheme);
  833. PropSheet_Changed(GetParent(hDlg),hDlg);
  834. }
  835. break;
  836. }
  837. break;
  838. case IDC_SOUND_FILES:
  839. switch (codeNotify)
  840. {
  841. case CBN_SETFOCUS:
  842. {
  843. if (!gfSubClassedEditWindow)
  844. {
  845. HWND hwndEdit = GetFocus();
  846. SubClassEditWindow(hwndEdit);
  847. gfSubClassedEditWindow = TRUE;
  848. SetFocus(GetDlgItem(hDlg, IDC_EVENT_TREE)); //This setfocus hack is needed
  849. SetFocus(hwndEdit); //to activate the hook.
  850. }
  851. }
  852. break;
  853. case CBN_EDITCHANGE:
  854. DPF("CBN_EDITCHANGE \r\n");
  855. if (!gfEditBoxChanged)
  856. gfEditBoxChanged = TRUE;
  857. break;
  858. case CBN_DROPDOWN:
  859. DPF("CBN_DD\r\n");
  860. fFilesCBDroppedDown = TRUE;
  861. break;
  862. case CBN_CLOSEUP:
  863. DPF("CBN_CLOSEUP\r\n");
  864. fFilesCBDroppedDown = FALSE;
  865. break;
  866. case CBN_SELCHANGE:
  867. DPF("CBN_SELCHANGE\r\n");
  868. if (fFilesCBDroppedDown)
  869. break;
  870. case CBN_SELENDOK:
  871. {
  872. HWND hwndS = GetDlgItem(hDlg, IDC_SOUND_FILES);
  873. DPF("CBN_SELENDOK\r\n");
  874. iIndex = ComboBox_GetCurSel(hwndS);
  875. if (iIndex >= 0)
  876. {
  877. TCHAR szFile[MAX_PATH];
  878. if (gfEditBoxChanged)
  879. gfEditBoxChanged = FALSE;
  880. lstrcpy(szFile, gszCurDir);
  881. lstrcat(szFile, cszSlash);
  882. ComboBox_GetLBText(hwndS, iIndex, (LPTSTR)(szFile + lstrlen(szFile)));
  883. if (iIndex)
  884. {
  885. if (gfNukeExt)
  886. AddExt(szFile, cszWavExt);
  887. }
  888. else
  889. {
  890. TCHAR szTmp[64];
  891. ComboBox_GetText(hwndS, szTmp, sizeof(szTmp)/sizeof(TCHAR));
  892. iIndex = ComboBox_FindStringExact(hwndS, 0, szTmp);
  893. if (iIndex == CB_ERR)
  894. {
  895. if (DisplayMessage(hDlg, IDS_SOUND, IDS_NONECHOSEN, MB_YESNO) == IDNO)
  896. {
  897. PostMessage(ghwndDlg, WM_RESTOREEVENTFILE, 0, 1L);
  898. break;
  899. }
  900. }
  901. lstrcpy(szFile, gszNull);
  902. }
  903. pEvent = (PEVENT)(GetWindowLongPtr(hDlg, DWLP_USER));
  904. ChangeSoundMapping(hDlg, szFile, pEvent);
  905. SetFocus(GetDlgItem(hDlg, ID_PLAY));
  906. }
  907. break;
  908. }
  909. }
  910. break;
  911. case ID_SAVE_SCHEME:
  912. // Retrieve current scheme and pass it to the savescheme dialog.
  913. iIndex = ComboBox_GetCurSel(hWndC);
  914. if (iIndex != CB_ERR)
  915. {
  916. ComboBox_GetLBText(hWndC, iIndex, szBuf);
  917. if (DialogBoxParam(ghInstance, MAKEINTRESOURCE(SAVESCHEMEDLG),
  918. GetParent(hDlg), SaveSchemeDlg, (LPARAM)(LPTSTR)szBuf))
  919. {
  920. pszKey = (LPTSTR)ComboBox_GetItemData(hWndC, NONE_ENTRY);
  921. if (!lstrcmpi(pszKey, aszCurrent))
  922. {
  923. ComboBox_DeleteString(hWndC, NONE_ENTRY);
  924. }
  925. }
  926. }
  927. break;
  928. case ID_REMOVE_SCHEME:
  929. if (RemoveScheme(hDlg))
  930. {
  931. iIndex = ComboBox_FindStringExact(hWndC, 0, aszNullSchemeLabel);
  932. ComboBox_SetCurSel(hWndC, iIndex);
  933. giScheme = -1;
  934. FORWARD_WM_COMMAND(hDlg, CB_SCHEMES, hWndC, CBN_SELENDOK,SendMessage);
  935. }
  936. SetFocus(GetDlgItem(hDlg, CB_SCHEMES));
  937. break;
  938. }
  939. return FALSE;
  940. }
  941. void InitImageList(HWND hwndTree)
  942. {
  943. HICON hIcon = NULL;
  944. UINT uFlags;
  945. int cxMiniIcon;
  946. int cyMiniIcon;
  947. DWORD dwLayout;
  948. if (hSndImagelist)
  949. {
  950. TreeView_SetImageList(hwndTree, NULL, TVSIL_NORMAL);
  951. ImageList_Destroy(hSndImagelist);
  952. hSndImagelist = NULL;
  953. }
  954. cxMiniIcon = GetSystemMetrics(SM_CXSMICON);
  955. cyMiniIcon = GetSystemMetrics(SM_CYSMICON);
  956. uFlags = ILC_MASK | ILC_COLOR32;
  957. if (GetProcessDefaultLayout(&dwLayout) &&
  958. (dwLayout & LAYOUT_RTL))
  959. {
  960. uFlags |= ILC_MIRROR;
  961. }
  962. hSndImagelist = ImageList_Create(cxMiniIcon,cyMiniIcon, uFlags, 4, 2);
  963. if (!hSndImagelist)
  964. return;
  965. hIcon = LoadImage(ghInstance, MAKEINTRESOURCE(IDI_PROGRAM),IMAGE_ICON,cxMiniIcon,cyMiniIcon,LR_DEFAULTCOLOR);
  966. ImageList_AddIcon(hSndImagelist, hIcon);
  967. DestroyIcon(hIcon);
  968. hIcon = LoadImage(ghInstance, MAKEINTRESOURCE(IDI_AUDIO),IMAGE_ICON,cxMiniIcon,cyMiniIcon,LR_DEFAULTCOLOR);
  969. ImageList_AddIcon(hSndImagelist, hIcon);
  970. DestroyIcon(hIcon);
  971. hIcon = LoadImage(ghInstance, MAKEINTRESOURCE(IDI_BLANK),IMAGE_ICON,cxMiniIcon,cyMiniIcon,LR_DEFAULTCOLOR);
  972. ImageList_AddIcon(hSndImagelist, hIcon);
  973. DestroyIcon(hIcon);
  974. TreeView_SetImageList(hwndTree, hSndImagelist, TVSIL_NORMAL);
  975. }
  976. /*
  977. ***************************************************************
  978. * InitDialog
  979. *
  980. * Description:
  981. * Reads the current event names and mappings from reg.db
  982. *
  983. * Each entry in the [reg.db] section is in this form:
  984. *
  985. * AppEvents
  986. * |
  987. * |___Schemes = <SchemeKey>
  988. * |
  989. * |______Names
  990. * | |
  991. * | |______SchemeKey = <Name>
  992. * |
  993. * |______Apps
  994. * |
  995. * |______Module
  996. * |
  997. * |_____Event
  998. * |
  999. * |_____SchemeKey = <Path\filename>
  1000. * |
  1001. * |____Active = <1\0
  1002. *
  1003. * The Module, Event and the file label are displayed in the
  1004. * comboboxes.
  1005. *
  1006. * Parameters:
  1007. * HWND hDlg - parent window.
  1008. *
  1009. * Return Value: BOOL
  1010. * True if entire initialization is ok.
  1011. *
  1012. ***************************************************************
  1013. */
  1014. BOOL PASCAL InitDialog(HWND hDlg)
  1015. {
  1016. TCHAR szDefKey[MAXSTR];
  1017. TCHAR szScheme[MAXSTR];
  1018. TCHAR szLabel[MAXSTR];
  1019. int iVal;
  1020. int i;
  1021. int cAdded;
  1022. HWND hWndC;
  1023. LONG cbSize;
  1024. HKEY hkNames;
  1025. HWND hwndTree = GetDlgItem(hDlg, IDC_EVENT_TREE);
  1026. hWndC = GetDlgItem(hDlg, CB_SCHEMES);
  1027. InitImageList(hwndTree);
  1028. EnableWindow(GetDlgItem(hDlg, ID_SAVE_SCHEME), FALSE);
  1029. EnableWindow(GetDlgItem(hDlg, ID_REMOVE_SCHEME), FALSE);
  1030. EnableWindow(GetDlgItem(hDlg, ID_PLAY), FALSE);
  1031. EnableWindow(GetDlgItem(hDlg, ID_BROWSE), FALSE);
  1032. EnableWindow(GetDlgItem(hDlg, IDC_SOUND_FILES), FALSE);
  1033. EnableWindow(GetDlgItem(hDlg, IDC_STATIC_NAME), FALSE);
  1034. SetCurDir(hDlg, gszMediaDir, FALSE, TRUE);
  1035. if (RegOpenKey(HKEY_CURRENT_USER, aszNames, &hkNames) != ERROR_SUCCESS)
  1036. DPF("Failed to open aszNames\n");
  1037. else
  1038. DPF("Opened HKEY_CURRENT_USERS\n");
  1039. cAdded = 0;
  1040. for (i = 0; !RegEnumKey(hkNames, i, szScheme, sizeof(szScheme)/sizeof(TCHAR)); i++)
  1041. {
  1042. // Don't add the windows default key yet
  1043. if (lstrcmpi(szScheme, aszDefault))
  1044. {
  1045. cbSize = sizeof(szLabel);
  1046. if ((RegQueryValue(hkNames, szScheme, szLabel, &cbSize) != ERROR_SUCCESS) || (cbSize < 2))
  1047. lstrcpy(szLabel, szScheme);
  1048. if (!lstrcmpi(szScheme, gszNullScheme))
  1049. lstrcpy(aszNullSchemeLabel, szLabel);
  1050. ++cAdded;
  1051. AddScheme(hWndC, szLabel, szScheme, FALSE, 0);
  1052. }
  1053. }
  1054. // Add the windows default key in the second position in the listbox
  1055. cbSize = sizeof(szLabel);
  1056. if ((RegQueryValue(hkNames, aszDefault, szLabel, &cbSize) != ERROR_SUCCESS) || (cbSize < 2))
  1057. {
  1058. LoadString(ghInstance, IDS_WINDOWSDEFAULT, szLabel, MAXSTR);
  1059. if (RegSetValue(hkNames, aszDefault, REG_SZ, szLabel, 0) != ERROR_SUCCESS)
  1060. DPF("Failed to add printable name for default\n");
  1061. }
  1062. if (cAdded == 0)
  1063. AddScheme(hWndC, szLabel, (LPTSTR)aszDefault, TRUE, 0);
  1064. else
  1065. AddScheme(hWndC, szLabel, (LPTSTR)aszDefault, TRUE, WINDOWS_DEFAULTENTRY);
  1066. cbSize = sizeof(szDefKey);
  1067. if ((RegQueryValue(HKEY_CURRENT_USER, aszDefaultScheme, szDefKey,
  1068. &cbSize) != ERROR_SUCCESS) || (cbSize < 2))
  1069. {
  1070. ComboBox_SetCurSel(hWndC, 0);
  1071. DPF("No default scheme found\n");
  1072. }
  1073. else
  1074. {
  1075. if (!lstrcmpi(szDefKey, aszCurrent))
  1076. {
  1077. ComboBox_InsertString(hWndC, NONE_ENTRY, gszNull);
  1078. ComboBox_SetItemData(hWndC, NONE_ENTRY, aszCurrent);
  1079. iVal = NONE_ENTRY;
  1080. ComboBox_SetCurSel(hWndC, iVal);
  1081. }
  1082. else
  1083. {
  1084. cbSize = sizeof(szLabel);
  1085. if ((RegQueryValue(hkNames, szDefKey, szLabel, &cbSize) != ERROR_SUCCESS) || (cbSize < 2))
  1086. {
  1087. DPF("No Name for default scheme key %s found\n", (LPTSTR)szDefKey);
  1088. lstrcpy(szLabel, szDefKey);
  1089. }
  1090. if ((iVal = ComboBox_FindStringExact(hWndC, 0, szLabel)) != CB_ERR)
  1091. ComboBox_SetCurSel(hWndC, iVal);
  1092. else
  1093. if (lstrcmpi(aszDefault, szDefKey))
  1094. ComboBox_SetCurSel(hWndC, iVal);
  1095. else
  1096. {
  1097. iVal = ComboBox_GetCount(hWndC);
  1098. AddScheme(hWndC, szLabel, szDefKey, TRUE, iVal);
  1099. ComboBox_SetCurSel(hWndC, iVal);
  1100. }
  1101. }
  1102. giScheme = iVal; //setting the current global scheme;
  1103. if (LoadModules(hDlg, (LPTSTR)aszCurrent))
  1104. {
  1105. EnableWindow(GetDlgItem(hDlg, ID_SAVE_SCHEME), TRUE);
  1106. }
  1107. else
  1108. {
  1109. ClearModules(hDlg, hwndTree, TRUE);
  1110. ComboBox_SetCurSel(hWndC, 0);
  1111. DPF("LoadModules failed\n");
  1112. RegCloseKey(hkNames);
  1113. return FALSE;
  1114. }
  1115. if (!lstrcmpi(szDefKey, aszDefault))
  1116. EnableWindow(GetDlgItem(hDlg, ID_REMOVE_SCHEME), FALSE);
  1117. else
  1118. EnableWindow(GetDlgItem(hDlg, ID_REMOVE_SCHEME), TRUE);
  1119. // DPF("Finished doing init\n");
  1120. }
  1121. RegCloseKey(hkNames);
  1122. return TRUE;
  1123. }
  1124. const static DWORD aOpenHelpIDs[] = { // Context Help IDs
  1125. IDC_STATIC_PREVIEW, IDH_EVENT_BROWSE_PREVIEW,
  1126. ID_PLAY, IDH_EVENT_PLAY,
  1127. ID_STOP, IDH_EVENT_STOP,
  1128. 0, 0
  1129. };
  1130. INT_PTR CALLBACK OpenDlgHook(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  1131. {
  1132. static HSOUND hse;
  1133. switch (uMsg)
  1134. {
  1135. case WM_INITDIALOG:
  1136. {
  1137. TCHAR szOK[16];
  1138. TCHAR szBuf[MAXSTR];
  1139. LPTSTR lpszFile;
  1140. // lParam is lpOFN
  1141. DPF("****WM_INITDIALOG in HOOK **** \r\n");
  1142. LoadString(ghInstance, IDS_OK, szOK, sizeof(szOK)/sizeof(TCHAR));
  1143. SetDlgItemText(GetParent(hDlg), IDOK, szOK);
  1144. hse = NULL;
  1145. if (gfWaveExists)
  1146. {
  1147. HWND hwndPlay = GetDlgItem(hDlg, ID_PLAY);
  1148. HWND hwndStop = GetDlgItem(hDlg, ID_STOP);
  1149. SendMessage(hwndStop, BM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hBitmapStop);
  1150. SendMessage(hwndPlay, BM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hBitmapPlay);
  1151. EnableWindow(hwndStop, FALSE);
  1152. EnableWindow(hwndPlay, FALSE);
  1153. lpszFile = (LPTSTR)LocalAlloc(LPTR, MAX_PATH+sizeof(TCHAR));
  1154. SetWindowLongPtr(hDlg, DWLP_USER, (LPARAM)lpszFile);
  1155. LoadString (ghInstance, IDS_TIP_PLAY, szBuf, sizeof(szBuf)/sizeof(TCHAR));
  1156. CreateTooltip (GetDlgItem (hDlg, ID_PLAY), szBuf);
  1157. }
  1158. break;
  1159. }
  1160. case WM_HELP:
  1161. WinHelp((HWND)((LPHELPINFO) lParam)->hItemHandle, NULL,
  1162. HELP_WM_HELP, (UINT_PTR)(LPTSTR) aOpenHelpIDs);
  1163. break;
  1164. case WM_CONTEXTMENU:
  1165. WinHelp((HWND) wParam, NULL, HELP_CONTEXTMENU,
  1166. (UINT_PTR)(LPVOID) aOpenHelpIDs);
  1167. break;
  1168. case WM_COMMAND:
  1169. if (!gfWaveExists)
  1170. break;
  1171. switch (GET_WM_COMMAND_ID(wParam, lParam))
  1172. {
  1173. case ID_PLAY:
  1174. {
  1175. LPTSTR lpszFile = (LPTSTR)GetWindowLongPtr(hDlg, DWLP_USER);
  1176. MMRESULT err = MMSYSERR_NOERROR;
  1177. DPF("*****ID_PLAY in Dlg Hook ***\r\n");
  1178. if((soundOpen(lpszFile, hDlg, &hse) != MMSYSERR_NOERROR) || ((err = soundPlay(hse)) != MMSYSERR_NOERROR))
  1179. {
  1180. if (err == (MMRESULT)MMSYSERR_NOERROR || err != (MMRESULT)MMSYSERR_ALLOCATED)
  1181. ErrorBox(hDlg, IDS_ERRORFILEPLAY, lpszFile);
  1182. else
  1183. ErrorBox(hDlg, IDS_ERRORDEVBUSY, lpszFile);
  1184. hse = NULL;
  1185. }
  1186. else
  1187. {
  1188. EnableWindow(GetDlgItem(hDlg, ID_PLAY), FALSE);
  1189. EnableWindow(GetDlgItem(hDlg, ID_STOP), TRUE);
  1190. }
  1191. break;
  1192. }
  1193. case ID_STOP:
  1194. {
  1195. DPF("*****ID_STOP in Dlg Hook ***\r\n");
  1196. EndSound(&hse);
  1197. EnableWindow(GetDlgItem(hDlg, ID_STOP), FALSE);
  1198. EnableWindow(GetDlgItem(hDlg, ID_PLAY), TRUE);
  1199. break;
  1200. }
  1201. default:
  1202. return(FALSE);
  1203. }
  1204. break;
  1205. case MM_WOM_DONE:
  1206. EnableWindow(GetDlgItem(hDlg, ID_STOP), FALSE);
  1207. if (hse)
  1208. {
  1209. soundOnDone(hse);
  1210. soundClose(hse);
  1211. hse = NULL;
  1212. }
  1213. EnableWindow(GetDlgItem(hDlg, ID_PLAY), TRUE);
  1214. break;
  1215. case WM_DESTROY:
  1216. {
  1217. LPTSTR lpszFile;
  1218. if (!gfWaveExists)
  1219. break;
  1220. lpszFile = (LPTSTR)GetWindowLongPtr(hDlg, DWLP_USER);
  1221. DPF("**WM_DESTROY in Hook **\r\n");
  1222. if (lpszFile)
  1223. LocalFree((HLOCAL)lpszFile);
  1224. EndSound(&hse);
  1225. break;
  1226. }
  1227. case WM_NOTIFY:
  1228. {
  1229. LPOFNOTIFY pofn;
  1230. if (!gfWaveExists)
  1231. break;
  1232. pofn = (LPOFNOTIFY)lParam;
  1233. switch (pofn->hdr.code)
  1234. {
  1235. case CDN_SELCHANGE:
  1236. {
  1237. TCHAR szCurSel[MAX_PATH];
  1238. HWND hwndPlay = GetDlgItem(hDlg, ID_PLAY);
  1239. LPTSTR lpszFile = (LPTSTR)GetWindowLongPtr(hDlg, DWLP_USER);
  1240. HFILE hFile;
  1241. EndSound(&hse);
  1242. if (CommDlg_OpenSave_GetFilePath(GetParent(hDlg),szCurSel, sizeof(szCurSel)/sizeof(TCHAR)) <= (int)(sizeof(szCurSel)/sizeof(TCHAR)))
  1243. {
  1244. OFSTRUCT of;
  1245. if (!lstrcmpi(szCurSel, lpszFile))
  1246. break;
  1247. DPF("****The current selection is %s ***\r\n", szCurSel);
  1248. hFile = (HFILE)HandleToUlong(CreateFile(szCurSel,GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL));
  1249. if (lstrcmpi((LPTSTR)(szCurSel+lstrlen(szCurSel)-4), cszWavExt) || (-1 == hFile))
  1250. {
  1251. if (lpszFile[0] == TEXT('\0'))
  1252. break;
  1253. lpszFile[0] = TEXT('\0');
  1254. EnableWindow(hwndPlay, FALSE);
  1255. }
  1256. else
  1257. {
  1258. CloseHandle(LongToHandle(hFile));
  1259. EnableWindow(hwndPlay, TRUE);
  1260. lstrcpy(lpszFile, szCurSel);
  1261. }
  1262. }
  1263. break;
  1264. }
  1265. case CDN_FOLDERCHANGE:
  1266. {
  1267. EnableWindow(GetDlgItem(hDlg, ID_PLAY), FALSE);
  1268. break;
  1269. }
  1270. default:
  1271. break;
  1272. }
  1273. break;
  1274. }
  1275. default:
  1276. return FALSE;
  1277. }
  1278. return TRUE;
  1279. }
  1280. /*
  1281. ***************************************************************
  1282. * InitFileOpen
  1283. *
  1284. * Description:
  1285. * Sets up the openfilestruct to read display .wav and .mid files
  1286. * and sets up global variables for the filename and path.
  1287. *
  1288. * Parameters:
  1289. * HWND hDlg - Window handle
  1290. * LPOPENFILENAME lpofn - pointer to openfilename struct
  1291. *
  1292. * Returns: BOOL
  1293. *
  1294. ***************************************************************
  1295. */
  1296. STATIC BOOL PASCAL InitFileOpen(HWND hDlg, LPOPENFILENAME lpofn)
  1297. {
  1298. lpofn->lStructSize = sizeof(OPENFILENAME);
  1299. lpofn->hwndOwner = hDlg;
  1300. lpofn->hInstance = ghInstance;
  1301. lpofn->lpstrFilter = aszFilter;
  1302. lpofn->lpstrCustomFilter = NULL;
  1303. lpofn->nMaxCustFilter = 0;
  1304. lpofn->nFilterIndex = 0;
  1305. lpofn->lpstrFile = aszPath;
  1306. lpofn->nMaxFile = sizeof(aszPath)/sizeof(TCHAR);
  1307. lpofn->lpstrFileTitle = aszFileName;
  1308. lpofn->nMaxFileTitle = sizeof(aszFileName)/sizeof(TCHAR);
  1309. lpofn->lpstrInitialDir = gszCurDir;
  1310. lpofn->lpstrTitle = aszBrowse;
  1311. lpofn->Flags = OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST |OFN_HIDEREADONLY |OFN_EXPLORER |OFN_ENABLEHOOK;
  1312. if (gfWaveExists)
  1313. lpofn->Flags |= OFN_ENABLETEMPLATE;
  1314. lpofn->nFileOffset = 0;
  1315. lpofn->nFileExtension = 0;
  1316. lpofn->lpstrDefExt = NULL;
  1317. lpofn->lCustData = 0;
  1318. lpofn->lpfnHook = OpenDlgHook;
  1319. if (gfWaveExists)
  1320. lpofn->lpTemplateName = MAKEINTRESOURCE(BROWSEDLGTEMPLATE);
  1321. else
  1322. lpofn->lpTemplateName = NULL;
  1323. return TRUE;
  1324. }
  1325. /* FixupNulls(chNull, p)
  1326. *
  1327. * To facilitate localization, we take a localized string with non-NULL
  1328. * NULL substitutes and replacement with a real NULL.
  1329. */
  1330. STATIC void NEAR PASCAL FixupNulls(
  1331. TCHAR chNull,
  1332. LPTSTR p)
  1333. {
  1334. while (*p) {
  1335. if (*p == chNull)
  1336. *p++ = 0;
  1337. else
  1338. p = CharNext(p);
  1339. }
  1340. } /* FixupNulls */
  1341. /* GetDefaultMediaDirectory
  1342. *
  1343. * Returns C:\WINNT\Media, or whatever it's called.
  1344. *
  1345. */
  1346. BOOL GetDefaultMediaDirectory(LPTSTR pDirectory, DWORD cbDirectory)
  1347. {
  1348. static SZCODE szSetup[] = REGSTR_PATH_SETUP;
  1349. static SZCODE szMedia[] = REGSTR_VAL_MEDIA;
  1350. HKEY hkeySetup;
  1351. LONG Result;
  1352. Result = RegOpenKeyEx(HKEY_LOCAL_MACHINE, szSetup,
  1353. REG_OPTION_RESERVED,
  1354. KEY_QUERY_VALUE, &hkeySetup);
  1355. if (Result == ERROR_SUCCESS)
  1356. {
  1357. Result = RegQueryValueEx(hkeySetup, szMedia, NULL, REG_NONE,
  1358. (LPBYTE)pDirectory, &cbDirectory);
  1359. RegCloseKey(hkeySetup);
  1360. }
  1361. return (Result == ERROR_SUCCESS);
  1362. }
  1363. /*
  1364. ***************************************************************
  1365. * InitStringTable
  1366. *
  1367. * Description:
  1368. * Load the RC strings into the storage for them
  1369. *
  1370. * Parameters:
  1371. * void
  1372. *
  1373. * Returns: BOOL
  1374. ***************************************************************
  1375. */
  1376. STATIC BOOL PASCAL InitStringTable(void)
  1377. {
  1378. static SZCODE cszSetup[] = REGSTR_PATH_SETUP;
  1379. static SZCODE cszMedia[] = REGSTR_VAL_MEDIA;
  1380. LoadString(ghInstance, IDS_NONE, gszNone, sizeof(gszNone)/sizeof(TCHAR));
  1381. LoadString(ghInstance, IDS_BROWSEFORSOUND, aszBrowseStr, sizeof(aszBrowseStr)/sizeof(TCHAR));
  1382. LoadString(ghInstance, IDS_REMOVESCHEME, gszRemoveScheme,sizeof(gszRemoveScheme)/sizeof(TCHAR));
  1383. LoadString(ghInstance, IDS_CHANGESCHEME, gszChangeScheme,sizeof(gszChangeScheme)/sizeof(TCHAR));
  1384. LoadString(ghInstance, IDS_DEFAULTAPP, gszDefaultApp, sizeof(gszDefaultApp)/sizeof(TCHAR));
  1385. LoadString(ghInstance, IDS_WAVFILES, aszFilter, sizeof(aszFilter)/sizeof(TCHAR));
  1386. LoadString(ghInstance, IDS_NULLCHAR, aszNullChar, sizeof(aszNullChar)/sizeof(TCHAR));
  1387. FixupNulls(*aszNullChar, aszFilter);
  1388. gszMediaDir[0] = TEXT('\0');
  1389. if (!GetDefaultMediaDirectory(gszMediaDir, sizeof(gszMediaDir)/sizeof(TCHAR)))
  1390. {
  1391. if (!GetWindowsDirectory (gszMediaDir, sizeof(gszMediaDir)/sizeof(TCHAR)))
  1392. return FALSE;
  1393. }
  1394. return TRUE;
  1395. }
  1396. /*
  1397. ***************************************************************
  1398. * SoundCleanup
  1399. *
  1400. * Description:
  1401. * Cleanup all the allocs and bitmaps when the sound page exists
  1402. *
  1403. * Parameters:
  1404. * void
  1405. *
  1406. * Returns: BOOL
  1407. ***************************************************************
  1408. */
  1409. STATIC BOOL PASCAL SoundCleanup(HWND hDlg)
  1410. {
  1411. DeleteObject(hBitmapStop);
  1412. DeleteObject(hBitmapPlay);
  1413. TreeView_SetImageList(GetDlgItem(hDlg, IDC_EVENT_TREE), NULL, TVSIL_NORMAL);
  1414. ImageList_Destroy(hSndImagelist);
  1415. hSndImagelist = NULL;
  1416. DPF("ending sound cleanup\n");
  1417. return TRUE;
  1418. }
  1419. /****************************************************************************/