home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / sdk / graphics / audio / mixapp / malines.c < prev    next >
C/C++ Source or Header  |  1997-10-05  |  16KB  |  521 lines

  1. //==========================================================================;
  2. //
  3. //  THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
  4. //  KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  5. //  IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR
  6. //  PURPOSE.
  7. //
  8. //  Copyright (C) 1993 - 1997  Microsoft Corporation.  All Rights Reserved.
  9. //
  10. //--------------------------------------------------------------------------;
  11. //
  12. //  malines.c
  13. //
  14. //  Description:
  15. //
  16. //
  17. //  History:
  18. //       9/21/93
  19. //
  20. //==========================================================================;
  21.  
  22. #include <windows.h>
  23. #include <windowsx.h>
  24. #include <mmsystem.h>
  25.  
  26. #include "mixapp.h"
  27.  
  28. #include "debug.h"
  29.  
  30.  
  31. TCHAR       gszLineFormatTitle[]        = TEXT("Type\t3!Component\t10!Line ID\t6!Flags\t6!Ctrls\t3!Conns\t3!Name");
  32. TCHAR       gszLineFormatList[]         = TEXT("%-s%c\t%-s\t%.08lXh\t%.08lXh\t%lu\t%lu\t%-s");
  33.  
  34.  
  35. //==========================================================================;
  36. //
  37. //
  38. //
  39. //
  40. //==========================================================================;
  41.  
  42. //--------------------------------------------------------------------------;
  43. //
  44. //  BOOL MixAppGetComponentName
  45. //
  46. //  Description:
  47. //
  48. //
  49. //  Arguments:
  50. //      LPMIXERLINE pmxl:
  51. //
  52. //      LPTSTR szComponent:
  53. //
  54. //  Return (BOOL):
  55. //
  56. //  History:
  57. //      08/18/93
  58. //
  59. //--------------------------------------------------------------------------;
  60.  
  61. BOOL FNLOCAL MixAppGetComponentName
  62. (
  63.     LPMIXERLINE             pmxl,
  64.     LPTSTR                  szComponent
  65. )
  66. {
  67.     //
  68.     //
  69.     //
  70.     if (0 == (MIXERLINE_LINEF_SOURCE & pmxl->fdwLine))
  71.     {
  72.         switch (pmxl->dwComponentType)
  73.         {
  74.             case MIXERLINE_COMPONENTTYPE_DST_UNDEFINED:
  75.                 lstrcpy(szComponent, "Undefined");
  76.                 break;
  77.  
  78.             case MIXERLINE_COMPONENTTYPE_DST_DIGITAL:
  79.                 lstrcpy(szComponent, "Digital");
  80.                 break;
  81.  
  82.             case MIXERLINE_COMPONENTTYPE_DST_LINE:
  83.                 lstrcpy(szComponent, "Line Level");
  84.                 break;
  85.  
  86.             case MIXERLINE_COMPONENTTYPE_DST_MONITOR:
  87.                 lstrcpy(szComponent, "Monitor");
  88.                 break;
  89.  
  90.             case MIXERLINE_COMPONENTTYPE_DST_SPEAKERS:
  91.                 lstrcpy(szComponent, "Speakers");
  92.                 break;
  93.  
  94.             case MIXERLINE_COMPONENTTYPE_DST_HEADPHONES:
  95.                 lstrcpy(szComponent, "Headphones");
  96.                 break;
  97.  
  98.             case MIXERLINE_COMPONENTTYPE_DST_TELEPHONE:
  99.                 lstrcpy(szComponent, "Telephone");
  100.                 break;
  101.  
  102.             case MIXERLINE_COMPONENTTYPE_DST_WAVEIN:
  103.                 lstrcpy(szComponent, "Wave Input");
  104.                 break;
  105.  
  106.             case MIXERLINE_COMPONENTTYPE_DST_VOICEIN:
  107.                 lstrcpy(szComponent, "Voice Recognition");
  108.                 break;
  109.  
  110.             default:
  111.                 lstrcpy(szComponent, "NOT VALID");
  112.                 break;
  113.         }
  114.     }
  115.     else
  116.     {
  117.         switch (pmxl->dwComponentType)
  118.         {
  119.             case MIXERLINE_COMPONENTTYPE_SRC_UNDEFINED:
  120.                 lstrcpy(szComponent, "Undefined");
  121.                 break;
  122.  
  123.             case MIXERLINE_COMPONENTTYPE_SRC_DIGITAL:
  124.                 lstrcpy(szComponent, "Digital");
  125.                 break;
  126.  
  127.             case MIXERLINE_COMPONENTTYPE_SRC_LINE:
  128.                 lstrcpy(szComponent, "Line Level");
  129.                 break;
  130.  
  131.             case MIXERLINE_COMPONENTTYPE_SRC_MICROPHONE:
  132.                 lstrcpy(szComponent, "Microphone");
  133.                 break;
  134.  
  135.             case MIXERLINE_COMPONENTTYPE_SRC_SYNTHESIZER:
  136.                 lstrcpy(szComponent, "Synthesizer");
  137.                 break;
  138.  
  139.             case MIXERLINE_COMPONENTTYPE_SRC_COMPACTDISC:
  140.                 lstrcpy(szComponent, "Compact Disc");
  141.                 break;
  142.  
  143.             case MIXERLINE_COMPONENTTYPE_SRC_TELEPHONE:
  144.                 lstrcpy(szComponent, "Telephone");
  145.                 break;
  146.  
  147.             case MIXERLINE_COMPONENTTYPE_SRC_PCSPEAKER:
  148.                 lstrcpy(szComponent, "PC Speaker");
  149.                 break;
  150.  
  151.             case MIXERLINE_COMPONENTTYPE_SRC_WAVEOUT:
  152.                 lstrcpy(szComponent, "Wave Out");
  153.                 break;
  154.  
  155.             case MIXERLINE_COMPONENTTYPE_SRC_AUXILIARY:
  156.                 lstrcpy(szComponent, "Auxiliary");
  157.                 break;
  158.  
  159.             case MIXERLINE_COMPONENTTYPE_SRC_ANALOG:
  160.                 lstrcpy(szComponent, "Analog");
  161.                 break;
  162.  
  163.             default:
  164.                 lstrcpy(szComponent, "NOT VALID");
  165.                 break;
  166.         }
  167.     }
  168.  
  169.     return (TRUE);
  170. } // MixAppGetComponentName()
  171.  
  172.  
  173. //--------------------------------------------------------------------------;
  174. //
  175. //  BOOL MixAppDlgProcLineInfo
  176. //
  177. //  Description:
  178. //      This dialog procedure is used to display driver capabilities.
  179. //
  180. //  Arguments:
  181. //      HWND hwnd: Handle to window.
  182. //
  183. //      UINT uMsg: Message being sent to the window.
  184. //
  185. //      WPARAM wParam: Specific argument to message.
  186. //
  187. //      LPARAM lParam: Specific argument to message.
  188. //
  189. //  Return (BOOL):
  190. //      The return value is specific to the message that was received. For
  191. //      the most part, it is FALSE if this dialog procedure does not handle
  192. //      a message.
  193. //
  194. //  History:
  195. //       1/ 2/93
  196. //
  197. //--------------------------------------------------------------------------;
  198.  
  199. BOOL CALLBACK MixAppDlgProcLineInfo
  200. (
  201.     HWND                    hwnd,
  202.     UINT                    uMsg,
  203.     WPARAM                  wParam,
  204.     LPARAM                  lParam
  205. )
  206. {
  207.     HWND                hedit;
  208.     UINT                u;
  209.     MIXERLINE           mxl;
  210.     MMRESULT            mmr;
  211.     TCHAR               ach[64];
  212.  
  213.     switch (uMsg)
  214.     {
  215.         case WM_INITDIALOG:
  216.             hedit = GetDlgItem(hwnd, IDD_LINEINFO_EDIT_INFO);
  217.             SetWindowFont(hedit, GetStockFont(SYSTEM_FIXED_FONT), FALSE);
  218.  
  219.             //
  220.             //
  221.             //
  222.             //
  223.             mxl.cbStruct      = sizeof(mxl);
  224.             mxl.dwLineID      = lParam;
  225.  
  226.             mmr = mixerGetLineInfo((HMIXEROBJ)ghmx, &mxl, MIXER_GETLINEINFOF_LINEID);
  227.             if (MMSYSERR_NOERROR != mmr)
  228.             {
  229.                 AppMsgBox(hwnd, MB_OK | MB_ICONEXCLAMATION,
  230.                           "mixerGetLineInfo(lineid=%.08lXh) failed on hmx=%.04Xh, mmr=%u!",
  231.                           lParam, ghmx, mmr);
  232.             }
  233.             else
  234.             {
  235.                 static TCHAR    szDisplayTitle[]  = TEXT("[Line Info]\r\n");
  236.  
  237.                 //
  238.                 //
  239.                 //
  240.                 MEditPrintF(hedit, NULL);
  241.                 MEditPrintF(hedit, szDisplayTitle);
  242.  
  243.                 MEditPrintF(hedit, "%25s: %.04Xh", (LPTSTR)"Mixer Handle", ghmx);
  244.  
  245.                 //
  246.                 //
  247.                 //
  248.                 MEditPrintF(hedit, "%25s: %lu bytes (requested %lu)", (LPTSTR)"Size of Line Info", mxl.cbStruct, (DWORD)sizeof(mxl));
  249.                 MEditPrintF(hedit, "%25s: %lu", (LPTSTR)"Destination", mxl.dwDestination);
  250.                 MEditPrintF(hedit, "%25s: %lu", (LPTSTR)"Source", mxl.dwSource);
  251.                 MEditPrintF(hedit, "%25s: %.08lXh", (LPTSTR)"Line ID", mxl.dwLineID);
  252.                 MEditPrintF(hedit, "~%25s: %.08lXh", (LPTSTR)"Line Flags", mxl.fdwLine);
  253.  
  254.                 if (MIXERLINE_LINEF_SOURCE & mxl.fdwLine)
  255.                     MEditPrintF(hedit, "~, source");
  256.                 else
  257.                     MEditPrintF(hedit, "~, destination");
  258.  
  259.                 if (MIXERLINE_LINEF_DISCONNECTED & mxl.fdwLine)
  260.                     MEditPrintF(hedit, "~, disconnected");
  261.  
  262.                 if (MIXERLINE_LINEF_ACTIVE & mxl.fdwLine)
  263.                     MEditPrintF(hedit, "~, active");
  264.  
  265.                 if (~(MIXERLINE_LINEF_SOURCE | MIXERLINE_LINEF_DISCONNECTED | MIXERLINE_LINEF_ACTIVE) & mxl.fdwLine)
  266.                     MEditPrintF(hedit, "~, *INVALID FLAGS*");
  267.  
  268.                 MEditPrintF(hedit, "");
  269.                 MEditPrintF(hedit, "%25s: %.08lXh", (LPTSTR)"Driver User DWord", mxl.dwUser);
  270.  
  271.                 MixAppGetComponentName(&mxl, ach);
  272.                 MEditPrintF(hedit, "%25s: %lu, (%s)", (LPTSTR)"Component Type", mxl.dwComponentType, (LPTSTR)ach);
  273.                 MEditPrintF(hedit, "%25s: %lu", (LPTSTR)"Num Channels", mxl.cChannels);
  274.                 MEditPrintF(hedit, "%25s: %lu", (LPTSTR)"Num Connections", mxl.cConnections);
  275.                 MEditPrintF(hedit, "%25s: %lu", (LPTSTR)"Num Controls", mxl.cControls);
  276.                 MEditPrintF(hedit, "%25s: '%s'", (LPTSTR)"Short Name", (LPTSTR)mxl.szShortName);
  277.                 MEditPrintF(hedit, "%25s: '%s'", (LPTSTR)"Name", (LPTSTR)mxl.szName);
  278.                 MEditPrintF(hedit, "\r\n%25s: %lu", (LPTSTR)"Target Type", mxl.Target.dwType);
  279.                 MEditPrintF(hedit, "%25s: %lu", (LPTSTR)"Device ID", mxl.Target.dwDeviceID);
  280.                 MEditPrintF(hedit, "%25s: %u", (LPTSTR)"Manufacturer ID", mxl.Target.wMid);
  281.                 MEditPrintF(hedit, "%25s: %u", (LPTSTR)"Product ID", mxl.Target.wPid);
  282.                 MEditPrintF(hedit, "%25s: %u.%.02u", (LPTSTR)"Version",
  283.                             mxl.Target.vDriverVersion >> 8,
  284.                             mxl.Target.vDriverVersion & 0x00FF);
  285.                 MEditPrintF(hedit, "%25s: '%s'", (LPTSTR)"Product Name", (LPTSTR)mxl.Target.szPname);
  286.             }
  287.  
  288.             //
  289.             //  return nonzero to set the input focus to the control
  290.             //  identified by the (hwndFocus = (HWND)wParam) argument.
  291.             //  a zero return tells the dialog manager that this function
  292.             //  has set the focus using SetFocus.
  293.             //
  294.             return (TRUE);
  295.  
  296.         case WM_COMMAND:
  297.             u = GET_WM_COMMAND_ID(wParam, lParam);
  298.             if ((IDOK == u) || (IDCANCEL == u))
  299.             {
  300.                 EndDialog(hwnd, (IDOK == u));
  301.             }
  302.             break;
  303.     }
  304.  
  305.     return (FALSE);
  306. } // MixAppDlgProcLineInfo()
  307.  
  308.  
  309. //--------------------------------------------------------------------------;
  310. //
  311. //  BOOL MixAppRefreshLineList
  312. //
  313. //  Description:
  314. //
  315. //
  316. //  Arguments:
  317. //      HWND hwnd: Handle of main window.
  318. //
  319. //  Return (BOOL):
  320. //
  321. //  History:
  322. //      05/16/93
  323. //
  324. //--------------------------------------------------------------------------;
  325.  
  326. BOOL FNGLOBAL MixAppRefreshLineList
  327. (
  328.     HWND                    hwnd,
  329.     PTABBEDLISTBOX          ptlb
  330. )
  331. {
  332.     static TCHAR        szLineTypeDst[] = TEXT("DST");
  333.     static TCHAR        szLineTypeSrc[] = TEXT("  src");
  334.  
  335.     MMRESULT            mmr;
  336.     UINT                u;
  337.     UINT                v;
  338.     UINT                cConnections;
  339.     MIXERLINE           mxl;
  340.     TCHAR               ach[128];
  341.     TCHAR               szComponent[64];
  342.     int                 nIndex;
  343.     MIXERCAPS           mxcaps;
  344.  
  345.  
  346.     //
  347.     //
  348.     //
  349.     SetWindowRedraw(ptlb->hlb, FALSE);
  350.     ListBox_ResetContent(ptlb->hlb);
  351.  
  352.  
  353.     if (0 != (APP_OPTF_DEBUGLOG & gfuAppOptions))
  354.         MixAppDebugLog(NULL);
  355.  
  356.  
  357.     //
  358.     //
  359.     //
  360.     //
  361.     mmr = mixerGetDevCaps((UINT)ghmx, &mxcaps, sizeof(mxcaps));
  362.     if (MMSYSERR_NOERROR != mmr)
  363.     {
  364.         AppMsgBox(hwnd, MB_OK | MB_ICONEXCLAMATION,
  365.                     "mixerGetDevCaps() failed on hmx=%.04Xh, mmr=%u!",
  366.                     ghmx, mmr);
  367.  
  368.         mxcaps.cDestinations = 0;
  369.     }
  370.  
  371.     for (u = 0; u < mxcaps.cDestinations; u++)
  372.     {
  373.         mxl.cbStruct      = sizeof(mxl);
  374.         mxl.dwDestination = u;
  375.  
  376.         mmr = mixerGetLineInfo((HMIXEROBJ)ghmx, &mxl, MIXER_GETLINEINFOF_DESTINATION);
  377.         if (MMSYSERR_NOERROR != mmr)
  378.         {
  379.             AppMsgBox(hwnd, MB_OK | MB_ICONEXCLAMATION,
  380.                       "mixerGetLineInfo(dst=%u) failed on hmx=%.04Xh, mmr=%u!",
  381.                       u, ghmx, mmr);
  382.             continue;
  383.         }
  384.  
  385.         MixAppGetComponentName(&mxl, szComponent);
  386.  
  387.         //
  388.         //
  389.         //
  390.         wsprintf(ach, gszLineFormatList,
  391.                  (LPSTR)szLineTypeDst,
  392.                  (MIXERLINE_LINEF_ACTIVE & mxl.fdwLine) ? '*' : ' ',
  393.                  (LPTSTR)szComponent,
  394.                  mxl.dwLineID,
  395.                  mxl.fdwLine,
  396.                  mxl.cControls,
  397.                  mxl.cConnections,
  398.                  (LPSTR)mxl.szName);
  399.  
  400.         if (0 != (APP_OPTF_DEBUGLOG & gfuAppOptions))
  401.         {
  402.             MixAppDebugLog(ach);
  403.             MixAppDebugLog(gszCRLF);
  404.         }
  405.  
  406.         nIndex = ListBox_AddString(ptlb->hlb, ach);
  407.         ListBox_SetItemData(ptlb->hlb, nIndex, mxl.dwLineID);
  408.  
  409.         cConnections = (UINT)mxl.cConnections;
  410.         for (v = 0; v < cConnections; v++)
  411.         {
  412.             mxl.cbStruct      = sizeof(mxl);
  413.             mxl.dwDestination = u;
  414.             mxl.dwSource      = v;
  415.  
  416.             mmr = mixerGetLineInfo((HMIXEROBJ)ghmx, &mxl, MIXER_GETLINEINFOF_SOURCE);
  417.             if (MMSYSERR_NOERROR != mmr)
  418.             {
  419.                 AppMsgBox(hwnd, MB_OK | MB_ICONEXCLAMATION,
  420.                           "mixerGetLineInfo(src=%u) failed on hmx=%.04Xh, mmr=%u!",
  421.                           v, ghmx, mmr);
  422.                 continue;
  423.             }
  424.  
  425.  
  426.             MixAppGetComponentName(&mxl, szComponent);
  427.  
  428.  
  429.             //
  430.             //
  431.             //
  432.             wsprintf(ach, gszLineFormatList,
  433.                      (LPSTR)szLineTypeSrc,
  434.                      (MIXERLINE_LINEF_ACTIVE & mxl.fdwLine) ? '*' : ' ',
  435.                      (LPTSTR)szComponent,
  436.                      mxl.dwLineID,
  437.                      mxl.fdwLine,
  438.                      mxl.cControls,
  439.                      mxl.cConnections,
  440.                      (LPSTR)mxl.szName);
  441.  
  442.             if (0 != (APP_OPTF_DEBUGLOG & gfuAppOptions))
  443.             {
  444.                 MixAppDebugLog(ach);
  445.                 MixAppDebugLog(gszCRLF);
  446.             }
  447.  
  448.             nIndex = ListBox_AddString(ptlb->hlb, ach);
  449.             ListBox_SetItemData(ptlb->hlb, nIndex, mxl.dwLineID);
  450.         }
  451.     }
  452.  
  453.  
  454.     //
  455.     //
  456.     //
  457.     SetWindowRedraw(ptlb->hlb, TRUE);
  458.  
  459.     return (TRUE);
  460. } // MixAppRefreshLineList()
  461.  
  462.  
  463. //==========================================================================;
  464. //
  465. //
  466. //
  467. //
  468. //==========================================================================;
  469.  
  470. //--------------------------------------------------------------------------;
  471. //
  472. //  LRESULT MixAppLineChange
  473. //
  474. //  Description:
  475. //
  476. //
  477. //  Arguments:
  478. //      HWND hwnd:
  479. //
  480. //      HMIXER hmx:
  481. //
  482. //      DWORD dwLineID:
  483. //
  484. //  Return (LRESULT):
  485. //
  486. //  History:
  487. //      07/21/93
  488. //
  489. //--------------------------------------------------------------------------;
  490.  
  491. LRESULT FNGLOBAL MixAppLineChange
  492. (
  493.     HWND                    hwnd,
  494.     HMIXER                  hmx,
  495.     DWORD                   dwLineID
  496. )
  497. {
  498.     DPF(1, "MixAppLineChange(hwnd=%Xh, hmx=%Xh, dwLineID=%.08lXh)",
  499.         hwnd, hmx, dwLineID);
  500.  
  501.  
  502.     //
  503.     //
  504.     //
  505.     if (gfDisplayingControl &&
  506.         (dwLineID == gmxl.dwLineID) &&
  507.         (NULL != ghdlgControl))
  508.     {
  509.         SendMessage(ghdlgControl, MM_MIXM_LINE_CHANGE, (WPARAM)hmx, dwLineID);
  510.     }
  511.  
  512.  
  513.     MixAppRefreshLineList(hwnd, gptlbLines);
  514.  
  515.  
  516.     //
  517.     //  return zero because we handled the message
  518.     //
  519.     return (0L);
  520. } // MixAppLineChange()
  521.