home *** CD-ROM | disk | FTP | other *** search
/ Prima Shareware 3 / DuCom_Prima-Shareware-3_cd1.bin / PROGRAMO / C / APPSR / APPPLAY / APPPLAY.C next >
Encoding:
C/C++ Source or Header  |  1993-05-02  |  5.3 KB  |  182 lines

  1. /*-------------------------------------------------------------------------
  2.  AppPlay.c
  3.  
  4.  A Wave file Player for AppBar.
  5.  
  6.  by
  7.  GMP van kempen
  8.  NEVERnever Software 1993
  9.  
  10. History:
  11.  
  12. 4.00.1 Initial release
  13. 4.00.2 Added change Button, improved looks
  14. 4.00.3 Made "OK" button default push button. Improved handling of
  15.        the commandline.
  16.  
  17. ---------------------------------------------------------------------------*/
  18. //compile with the strictest error checking
  19. #define STRICT
  20. #include <windows.h>
  21. #include <windowsx.h>
  22. #include <mmsystem.h>
  23. #include <shellapi.h>
  24. #include <ctl3d.h>
  25. #include <stdio.h>
  26. #include <string.h>
  27. #include "appplay.h"
  28.  
  29. #define MAKECHILD(a,b,c,d,e,f,g,h) CreateWindow(a,b,WS_CHILD | WS_VISIBLE | c,d,e,f,g,hWnd,h,hInst,(LPSTR) NULL)
  30. #define MAKEBUTTON(a,b,c,d,e,f)    MAKECHILD("button",a,BS_PUSHBUTTON,b,c,d,e,f)
  31. #define MAKEDEFBUTTON(a,b,c,d,e,f) MAKECHILD("button",a,BS_DEFPUSHBUTTON,b,c,d,e,f)
  32. #define MAKETEXT(a,b,c,d,e)       MAKECHILD("static",a,SS_LEFT,b,c,d,e,(HMENU) -1)
  33. #define MAKESTATIC(a,b,c,d)       MAKECHILD("static",NULL,SS_BLACKRECT,a,b,c,d,(HMENU) -1)
  34. #define MAKEBORDER(a,b,c,d)       MAKECHILD("static",NULL,SS_WHITERECT,a,b,c,d,(HMENU) -1)
  35.  
  36. char        szAppName[] = "AppPlay";
  37. HINSTANCE   hInst;
  38.  
  39. int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
  40.            LPSTR lpszCmdLine, int nCmdShow)
  41.     {
  42.     HWND    hWnd;
  43.     MSG     msg;
  44.     WNDCLASS    wndclass;
  45.     int     xScreen, yScreen, yCaption, xSize, ySize;
  46.  
  47.     lstrcpy(szBuffer, lpszCmdLine);
  48.     if(strlen(szBuffer))
  49.     {
  50.     sndPlaySound(szBuffer, SND_ASYNC | SND_NODEFAULT);
  51.     return msg.wParam;
  52.     }
  53.  
  54.     if(!hPrevInstance)
  55.     {
  56.     wndclass.style            = NULL;
  57.     wndclass.lpfnWndProc        = WndProc;
  58.     wndclass.cbClsExtra        = 0;
  59.     wndclass.cbWndExtra        = 0;
  60.     wndclass.hInstance        = hInstance;
  61.     wndclass.hIcon            = LoadIcon(hInstance, szAppName);
  62.     wndclass.hCursor        = LoadCursor(NULL, IDC_ARROW);
  63.     wndclass.hbrBackground        = GetStockBrush(LTGRAY_BRUSH);
  64.     wndclass.lpszMenuName        = NULL;
  65.     wndclass.lpszClassName        = szAppName;
  66.  
  67.     RegisterClass(&wndclass);
  68.     }
  69.  
  70.     hInst = hInstance;
  71.  
  72.     xScreen = GetSystemMetrics(SM_CXSCREEN);
  73.     yScreen = GetSystemMetrics(SM_CYSCREEN);
  74.     yCaption = GetSystemMetrics(SM_CYCAPTION);
  75.  
  76.     Ctl3dRegister(hInstance);
  77.  
  78.     xSize = 260;
  79.     ySize = 123 + yCaption;
  80.  
  81.     hWnd = CreateWindow(szAppName, "AppPlay 4.0",
  82.             WS_POPUP | WS_SYSMENU | WS_CAPTION |
  83.             WS_MINIMIZEBOX | WS_VISIBLE,
  84.             (xScreen - xSize)/2, yScreen/2 - ySize,
  85.             xSize, ySize,
  86.             NULL, (HMENU) NULL, hInstance, NULL);
  87.  
  88.     ShowWindow(hWnd, SW_SHOWNORMAL);
  89.     UpdateWindow(hWnd);
  90.  
  91.     while(GetMessage(&msg, NULL, 0, 0))
  92.     {
  93.     TranslateMessage(&msg);
  94.     DispatchMessage(&msg);
  95.     }
  96.  
  97.     Ctl3dUnregister(hInstance);
  98.  
  99.     return msg.wParam;
  100.     } /* end WinMain */
  101.  
  102. /*------------------------------------------------------------------------/
  103.    FUNCTION: WndProc()
  104. /------------------------------------------------------------------------*/
  105. long WINAPI WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
  106.     {
  107.     char *Button[3] = {"&Help","&OK","&Change"};
  108.     char Text[2][256];
  109.     int i, DroppedFiles;
  110.     HBRUSH hbrush;
  111.     HWND hWndButton[3];
  112.  
  113.     switch (message)
  114.     {
  115.     case WM_CREATE:
  116.         // create static frame around text fields
  117.         Ctl3dSubclassCtl(MAKEBORDER(0, 0, 258, 122));
  118.         Ctl3dSubclassCtl(MAKESTATIC(9, 9, 242, 72));
  119.         strcpy(Text[0], "A Wavefile play utility for AppBar");
  120.         GetPrivateProfileString("drivers","Wave", "<none>",
  121.                     szBuffer, 255, "system.ini");
  122.         sprintf(Text[1], "Current sound driver: %s",szBuffer);
  123.         hWndButton[0] = MAKEBUTTON(Button[0], 10, 90, 80, 24, IDC_BUTTONS);
  124.         hWndButton[1] = MAKEDEFBUTTON(Button[1], 10+80, 90, 80, 24, IDC_BUTTONS+1);
  125.         hWndButton[2] = MAKEBUTTON(Button[2], 10+160, 90, 80, 24, IDC_BUTTONS+2);
  126.         for(i=0;i<2;i++)
  127.         MAKETEXT(Text[i], 16, 16+i*22, 230, 20);
  128.         DragAcceptFiles(hWnd, TRUE);
  129.         return 0;
  130.  
  131.     case WM_SYSCOLORCHANGE:
  132.            Ctl3dColorChange();
  133.        break;
  134.  
  135.     case WM_CTLCOLOR:
  136.         hbrush = Ctl3dCtlColorEx(message, wParam, lParam);
  137.         if(hbrush != (HBRUSH) FALSE)
  138.         return hbrush;
  139.         else
  140.         return DefWindowProc(hWnd, message, wParam, lParam);
  141.  
  142.        case WM_KEYDOWN:
  143.         if(wParam == VK_RETURN)
  144.         SendMessage(hWnd, WM_COMMAND, IDC_BUTTONS+1, 0);
  145.         return 0;
  146.  
  147.        case WM_DROPFILES:
  148.         DroppedFiles = DragQueryFile((HANDLE) wParam, 0xFFFF, (LPSTR) NULL, 0);
  149.         for(i=0;i<DroppedFiles;i++)
  150.             {
  151.             DragQueryFile((HANDLE) wParam, i, szBuffer, sizeof(szBuffer));
  152.             sndPlaySound(szBuffer, SND_ASYNC | SND_NODEFAULT);
  153.             }
  154.         DragFinish((HANDLE) wParam);
  155.         return 0;
  156.  
  157.        case WM_COMMAND:
  158.         switch(wParam)
  159.         {
  160.         case IDC_BUTTONS: /* help */
  161.             WinHelp(hWnd, "AppTools.hlp",HELP_CONTENTS, 0L);
  162.             break;
  163.  
  164.         case IDC_BUTTONS+1:  /* Ok */
  165.             SendMessage(hWnd, WM_DESTROY, 0, 0);
  166.             break;
  167.  
  168.         case IDC_BUTTONS+2: /* Change */
  169.             WinExec("control.exe",SW_SHOWNORMAL);
  170.             SendMessage(hWnd, WM_DESTROY, 0, 0);
  171.             break;
  172.         }
  173.         break;
  174.  
  175.        case WM_DESTROY:    // kill the whole program
  176.         DragAcceptFiles(hWnd, FALSE);
  177.         PostQuitMessage(0);
  178.         return 0;
  179.     }
  180.     return DefWindowProc(hWnd, message, wParam, lParam);
  181.     } /* end WndProc */
  182.