Annotation of mstools/samples/playsnd/playsnd.c, revision 1.1.1.2

1.1       root        1: /*
                      2:     PlaySnd.c
                      3: 
                      4:     This is a PlaySnd Win32 app
                      5: 
                      6: */
                      7: 
                      8: #include <windows.h>
                      9: #include "PlaySnd.h"
                     10: 
                     11: /* useful global things */
                     12: 
                     13: HANDLE ghModule;                // global module handle
                     14: char szAppName[SIZEOFAPPNAME];  // app name
                     15: HWND ghwndMain;                 // handle of main window
                     16: BOOL bNoWait;
1.1.1.2 ! root       17: BOOL bNoDefault = SND_NODEFAULT;
1.1       root       18: BOOL bSync;
                     19: BOOL bResourceID;
                     20: 
                     21: //
                     22: // local fns
                     23: //
                     24: 
                     25: void MyBeep(DWORD wParam);
                     26: 
                     27: /***************** Main entry point routine *************************/
                     28: 
                     29: int _CRTAPI1 main(int argc, char *argv[], char *envp[])
                     30: {
                     31:     MSG msg;
                     32:     HANDLE hAccTable;           /* handle to keyboard accelerator table */
                     33: 
                     34:     UNREFERENCED_PARAMETER(envp);
                     35: 
                     36:     if (argc > 1) {
                     37: 
                     38:         // assume that the first arg is a filename
1.1.1.2 ! root       39:                dprintf1(("Calling PLAYSOUND to play %s", argv[1]));
1.1       root       40: 
                     41:                WinAssert(SND_ASYNC);
                     42: 
1.1.1.2 ! root       43:         PlaySound(argv[1], NULL, SND_SYNC | SND_FILENAME | bNoDefault);
1.1       root       44:         return 0;
                     45:     }
                     46: 
                     47:     // try to init the main part of the app
                     48:     if (! InitApp()) {
1.1.1.2 ! root       49:                dprintf(("Failed to initialise correctly"));
1.1       root       50:         return 1;
                     51:     }
                     52: 
                     53:     /* load the keyboard accelerator table */
                     54: 
                     55:     hAccTable = LoadAccelerators(ghModule, MAKEINTRESOURCE(IDA_ACCTABLE)/*"AccTable" */);
                     56:     WinAssert(hAccTable);
                     57: 
                     58:     /* check for messages from Windows and process them */
                     59: 
                     60:     while (GetMessage(&msg, NULL, 0, 0)) {
                     61:         if (!TranslateAccelerator(ghwndMain, hAccTable, &msg)) {
                     62:             TranslateMessage(&msg);
                     63:             DispatchMessage(&msg);
                     64:         }
                     65:     }
                     66: 
                     67:     return 0;
                     68: }
                     69: 
                     70: /************* main window message handler ******************************/
                     71: 
                     72: int APIENTRY MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
                     73: {
                     74:     HMENU hMenu;
                     75:     PAINTSTRUCT ps;             /* paint structure */
                     76: 
                     77:     /* process any messages we want */
                     78: 
                     79:     switch(message) {
                     80:     case WM_CREATE:
                     81:         break;
                     82: 
                     83:     case WM_SIZE:
                     84:         break;
                     85: 
                     86:     case WM_INITMENUPOPUP:
                     87:         // show the option flag states
1.1.1.2 ! root       88:                dprintf2(("WM_INITMENUPOPUP %8x %8x %8x",hWnd, wParam, lParam));
1.1       root       89:         hMenu = GetMenu(hWnd);
                     90:         CheckMenuItem(hMenu, IDM_SYNC, bSync ? MF_CHECKED : MF_UNCHECKED);
                     91:         CheckMenuItem(hMenu, IDM_NOWAIT, bNoWait ? MF_CHECKED : MF_UNCHECKED);
1.1.1.2 ! root       92: 
        !            93:         // Note: we are slightly naughty here.  bNoDefault is not a true
        !            94:         // boolean value.  It will contain SND_NODEFAULT or NULL
        !            95:         CheckMenuItem(hMenu, IDM_NODEFAULT, bNoDefault ? MF_CHECKED : MF_UNCHECKED);
        !            96: 
1.1       root       97:         CheckMenuItem(hMenu, IDM_RESOURCEID, bResourceID ? MF_CHECKED : MF_UNCHECKED);
                     98: 
1.1.1.2 ! root       99:        ModifyMenu(hMenu, IDM_HELP_KEYBOARD, MF_GRAYED | MF_STRING, IDM_HELP_KEYBOARD, "&Keyboard"); 
        !           100: 
1.1       root      101: #ifdef MEDIA_DEBUG
                    102:                CheckMenuItem(hMenu, (__iDebugLevel + IDM_DEBUG0), MF_CHECKED);
                    103: #endif
                    104:         break;
                    105: 
                    106:     case WM_COMMAND:
                    107:         /* process menu messages */
                    108:         CommandMsg(hWnd, wParam);
                    109:         break;
                    110: 
                    111:     case WM_PAINT:
                    112:         BeginPaint(hWnd, &ps);
                    113:         EndPaint(hWnd, &ps);
                    114:         break;
                    115: 
                    116:     case WM_DESTROY:
                    117:         TerminateApp();
                    118:         PostQuitMessage(0);
                    119:         break;
                    120: 
                    121:     default:
                    122:         return DefWindowProc(hWnd, message, wParam, lParam);
                    123:         break;
                    124:     }
                    125:     return 0;
                    126: }
                    127: 
                    128: void CommandMsg(HWND hWnd, DWORD wParam)
                    129: {
                    130:     /* process any WM_COMMAND messages we want */
                    131: 
                    132:     switch (wParam) {
                    133:     case IDM_PLAYFILE:
                    134:         PlayFile();
                    135:         break;
                    136: 
                    137:     case IDM_SOUNDS:
                    138:         Sounds(hWnd);
                    139:         break;
                    140: 
                    141:     case IDM_DING:
                    142:     case IDM_SIREN:
                    143:     case IDM_LASER:
                    144:         Resource(wParam);
                    145:         break;
                    146: 
                    147:     case IDM_ICONHAND:
                    148:     case IDM_ICONQUESTION:
                    149:     case IDM_ICONEXCLAMATION:
                    150:     case IDM_ICONASTERISK:
                    151:     case IDM_SYNC_ICONHAND:
                    152:     case IDM_SYNC_ICONQUESTION:
                    153:     case IDM_SYNC_ICONEXCLAMATION:
                    154:     case IDM_SYNC_ICONASTERISK:
                    155:         MyBeep(wParam);
                    156:         break;
                    157: 
                    158:     case IDM_RESOURCEID:
                    159:         bResourceID = !bResourceID;
                    160:         break;
                    161: 
                    162:     case IDM_SYNC:
                    163:         bSync = !bSync;
                    164:         break;
                    165: 
                    166:     case IDM_NOWAIT:
                    167:         bNoWait = !bNoWait;
                    168:         break;
                    169: 
1.1.1.2 ! root      170:     case IDM_NODEFAULT:
        !           171:         if (bNoDefault) {
        !           172:             bNoDefault = 0;
        !           173:         } else {
        !           174:             bNoDefault = SND_NODEFAULT;
        !           175:         }
        !           176:         break;
        !           177: 
1.1       root      178:     case IDM_ABOUT:
                    179:         About(hWnd);
                    180:         break;
                    181: 
                    182:     case IDM_HELP_INDEX:
                    183:     case IDM_HELP_KEYBOARD:
                    184:     case IDM_HELP_HELP:
                    185:         Help(hWnd, wParam);
                    186:         break;
                    187: 
                    188: #ifdef MEDIA_DEBUG
                    189:     case IDM_DEBUG0:
                    190:     case IDM_DEBUG1:
                    191:     case IDM_DEBUG2:
                    192:     case IDM_DEBUG3:
                    193:     case IDM_DEBUG4:
                    194:         dDbgSetDebugMenuLevel((int)(wParam - IDM_DEBUG0));
                    195:         break;
                    196: #endif
                    197: 
                    198:     case IDM_EXIT:
                    199:         PostMessage(hWnd, WM_CLOSE, 0, 0l);
                    200:         break;
                    201: 
                    202:     default:
                    203:         break;
                    204:     }
                    205: }
                    206: 
                    207: void MyBeep(DWORD wParam)
                    208: {
                    209:     DWORD dwFlags = MB_OK;
                    210:        LPSTR lpstr = NULL;
                    211: 
                    212:     switch (wParam) {
                    213:     case IDM_SYNC_ICONHAND:
                    214:     case IDM_SYNC_ICONQUESTION:
                    215:     case IDM_SYNC_ICONEXCLAMATION:
                    216:     case IDM_SYNC_ICONASTERISK:
                    217:         dwFlags |= MB_TASKMODAL;
                    218:         break;
                    219:     }
                    220: 
                    221:     switch (wParam) {
                    222:     case IDM_ICONHAND:
                    223:     case IDM_SYNC_ICONHAND:
                    224:         dwFlags |= MB_ICONHAND;
                    225:         lpstr =  "MB_ICONHAND";
                    226:         break;
                    227: 
                    228:     case IDM_ICONQUESTION:
                    229:     case IDM_SYNC_ICONQUESTION:
                    230:         dwFlags |= MB_ICONQUESTION;
                    231:         lpstr =  "MB_ICONQUESTION";
                    232:         break;
                    233: 
                    234:     case IDM_ICONEXCLAMATION:
                    235:     case IDM_SYNC_ICONEXCLAMATION:
                    236:         dwFlags |= MB_ICONEXCLAMATION;
                    237:         lpstr = "MB_ICONEXCLAMATION";
                    238:         break;
                    239: 
                    240:     case IDM_ICONASTERISK:
                    241:     case IDM_SYNC_ICONASTERISK:
                    242:         dwFlags |= MB_ICONASTERISK;
                    243:         lpstr = "MB_ICONASTERISK";
                    244:         break;
                    245: 
                    246:     default:
                    247:         break;
                    248: 
                    249:     }
                    250:        if (lpstr) {
1.1.1.2 ! root      251:                dprintf2(("Calling Message beep with flags %8x  Type %s", dwFlags, lpstr));
1.1       root      252:         MessageBeep((UINT)dwFlags);
1.1.1.2 ! root      253:                dprintf2(("Now calling MessageBox"));
1.1       root      254:         MessageBox(ghwndMain, lpstr, szAppName, (UINT)dwFlags);
                    255:        }
                    256: }

unix.superglobalmegacorp.com

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