home *** CD-ROM | disk | FTP | other *** search
- //*******************************************************************
- //
- // program - sample.c
- // purpose - a C windows program to demonstrate MODLIB APIs in Win 3.1
- //
- //*******************************************************************
-
- #define STRICT
-
- #include <windows.h>
- #pragma hdrstop
- //#include <mmsystem.h>
- #include <windowsx.h>
-
- #include "sample.h"
- #include "modlib.h"
-
- // data initialized by first instance
- typedef struct tagSETUPDATA
- {
- char szAppName[20]; // name of application
- } SETUPDATA;
-
- SETUPDATA SetUpData;
-
- // Data that can be referenced throughout the
- // program but not passed to other instances
-
- HANDLE hInst; // hInstance of application
- HWND hWndMain; // hWnd of main window
- char szAppName[10]; // name of application
-
- // channels ON / OFF
- char C1 = 1;
- char C2 = 1;
- char C3 = 1;
- char C4 = 1;
-
- HWND WC1;
- HWND WC2;
- HWND WC3;
- HWND WC4;
-
- // function prototypes
-
- int PASCAL WinMain(HINSTANCE,HINSTANCE,LPSTR,int);
- void InitApp(HINSTANCE,HINSTANCE,LPSTR,int);
- void InitAppFirst(HINSTANCE, int);
-
- LRESULT CALLBACK _export AppWndProc(HWND,UINT,WPARAM,LPARAM) ;
-
-
-
- //*******************************************************************
- // WinMain - sample main
- //
- // paramaters:
- // hInstance - The instance of this instance of this
- // application.
- // hPrevInstance - The instance of the previous instance
- // of this application. This will be 0
- // if this is the first instance.
- // lpszCmdLine - A long pointer to the command line that
- // started this application.
- // cmdShow - Indicates how the window is to be shown
- // initially. ie. SW_SHOWNORMAL, SW_HIDE,
- // SW_MIMIMIZE.
- //
- // returns:
- // wParam from last message.
- //
- //*******************************************************************
- int PASCAL WinMain(
- HINSTANCE hInstance,
- HINSTANCE hPrevInstance,
- LPSTR lpszCmdLine,
- int cmdShow)
- {
- MSG msg;
-
- // Go init this application.
- InitApp(hInstance, hPrevInstance, lpszCmdLine, cmdShow);
-
- // Get and dispatch messages for this applicaton.
- while (GetMessage(&msg, NULL, 0, 0))
- {
- TranslateMessage(&msg);
- DispatchMessage(&msg);
- }
-
- return(msg.wParam);
- }
-
-
- #pragma argsused
- void InitApp(
- HINSTANCE hInstance,
- HINSTANCE hPrevInstance,
- LPSTR lpszCmdLine,
- int cmdShow)
- {
- if (! hPrevInstance) // if no previous instance, this is first
- InitAppFirst(hInstance, cmdShow) ;
- }
-
- void InitAppFirst(
- HINSTANCE hInstance,
- int cmdShow)
- {
- WNDCLASS wcMyAppClass ;
-
- // Get string from resource with application name.
- LoadString(hInstance, IDS_NAME, (LPSTR) SetUpData.szAppName, 10) ;
-
- // Define the window class for this application.
- wcMyAppClass.lpszClassName = SetUpData.szAppName ;
- wcMyAppClass.hInstance = hInstance ;
- wcMyAppClass.lpfnWndProc = AppWndProc ;
- wcMyAppClass.hCursor = LoadCursor(NULL, IDC_ARROW) ;
- wcMyAppClass.hIcon = LoadIcon(hInstance, SetUpData.szAppName) ;
- wcMyAppClass.lpszMenuName = NULL ;
- wcMyAppClass.hbrBackground = GetStockObject(WHITE_BRUSH) ;
- wcMyAppClass.style = CS_HREDRAW | CS_VREDRAW ;
- wcMyAppClass.cbClsExtra = 0 ;
- wcMyAppClass.cbWndExtra = 0 ;
-
- // Register the class
- RegisterClass(&wcMyAppClass);
-
- hInst = hInstance; // save for use by window procs
-
- // Create applications main window.
- hWndMain = CreateWindow(
- SetUpData.szAppName, // window class name
- SetUpData.szAppName, // window title
- WS_OVERLAPPEDWINDOW, // type of window
- 100, // x window location
- 100, // y
- 450, // cx and size
- 250, // cy
- NULL, // no parent for this window
- NULL, // use the class menu
- hInstance, // who created this window
- NULL // no parms to pass on
- );
-
- // Update display of main window.
- ShowWindow(hWndMain, cmdShow);
- UpdateWindow(hWndMain);
- }
-
-
- //*******************************************************************
- // AppWndProc - handles messages for this application
- //
- // paramaters:
- // hWnd - The window handle for this message
- // message - The message number
- // wParam - The WPARAM parmater for this message
- // lParam - The LPARAM parmater for this message
- //
- // returns:
- // depends on message.
- //
- //*******************************************************************
- LRESULT CALLBACK _export AppWndProc(
- HWND hWnd,
- UINT message,
- WPARAM wParam,
- LPARAM lParam)
- {
- HDC hdc;
-
- switch (message)
- {
- case WM_CREATE:
- CreateWindow ("button", "&Play",
- WS_CHILD| WS_VISIBLE| BS_PUSHBUTTON,
- 20, 40, 120, 30,
- hWnd, (HMENU)IDBT_PLAY, hInst, NULL);
-
- CreateWindow ("button", "&Stop",
- WS_CHILD| WS_VISIBLE| BS_PUSHBUTTON,
- 20, 80, 120, 30,
- hWnd, (HMENU)IDBT_STOP, hInst, NULL);
-
- CreateWindow ("button", "&Decrease Vol",
- WS_CHILD| WS_VISIBLE| BS_PUSHBUTTON,
- 20, 120, 120, 30,
- hWnd, (HMENU)IDBT_DECVOL, hInst, NULL);
-
- CreateWindow ("button", "&Increase Vol",
- WS_CHILD| WS_VISIBLE| BS_PUSHBUTTON,
- 20, 160, 120, 30,
- hWnd, (HMENU)IDBT_INCVOL, hInst, NULL);
-
- WC1 = CreateWindow ("button", "Channel &1 ON",
- WS_CHILD| WS_VISIBLE| BS_PUSHBUTTON,
- 160, 40, 120, 30,
- hWnd, (HMENU)IDBT_C1, hInst, NULL);
-
- WC2 = CreateWindow ("button", "Channel &2 ON",
- WS_CHILD| WS_VISIBLE| BS_PUSHBUTTON,
- 160, 80, 120, 30,
- hWnd, (HMENU)IDBT_C2, hInst, NULL);
-
- WC3 = CreateWindow ("button", "Channel &3 ON",
- WS_CHILD| WS_VISIBLE| BS_PUSHBUTTON,
- 160, 120, 120, 30,
- hWnd, (HMENU)IDBT_C3, hInst, NULL);
-
- WC4 = CreateWindow ("button", "Channel &4 ON",
- WS_CHILD| WS_VISIBLE| BS_PUSHBUTTON,
- 160, 160, 120, 30,
- hWnd, (HMENU)IDBT_C4, hInst, NULL);
-
- return(DefWindowProc(hWnd, message, wParam, lParam));
-
- case WM_COMMAND:
- hdc = GetDC (hWnd);
- ReleaseDC (hWnd, hdc);
-
- switch (GET_WM_COMMAND_ID(wParam, lParam))
- {
- case IDBT_PLAY:
- MOD_start_playback("SPACE.MOD", 4) ;
- break ;
-
- case IDBT_STOP:
- MOD_stop_playback() ;
- break ;
-
- case IDBT_INCVOL:
- MOD_increase_volume(1000) ;
- break ;
-
- case IDBT_DECVOL:
- MOD_decrease_volume(1000) ;
- break ;
-
- case IDBT_C1:
- if(C1 == 1) {
- C1 = 0 ;
- MOD_close_channel(0) ;
- SetWindowText(WC1, "Channel &1 OFF") ;
- }
- else {
- C1 = 1 ;
- MOD_open_channel(0) ;
- SetWindowText(WC1, "Channel &1 ON") ;
- }
-
- break ;
-
- case IDBT_C2:
- if(C2 == 1) {
- C2 = 0 ;
- MOD_close_channel(1) ;
- SetWindowText(WC2, "Channel &2 OFF") ;
- }
- else {
- C2 = 1 ;
- MOD_open_channel(1) ;
- SetWindowText(WC2, "Channel &2 ON") ;
- }
-
- break ;
-
-
- case IDBT_C3:
- if(C3 == 1) {
- C3 = 0 ;
- MOD_close_channel(2) ;
- SetWindowText(WC3, "Channel &3 OFF") ;
- }
- else {
- C3 = 1 ;
- MOD_open_channel(2) ;
- SetWindowText(WC3, "Channel &3 ON") ;
- }
-
- break ;
-
- case IDBT_C4:
- if(C4 == 1) {
- C4 = 0 ;
- MOD_close_channel(3) ;
- SetWindowText(WC4, "Channel &4 OFF") ;
- }
- else {
- C4 = 1 ;
- MOD_open_channel(3) ;
- SetWindowText(WC4, "Channel &1 ON") ;
- }
-
- break ;
-
-
- default:
- break;
- }
- break;
-
- case WM_DESTROY:
- PostQuitMessage(0); // this is the end...
- break;
-
- case WM_CLOSE:
- // Tell windows to destroy our window.
- DestroyWindow(hWnd);
- break;
-
- default:
- // Let windows handle all messages we choose to ignore.
- return(DefWindowProc(hWnd, message, wParam, lParam));
- }
- return(0L);
- }
-