home *** CD-ROM | disk | FTP | other *** search
/ Sound, Music & MIDI Collection 2 / SMMVOL2.bin / WIN / WIN_MISC / MODLIB01.ZIP / C / SAMPLE.C < prev    next >
Encoding:
C/C++ Source or Header  |  1995-08-11  |  8.5 KB  |  319 lines

  1. //*******************************************************************
  2. //
  3. // program - sample.c
  4. // purpose - a C windows program to demonstrate MODLIB APIs in Win 3.1
  5. //
  6. //*******************************************************************
  7.  
  8. #define STRICT
  9.  
  10. #include <windows.h>
  11. #pragma hdrstop
  12. //#include <mmsystem.h>
  13. #include <windowsx.h>
  14.  
  15. #include "sample.h"
  16. #include "modlib.h"
  17.  
  18. // data initialized by first instance
  19. typedef struct tagSETUPDATA
  20.   {
  21.      char   szAppName[20]; // name of application
  22.   } SETUPDATA;
  23.  
  24. SETUPDATA SetUpData;
  25.  
  26. // Data that can be referenced throughout the
  27. // program but not passed to other instances
  28.  
  29. HANDLE    hInst;                              // hInstance of application
  30. HWND      hWndMain;                           // hWnd of main window
  31. char      szAppName[10];                      // name of application
  32.  
  33. // channels ON / OFF
  34. char         C1 = 1;
  35. char         C2 = 1;
  36. char         C3 = 1;
  37. char         C4 = 1;
  38.  
  39. HWND         WC1;
  40. HWND         WC2;
  41. HWND         WC3;
  42. HWND         WC4;
  43.  
  44. // function prototypes
  45.  
  46. int      PASCAL        WinMain(HINSTANCE,HINSTANCE,LPSTR,int);
  47. void                   InitApp(HINSTANCE,HINSTANCE,LPSTR,int);
  48. void                   InitAppFirst(HINSTANCE, int);
  49.  
  50. LRESULT CALLBACK _export AppWndProc(HWND,UINT,WPARAM,LPARAM) ;
  51.  
  52.  
  53.  
  54. //*******************************************************************
  55. // WinMain - sample main
  56. //
  57. // paramaters:
  58. //             hInstance     - The instance of this instance of this
  59. //                             application.
  60. //             hPrevInstance - The instance of the previous instance
  61. //                             of this application. This will be 0
  62. //                             if this is the first instance.
  63. //             lpszCmdLine   - A long pointer to the command line that
  64. //                             started this application.
  65. //             cmdShow       - Indicates how the window is to be shown
  66. //                             initially. ie. SW_SHOWNORMAL, SW_HIDE,
  67. //                             SW_MIMIMIZE.
  68. //
  69. // returns:
  70. //             wParam from last message.
  71. //
  72. //*******************************************************************
  73. int PASCAL WinMain(
  74. HINSTANCE hInstance,
  75. HINSTANCE hPrevInstance,
  76. LPSTR lpszCmdLine,
  77. int cmdShow)
  78. {
  79.      MSG   msg;
  80.  
  81.      // Go init this application.
  82.      InitApp(hInstance, hPrevInstance, lpszCmdLine, cmdShow);
  83.  
  84.      // Get and dispatch messages for this applicaton.
  85.      while (GetMessage(&msg, NULL, 0, 0))
  86.      {
  87.           TranslateMessage(&msg);
  88.           DispatchMessage(&msg);
  89.      }
  90.  
  91.      return(msg.wParam);
  92. }
  93.  
  94.  
  95. #pragma argsused
  96. void InitApp(
  97. HINSTANCE hInstance,
  98. HINSTANCE hPrevInstance,
  99. LPSTR lpszCmdLine,
  100. int cmdShow)
  101. {
  102.      if (! hPrevInstance)           // if no previous instance, this is first
  103.           InitAppFirst(hInstance, cmdShow) ;
  104. }
  105.  
  106. void InitAppFirst(
  107. HINSTANCE hInstance,
  108. int cmdShow)
  109. {
  110.      WNDCLASS wcMyAppClass ;
  111.  
  112.      // Get string from resource with application name.
  113.      LoadString(hInstance, IDS_NAME, (LPSTR) SetUpData.szAppName, 10) ;
  114.  
  115.      // Define the window class for this application.
  116.      wcMyAppClass.lpszClassName = SetUpData.szAppName ;
  117.      wcMyAppClass.hInstance     = hInstance ;
  118.      wcMyAppClass.lpfnWndProc   = AppWndProc ;
  119.      wcMyAppClass.hCursor       = LoadCursor(NULL, IDC_ARROW) ;
  120.      wcMyAppClass.hIcon         = LoadIcon(hInstance, SetUpData.szAppName) ;
  121.      wcMyAppClass.lpszMenuName  = NULL ;
  122.      wcMyAppClass.hbrBackground = GetStockObject(WHITE_BRUSH) ;
  123.      wcMyAppClass.style         = CS_HREDRAW | CS_VREDRAW ;
  124.      wcMyAppClass.cbClsExtra    = 0 ;
  125.      wcMyAppClass.cbWndExtra    = 0 ;
  126.  
  127.      // Register the class
  128.      RegisterClass(&wcMyAppClass);
  129.  
  130.      hInst = hInstance;       // save for use by window procs
  131.  
  132.      // Create applications main window.
  133.      hWndMain = CreateWindow(
  134.                         SetUpData.szAppName,     // window class name
  135.                         SetUpData.szAppName,     // window title
  136.                         WS_OVERLAPPEDWINDOW,     // type of window
  137.                         100,                      // x  window location
  138.                         100,                     // y
  139.                         450,                      // cx and size
  140.                         250,                     // cy
  141.                         NULL,                    // no parent for this window
  142.                         NULL,                    // use the class menu
  143.                         hInstance,               // who created this window
  144.                         NULL                     // no parms to pass on
  145.                         );
  146.  
  147.      // Update display of main window.
  148.      ShowWindow(hWndMain, cmdShow);
  149.      UpdateWindow(hWndMain);
  150. }
  151.  
  152.  
  153. //*******************************************************************
  154. // AppWndProc - handles messages for this application
  155. //
  156. // paramaters:
  157. //             hWnd          - The window handle for this message
  158. //             message       - The message number
  159. //             wParam        - The WPARAM parmater for this message
  160. //             lParam        - The LPARAM parmater for this message
  161. //
  162. // returns:
  163. //             depends on message.
  164. //
  165. //*******************************************************************
  166. LRESULT CALLBACK _export AppWndProc(
  167. HWND hWnd,
  168. UINT message,
  169. WPARAM wParam,
  170. LPARAM lParam)
  171. {
  172.      HDC hdc;
  173.  
  174.      switch (message)
  175.      {
  176.           case WM_CREATE:
  177.                 CreateWindow ("button", "&Play",
  178.                                   WS_CHILD| WS_VISIBLE| BS_PUSHBUTTON,
  179.                                   20, 40, 120, 30,
  180.                                   hWnd, (HMENU)IDBT_PLAY, hInst, NULL);
  181.  
  182.                 CreateWindow ("button", "&Stop",
  183.                                   WS_CHILD| WS_VISIBLE| BS_PUSHBUTTON,
  184.                                   20, 80, 120, 30,
  185.                                   hWnd, (HMENU)IDBT_STOP, hInst, NULL);
  186.  
  187.                 CreateWindow ("button", "&Decrease Vol",
  188.                                   WS_CHILD| WS_VISIBLE| BS_PUSHBUTTON,
  189.                                   20, 120, 120, 30,
  190.                                   hWnd, (HMENU)IDBT_DECVOL, hInst, NULL);
  191.  
  192.                 CreateWindow ("button", "&Increase Vol",
  193.                                   WS_CHILD| WS_VISIBLE| BS_PUSHBUTTON,
  194.                                   20, 160, 120, 30,
  195.                                   hWnd, (HMENU)IDBT_INCVOL, hInst, NULL);
  196.  
  197.                 WC1 = CreateWindow ("button", "Channel &1 ON",
  198.                                   WS_CHILD| WS_VISIBLE| BS_PUSHBUTTON,
  199.                                   160, 40, 120, 30,
  200.                                   hWnd, (HMENU)IDBT_C1, hInst, NULL);
  201.  
  202.                 WC2 = CreateWindow ("button", "Channel &2 ON",
  203.                                   WS_CHILD| WS_VISIBLE| BS_PUSHBUTTON,
  204.                                   160, 80, 120, 30,
  205.                                   hWnd, (HMENU)IDBT_C2, hInst, NULL);
  206.  
  207.                 WC3 = CreateWindow ("button", "Channel &3 ON",
  208.                                   WS_CHILD| WS_VISIBLE| BS_PUSHBUTTON,
  209.                                   160, 120, 120, 30,
  210.                                   hWnd, (HMENU)IDBT_C3, hInst, NULL);
  211.  
  212.                 WC4 = CreateWindow ("button", "Channel &4 ON",
  213.                                   WS_CHILD| WS_VISIBLE| BS_PUSHBUTTON,
  214.                                   160, 160, 120, 30,
  215.                                   hWnd, (HMENU)IDBT_C4, hInst, NULL);
  216.  
  217.                 return(DefWindowProc(hWnd, message, wParam, lParam));
  218.  
  219.           case WM_COMMAND:
  220.                 hdc = GetDC (hWnd);
  221.                 ReleaseDC (hWnd, hdc);
  222.  
  223.                 switch (GET_WM_COMMAND_ID(wParam, lParam))
  224.                 {
  225.                      case IDBT_PLAY:
  226.                           MOD_start_playback("SPACE.MOD", 4) ;
  227.                           break ;
  228.  
  229.                      case IDBT_STOP:
  230.                           MOD_stop_playback() ;
  231.                           break ;
  232.  
  233.                      case IDBT_INCVOL:
  234.                           MOD_increase_volume(1000) ;
  235.                           break ;
  236.  
  237.                      case IDBT_DECVOL:
  238.                           MOD_decrease_volume(1000) ;
  239.                           break ;
  240.  
  241.                      case IDBT_C1:
  242.                           if(C1 == 1) {
  243.                              C1 = 0 ;
  244.                              MOD_close_channel(0) ;
  245.                              SetWindowText(WC1, "Channel &1 OFF") ;
  246.                           }
  247.                           else {
  248.                              C1 = 1 ;
  249.                              MOD_open_channel(0) ;
  250.                              SetWindowText(WC1, "Channel &1 ON") ;
  251.                           }
  252.  
  253.                           break ;
  254.  
  255.                      case IDBT_C2:
  256.                           if(C2 == 1) {
  257.                              C2 = 0 ;
  258.                              MOD_close_channel(1) ;
  259.                              SetWindowText(WC2, "Channel &2 OFF") ;
  260.                           }
  261.                           else {
  262.                              C2 = 1 ;
  263.                              MOD_open_channel(1) ;
  264.                              SetWindowText(WC2, "Channel &2 ON") ;
  265.                           }
  266.  
  267.                           break ;
  268.  
  269.  
  270.                      case IDBT_C3:
  271.                           if(C3 == 1) {
  272.                              C3 = 0 ;
  273.                              MOD_close_channel(2) ;
  274.                              SetWindowText(WC3, "Channel &3 OFF") ;
  275.                           }
  276.                           else {
  277.                              C3 = 1 ;
  278.                              MOD_open_channel(2) ;
  279.                              SetWindowText(WC3, "Channel &3 ON") ;
  280.                           }
  281.  
  282.                           break ;
  283.  
  284.                      case IDBT_C4:
  285.                           if(C4 == 1) {
  286.                              C4 = 0 ;
  287.                              MOD_close_channel(3) ;
  288.                              SetWindowText(WC4, "Channel &4 OFF") ;
  289.                           }
  290.                           else {
  291.                              C4 = 1 ;
  292.                              MOD_open_channel(3) ;
  293.                              SetWindowText(WC4, "Channel &1 ON") ;
  294.                           }
  295.  
  296.                           break ;
  297.  
  298.  
  299.                      default:
  300.                           break;
  301.                 }
  302.              break;
  303.  
  304.           case WM_DESTROY:
  305.                 PostQuitMessage(0);   // this is the end...
  306.                 break;
  307.  
  308.           case WM_CLOSE:
  309.                 // Tell windows to destroy our window.
  310.                 DestroyWindow(hWnd);
  311.                 break;
  312.  
  313.           default:
  314.              // Let windows handle all messages we choose to ignore.
  315.              return(DefWindowProc(hWnd, message, wParam, lParam));
  316.      }
  317.      return(0L);
  318. }
  319.