home *** CD-ROM | disk | FTP | other *** search
/ Sound Sensations! / sound_sensations.iso / soundb / sndhack / main.c < prev    next >
C/C++ Source or Header  |  1991-07-30  |  9KB  |  311 lines

  1. #include <windows.h>
  2. #include "app.h"
  3.  
  4. /*
  5.  * SndHack, A Windows Sound Hack Utility in
  6.  * Borland C++.  By Jerry Joplin, 1991.  Please
  7.  * modify and improve this code as you see fit.
  8.  *
  9.  * SndHack is a Windows Sound Function Interpreter.  It
  10.  * interprets text as a series of calls to Windows
  11.  * Sound Functions and executes the Sound Functions.
  12.  *
  13.  * Module: main.c
  14.  *
  15.  * Contains: Global data and functions.  WinMain and
  16.  * application wide functions should be located here.
  17.  *
  18.  */
  19.  
  20. /*********************************************************************/
  21. /* Global data                                                       */
  22. /*********************************************************************/
  23.  
  24. HWND    hWindow;                      /* handle to class window      */
  25. HANDLE  hInst;                        /* handle to process instance  */
  26. HWND    hEditWindow;                  /* handle to edit window       */
  27. HANDLE  hAccelTable;                  /* handle to accelerator table */
  28. HMENU   hMenu;                        /* handle to menu              */
  29. HANDLE  hNote;                        /* handle to note cursor       */
  30. HANDLE  hHourGlass;                   /* handle to hourglass cursor  */
  31. HANDLE  hText = NULL;                 /* handle to Edit Text buffer  */
  32. HANDLE  hData, hClipData;             /* handles to clip data        */
  33. LPSTR   lpData, lpClipData;           /* pointers to clip data       */
  34.  
  35. char WindowName[]    = "SndHack";
  36. char ClassName[]     = "SndHack";
  37. char HelpFileName[80];
  38.  
  39. /* Default sound function settings data structure                    */
  40. SndDef SndState = {
  41.   0,                                  /* open state: 0=closed, 1=open*/
  42.   0,                                  /* numvoices, total voices     */
  43.   S_PERIODVOICE,                      /* source setting              */
  44.   1,                                  /* voice, last voice used      */
  45.   120,                                /* tempo setting               */
  46.   64,                                 /* volume setting              */
  47.   S_NORMAL,                           /* mode setting                */
  48.   0,                                  /* pitch setting               */
  49.   1,                                  /* value of note setting       */
  50.   2,                                  /* length of note setting      */
  51.   0,                                  /* cdots of note setting       */
  52.   1,                                  /* shape of waveform setting   */
  53.   1,                                  /* repeat count setting        */
  54.   0x01000000L,                        /* long frequency setting      */
  55.   0x0100,                             /* frequency setting           */
  56.   0,                                  /* frequency fraction setting  */
  57.   1,                                  /* duration of sound setting   */
  58.   192,                                /* queue size                  */
  59.   0,                                  /* threshold count setting     */
  60.   S_QUEUEEMPTY,                       /* wait state setting          */
  61. };
  62.  
  63. /*********************************************************************/
  64. /* Local Function Prototypes                                         */
  65. /*********************************************************************/
  66.  
  67. void OutOfMemory(void);
  68.  
  69. /*********************************************************************/
  70. /* Local data and structures                                         */
  71. /*********************************************************************/
  72.  
  73.  
  74. /*-------------------------------------------------------------------*/
  75. /* Windows main()                                                    */
  76. /*-------------------------------------------------------------------*/
  77.  
  78. int NEAR PASCAL WinMain(hInstance, hPrevInstance, lpszCmdLine, cmdShow)
  79. HANDLE hInstance;
  80. HANDLE hPrevInstance;
  81. LPSTR lpszCmdLine;
  82. int cmdShow;
  83. {
  84.   HWND  hWnd;
  85.   MSG   msg;
  86.  
  87.   if (!hPrevInstance) {
  88.     if (!InitApplication(hInstance))
  89.       return FALSE;
  90.   }
  91.  
  92.   if (!InitInstance(hInstance,cmdShow))
  93.     return FALSE;
  94.  
  95.   while (GetMessage((LPMSG)&msg, NULL, 0, 0)) {
  96.     if (TranslateAccelerator(hWindow, hAccelTable, (LPMSG)&msg) == 0) {
  97.       TranslateMessage((LPMSG)&msg);
  98.       DispatchMessage((LPMSG)&msg);
  99.     }
  100.   }
  101.   return(msg.wParam);
  102. }
  103.  
  104.  
  105. /*-------------------------------------------------------------------*/
  106. /* Window message processor                                          */
  107. /*-------------------------------------------------------------------*/
  108.  
  109. long FAR PASCAL WinProc(hWnd, message, wParam, lParam)
  110. HWND hWnd;
  111. unsigned message;
  112. WORD wParam;
  113. LONG lParam;
  114. {
  115.   switch (message) {
  116.  
  117.     case WM_INITMENU:
  118.       if (wParam == GetMenu(hWnd)) {
  119.         if (OpenClipboard(hWnd)) {
  120.           if (IsClipboardFormatAvailable(CF_TEXT)
  121.             || IsClipboardFormatAvailable(CF_OEMTEXT))
  122.             EnableMenuItem(wParam, IDM_PASTE, MF_ENABLED);
  123.           else
  124.             EnableMenuItem(wParam, IDM_PASTE, MF_GRAYED);
  125.           CloseClipboard();
  126.           return(TRUE);
  127.         }
  128.         else                           /* Clipboard is not available */
  129.           return(FALSE);
  130.       }
  131.       return(TRUE);
  132.  
  133.     case WM_SETFOCUS:
  134.     case WM_SIZE:
  135.       return(EditProc(hWnd, message, wParam, lParam));
  136.  
  137.     case WM_QUERYENDSESSION:
  138.       return(FileQuerySave(hWnd));
  139.  
  140.     case WM_CLOSE:
  141.       if (FileQuerySave(hWnd))
  142.         DestroyWindow(hWnd);
  143.       break;
  144.  
  145.     case WM_DESTROY:
  146.       if (SndState.open) {
  147.         CloseSound();
  148.         SndState.open = 0;
  149.       }
  150.       PostQuitMessage(0);
  151.       break;
  152.  
  153.     case WM_COMMAND:
  154.       WinMenuCommand(hWnd, wParam);
  155.       break;
  156.  
  157.     default:
  158.       return(DefWindowProc(hWnd, message, wParam, lParam));
  159.     }
  160.  
  161.   return(0L);
  162. }
  163.  
  164. /*-------------------------------------------------------------------*/
  165. /* Window command processor                                          */
  166. /*-------------------------------------------------------------------*/
  167.  
  168. void WinMenuCommand(hWnd, id)
  169. HWND hWnd;
  170. int id;
  171. {
  172.   LPSTR lpszText;
  173.  
  174.   switch (id) {
  175.  
  176.     /* file menu commands */
  177.     case IDM_NEW:
  178.       FileNew(hWnd);
  179.       break;
  180.  
  181.     case IDM_OPEN:
  182.       FileOpen(hWnd);
  183.       break;
  184.  
  185.     case IDM_SAVE:
  186.       FileSave(hWnd);
  187.       break;
  188.  
  189.     case IDM_SAVEAS:
  190.       FileSaveAs(hWnd);
  191.       break;
  192.  
  193.     case IDM_EXIT:
  194.       if (FileQuerySave(hWnd))
  195.         DestroyWindow(hWnd);
  196.       break;
  197.  
  198.  
  199.     /* edit menu commands */
  200.     case IDM_UNDO:
  201.     case IDM_CLEAR:
  202.     case IDM_CUT:
  203.     case IDM_COPY:
  204.     case IDM_PASTE:
  205.       EditMenuCommand(hWnd,id);
  206.       break;
  207.  
  208.     /* Paste function menu commands */
  209.     case IDM_CLOSESOUND:
  210.     case IDM_COUNTVOICENOTES:
  211.     case IDM_GETTHRESHOLDEVENT:
  212.     case IDM_GETTHRESHOLDSTATUS:
  213.     case IDM_OPENSOUND:
  214.     case IDM_SETSOUNDNOISE:
  215.     case IDM_SETVOICEACCENT:
  216.     case IDM_SETVOICEENVELOPE:
  217.     case IDM_SETVOICENOTE:
  218.     case IDM_SETVOICEQUEUESIZE:
  219.     case IDM_SETVOICESOUND:
  220.     case IDM_SETVOICETHRESHOLD:
  221.     case IDM_STARTSOUND:
  222.     case IDM_STOPSOUND:
  223.     case IDM_SYNCALLVOICES:
  224.     case IDM_WAITSOUNDSTATE:
  225.       PasteMenuCommand(hWnd,id);
  226.       break;
  227.  
  228.     /* play menu commands */
  229.     case IDM_PLAY:
  230.       Play();
  231.       break;
  232.  
  233.     /* help menu commands */
  234.     case IDM_HELP_INDEX:
  235.       WinHelp(hWnd,HelpFileName,HELP_INDEX,0L);
  236.       break;
  237.  
  238.     case IDM_HELP_FUNCTIONS:
  239.       WinHelp(hWnd,HelpFileName,HELP_KEY,(DWORD)(LPSTR)"Sound Functions");
  240.       break;
  241.  
  242.     case IDM_HELP_HELP:
  243.       WinHelp(hWnd,"",HELP_HELPONHELP,0L);
  244.       break;
  245.  
  246.     case IDM_ABOUT:
  247.       GoDialogBox(hInst, "About", hWnd, About);
  248.       break;
  249.  
  250.     default:
  251.       break;
  252.   }
  253. }
  254.  
  255. /*-------------------------------------------------------------------*/
  256. /* Create a dialog box and let a callback function handle messages.  */
  257. /*-------------------------------------------------------------------*/
  258.  
  259. int GoDialogBox(hInstance, lpTemplateName, hWndParent, lpProc)
  260. HANDLE hInstance;
  261. LPSTR lpTemplateName;
  262. HWND hWndParent;
  263. FARPROC lpProc;
  264. {
  265.   int     nResult;
  266.   FARPROC lpDialog;
  267.  
  268.   lpDialog = MakeProcInstance(lpProc, hInstance);
  269.   nResult = DialogBox(hInstance, lpTemplateName, hWndParent, lpDialog);
  270.   FreeProcInstance(lpDialog);
  271.  
  272.   return(nResult);
  273. }
  274.  
  275.  
  276. /*-------------------------------------------------------------------*/
  277. /* About dialog box callback function.                               */
  278. /*-------------------------------------------------------------------*/
  279.  
  280. BOOL FAR PASCAL About( hDlg, message, wParam, lParam )
  281. HWND hDlg;
  282. unsigned message;
  283. WORD wParam;
  284. LONG lParam;
  285. {
  286.   if (message == WM_COMMAND) {
  287.     EndDialog( hDlg, TRUE );
  288.     return TRUE;
  289.   }
  290.   else if (message == WM_INITDIALOG) {
  291.     return TRUE;
  292.   }
  293.   else return FALSE;
  294. }
  295.  
  296.  
  297. /**********************************************************************/
  298. /* Local functions                                                    */
  299. /**********************************************************************/
  300.  
  301. void OutOfMemory(void)
  302. {
  303.   MessageBox(
  304.     GetFocus(),
  305.     "Out of Memory",
  306.     NULL,
  307.     MB_ICONHAND | MB_SYSTEMMODAL);
  308.   return;
  309. }
  310.  
  311.