--- mstools/samples/playsnd/sound.c 2018/08/09 18:21:49 1.1 +++ mstools/samples/playsnd/sound.c 2018/08/09 18:23:57 1.1.1.2 @@ -12,6 +12,7 @@ #include #include #include +#include #include "PlaySnd.h" #define KEYBUFSIZE 2048 @@ -60,7 +61,7 @@ void Sounds(HWND hWnd) void PlaySelection(HWND hDlg) { DWORD dwSel; - DWORD dwFlags = SND_ASYNC | SND_NODEFAULT | SND_NOSTOP; + DWORD dwFlags = SND_ASYNC | bNoDefault | SND_NOSTOP; char name[40]; UINT alias; LPSTR pName = name; @@ -95,19 +96,47 @@ void PlaySelection(HWND hDlg) } } - if (!PlaySound(pName, NULL, dwFlags)) { + if (!PlaySound(pName, NULL, dwFlags | bNoDefault)) { Error("Failed to play alias: %s", name); } } } +VOID SetSoundName(HWND hDlg) +{ + DWORD dwSel; + char name[40]; + char filename[MAX_PATH]; + UINT n; + + dwSel = SendDlgItemMessage(hDlg, IDSND_LIST, LB_GETCURSEL, 0, 0); + if (dwSel != LB_ERR + && SendDlgItemMessage(hDlg, IDSND_LIST, + LB_GETTEXT, + (WPARAM)dwSel, + (LPARAM)name) + && (n=GetProfileString("SOUNDS", name, NULL, filename, sizeof(filename))) + ) { + do { + n--; + if (filename[n] == ',') { + filename[n]=0; + } + } while (filename[n]); + GetFileTitle(filename, name, sizeof(name)); + SendDlgItemMessage(hDlg, IDSND_SOUNDNAME, WM_SETTEXT, 0, (LPARAM)name); + } else { + SendDlgItemMessage(hDlg, IDSND_SOUNDNAME, WM_SETTEXT, 0, (LPARAM)""); + } +} + LONG SoundDlgProc(HWND hDlg, UINT msg, DWORD wParam, LONG lParam) { LPSTR lpBuf, lpKey; DWORD dwChars; -// dprintf4("SoundDlgProc: %8.8XH, %8.8XH, %8.8XH", msg, wParam, lParam); +// dprintf4(("SoundDlgProc: %8.8XH, %8.8XH, %8.8XH", msg, wParam, lParam)); switch (msg) { case WM_INITDIALOG: @@ -119,7 +148,7 @@ LONG SoundDlgProc(HWND hDlg, UINT msg, D // get the key list dwChars = GetProfileString("sounds", NULL, "", lpBuf, KEYBUFSIZE); - dprintf4("%lu chars read from [sounds] section", dwChars); + dprintf4(("%lu chars read from [sounds] section", dwChars)); if (dwChars > 0) { // add each entry to the list box @@ -141,6 +170,7 @@ LONG SoundDlgProc(HWND hDlg, UINT msg, D 0, (LONG)(LPSTR)"[none]"); } + SendDlgItemMessage(hDlg, IDSND_SOUNDNAME, WM_SETTEXT, 0, (LPARAM)""); if (bSync) { // Set the initial state of the Sync checkbox from global flag @@ -160,7 +190,7 @@ LONG SoundDlgProc(HWND hDlg, UINT msg, D break; case WM_COMMAND: - dprintf4("WM_COMMAND: %08lXH, %08lX", wParam, lParam); + dprintf4(("WM_COMMAND: %08lXH, %08lX", wParam, lParam)); switch (LOWORD(wParam)) { case IDOK: EndDialog(hDlg, TRUE); @@ -176,7 +206,9 @@ LONG SoundDlgProc(HWND hDlg, UINT msg, D case LBN_SELCHANGE: // enable the play button EnableWindow(GetDlgItem(hDlg, IDSND_PLAY), TRUE); - dprintf3("Play button enabled"); + dprintf3(("Play button enabled")); + // Set the current sound name + SetSoundName(hDlg); break; case LBN_DBLCLK: