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.

256 lines
5.6 KiB

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