Annotation of mstools/samples/playsnd/sound.c, revision 1.1

1.1     ! root        1: /*
        !             2:     sound.c
        !             3: 
        !             4:     Sound menu stuff
        !             5: 
        !             6:     Puts up a list of all the sounds in the [sounds]
        !             7:     section of win.ini and plays the selected one
        !             8: 
        !             9: 
        !            10: */
        !            11: 
        !            12: #include <stdlib.h>
        !            13: #include <string.h>
        !            14: #include <windows.h>
        !            15: #include "PlaySnd.h"
        !            16: 
        !            17: #define KEYBUFSIZE 2048
        !            18: 
        !            19: LONG SoundDlgProc(HWND hDlg, UINT msg, DWORD wParam, LONG lParam);
        !            20: 
        !            21: typedef struct SoundNameAlias {
        !            22:        LPSTR pName;
        !            23:        UINT  alias;
        !            24: } SOUNDNAMEALIAS;
        !            25: 
        !            26: static SOUNDNAMEALIAS sss[] = {"System"};
        !            27: 
        !            28: static SOUNDNAMEALIAS SNA[] = {
        !            29:       "SystemAsterisk",     sndAlias('S', '*')   ,
        !            30:       "SystemQuestion",     sndAlias('S', '?')   ,
        !            31:       "SystemHand",         sndAlias('S', 'H')   ,
        !            32:       "SystemExit",         sndAlias('S', 'E')   ,
        !            33:       "SystemStartup",      sndAlias('S', 'S')   ,
        !            34:          "SystemWelcome",      sndAlias('S', 'W')   ,
        !            35:       "SystemExclamation",  sndAlias('S', '!')  ,
        !            36:       "SystemDefault",      sndAlias('S', 'D')   };
        !            37:                                                                                        
        !            38: #define NUMSYSTEMSOUNDS (sizeof(SNA)/sizeof(SOUNDNAMEALIAS))
        !            39: 
        !            40: UINT TranslateNameToAlias(LPSTR name)
        !            41: {
        !            42:        UINT n;
        !            43: 
        !            44:        for (n=0; n<NUMSYSTEMSOUNDS; ++n) {
        !            45: 
        !            46:                if (!lstrcmpi(name, SNA[n].pName)) {
        !            47:                        return(SNA[n].alias);
        !            48:                }
        !            49:        }
        !            50: 
        !            51:        return(0);
        !            52: }
        !            53: 
        !            54: void Sounds(HWND hWnd)
        !            55: {
        !            56:     WinEval(DialogBox(ghModule, MAKEINTRESOURCE(IDD_SOUNDDLG) // "SoundDlg"
        !            57:                        , hWnd, (DLGPROC)SoundDlgProc) != -1);
        !            58: }
        !            59: 
        !            60: void PlaySelection(HWND hDlg)
        !            61: {
        !            62:     DWORD dwSel;
        !            63:     DWORD dwFlags = SND_ASYNC | SND_NODEFAULT | SND_NOSTOP;
        !            64:     char name[40];
        !            65:        UINT alias;
        !            66:        LPSTR pName = name;
        !            67:        BOOL fSync;
        !            68:        BOOL fWait;
        !            69: 
        !            70:     dwSel = SendDlgItemMessage(hDlg, IDSND_LIST, LB_GETCURSEL, 0, 0);
        !            71:     if (dwSel != LB_ERR) {
        !            72:         SendDlgItemMessage(hDlg, IDSND_LIST,
        !            73:                     LB_GETTEXT,
        !            74:                     (WPARAM)dwSel,
        !            75:                     (LPARAM)name);
        !            76: 
        !            77:         dwFlags = SND_ALIAS;
        !            78: 
        !            79:                fSync = (BOOL)SendDlgItemMessage(hDlg, IDSND_SYNC, BM_GETCHECK, 0, 0);
        !            80: 
        !            81:         if (fSync) {
        !            82:                        // Turn off ASYNC
        !            83:                        dwFlags &= ~SND_ASYNC;
        !            84:                } else {
        !            85:                        dwFlags |= SND_ASYNC;
        !            86:                }
        !            87: 
        !            88:                fWait = (BOOL)SendDlgItemMessage(hDlg, IDSND_WAIT, BM_GETCHECK, 0, 0);
        !            89:         if (!fWait) dwFlags |= SND_NOWAIT;
        !            90: 
        !            91:                if (1 == SendDlgItemMessage(hDlg, IDSND_IDPLAY, BM_GETCHECK, 0, 0)) {
        !            92:                        if (0 != (alias = TranslateNameToAlias(name))) {
        !            93:                                dwFlags |= SND_ALIAS_ID;
        !            94:                                pName = (LPSTR)alias;
        !            95:                        }
        !            96:                }
        !            97: 
        !            98:         if (!PlaySound(pName, NULL, dwFlags)) {
        !            99:             Error("Failed to play alias: %s", name);
        !           100:         }
        !           101:     }
        !           102: 
        !           103: }
        !           104: 
        !           105: LONG SoundDlgProc(HWND hDlg, UINT msg, DWORD wParam, LONG lParam)
        !           106: {
        !           107:     LPSTR lpBuf, lpKey;
        !           108:     DWORD dwChars;
        !           109: 
        !           110: //  dprintf4("SoundDlgProc: %8.8XH, %8.8XH, %8.8XH", msg, wParam, lParam);
        !           111: 
        !           112:     switch (msg) {
        !           113:     case WM_INITDIALOG:
        !           114:         // fill the listbox with the keys in the [sounds]
        !           115:         // section of win.ini
        !           116: 
        !           117:         // allocate a buffer to put the keys in
        !           118:         WinEval(lpBuf = (LPSTR) GlobalAlloc(GMEM_FIXED|GMEM_ZEROINIT, KEYBUFSIZE));
        !           119: 
        !           120:         // get the key list
        !           121:         dwChars = GetProfileString("sounds", NULL, "", lpBuf, KEYBUFSIZE);
        !           122:         dprintf4("%lu chars read from [sounds] section", dwChars);
        !           123: 
        !           124:         if (dwChars > 0) {
        !           125:             // add each entry to the list box
        !           126:             lpKey = lpBuf;
        !           127:             while (*lpKey) {
        !           128:                                // TEMPORARY SECTION
        !           129:                                if (lstrcmpi((LPCTSTR)lpKey, "enable"))  // if not ENABLE
        !           130:                                // END OF TEMPORARY SECTION
        !           131:                 SendMessage(GetDlgItem(hDlg, IDSND_LIST),
        !           132:                             LB_ADDSTRING,
        !           133:                             0,
        !           134:                             (LONG)lpKey);
        !           135:                 lpKey += strlen(lpKey) + 1;
        !           136:             }
        !           137:         } else {
        !           138:             // show there aren't any
        !           139:             SendMessage(GetDlgItem(hDlg, IDSND_LIST),
        !           140:                         LB_ADDSTRING,
        !           141:                         0,
        !           142:                         (LONG)(LPSTR)"[none]");
        !           143:         }
        !           144: 
        !           145:                if (bSync) {
        !           146:                        // Set the initial state of the Sync checkbox from global flag
        !           147:                        SendDlgItemMessage(hDlg, IDSND_SYNC, BM_SETCHECK, 1, 0);
        !           148:                }
        !           149: 
        !           150:                if (!bNoWait) {
        !           151:                        // Set the initial state of the Wait checkbox from global flag
        !           152:                        SendDlgItemMessage(hDlg, IDSND_WAIT, BM_SETCHECK, 1, 0);
        !           153:                }
        !           154: 
        !           155:         GlobalFree((HANDLE)lpBuf);
        !           156: 
        !           157:         // disable the play button till we get a selection
        !           158:         EnableWindow(GetDlgItem(hDlg, IDSND_PLAY), FALSE);
        !           159: 
        !           160:         break;
        !           161: 
        !           162:     case WM_COMMAND:
        !           163:         dprintf4("WM_COMMAND: %08lXH, %08lX", wParam, lParam);
        !           164:         switch (LOWORD(wParam)) {
        !           165:         case IDOK:
        !           166:             EndDialog(hDlg, TRUE);
        !           167:             break;
        !           168: 
        !           169:         case IDSND_PLAY:
        !           170:             // get the current selection and try to play it
        !           171:             PlaySelection(hDlg);
        !           172:             break;
        !           173: 
        !           174:         case IDSND_LIST:
        !           175:             switch (HIWORD(wParam)){
        !           176:             case LBN_SELCHANGE:
        !           177:                 // enable the play button
        !           178:                 EnableWindow(GetDlgItem(hDlg, IDSND_PLAY), TRUE);
        !           179:                 dprintf3("Play button enabled");
        !           180:                 break;
        !           181: 
        !           182:             case LBN_DBLCLK:
        !           183:                 PlaySelection(hDlg);
        !           184:                 break;
        !           185: 
        !           186:             default:
        !           187:                 break;
        !           188:             }
        !           189:             break;
        !           190: 
        !           191:         default:
        !           192:             break;
        !           193:         }
        !           194:         break;
        !           195: 
        !           196:     default:
        !           197:         return FALSE; // say we didn't handle it
        !           198:         break;
        !           199:     }
        !           200: 
        !           201:     return TRUE; // say we handled it
        !           202: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.