VolumeCtrl.cpp
上传用户:oldpeter23
上传日期:2013-01-09
资源大小:1111k
文件大小:3k
源码类别:

IP电话/视频会议

开发平台:

Visual C++

  1. //NetTalk
  2. /*------------------------------------------------------------------------------*
  3.  =============================
  4.    模块名称: VolumeCtrl.cpp
  5.  =============================
  6.  
  7.  [版权]
  8.  
  9.    2000-2002  115软件工厂  版权所有
  10.                                               
  11. *------------------------------------------------------------------------------*/
  12. //not used
  13. #include "wndx.h"
  14. #include <Windows.h>
  15. #include "VolumeCtrl.h"
  16. /*------------------------------------------------------------------------------*/
  17. CVolumeCtrl::CVolumeCtrl()
  18. {
  19. m_h=0;
  20. }
  21. /*------------------------------------------------------------------------------*/
  22. CVolumeCtrl::~CVolumeCtrl()
  23. {
  24. Close();
  25. }
  26. /*------------------------------------------------------------------------------*/
  27. BOOL CVolumeCtrl::Open(UINT uDevHandle,BOOL bFlag)
  28. {
  29. BOOL bRet=FALSE;
  30. Close();
  31. DWORD f;
  32. if(bFlag)
  33. f=MIXER_OBJECTF_HWAVEOUT;
  34. else
  35. f=MIXER_OBJECTF_HWAVEIN;
  36. MMRESULT mmr;
  37. mmr=mixerOpen(&m_h,uDevHandle,0,0,f);
  38. if(mmr!=MMSYSERR_NOERROR)
  39. goto RET;
  40. m_mxl.cbStruct      = sizeof(m_mxl);
  41. m_mxl.dwDestination = 0;
  42. mmr = mixerGetLineInfo((HMIXEROBJ)m_h, &m_mxl, MIXER_GETLINEINFOF_DESTINATION);
  43. if (MMSYSERR_NOERROR != mmr)
  44. goto RET;
  45. m_mxlc.cbStruct       = sizeof(m_mxlc);
  46. m_mxlc.dwLineID       = m_mxl.dwLineID;
  47. m_mxlc.cControls      = m_mxl.cControls;
  48. m_mxlc.cbmxctrl       = sizeof(m_mxctrl);
  49. m_mxlc.dwControlType  = MIXERCONTROL_CONTROLTYPE_VOLUME;
  50. m_mxlc.pamxctrl       = &m_mxctrl;
  51. mmr = mixerGetLineControls((HMIXEROBJ)m_h, &m_mxlc, MIXER_GETLINECONTROLSF_ONEBYTYPE);
  52. if (MMSYSERR_NOERROR != mmr)
  53. goto RET;
  54. bRet=TRUE;
  55. RET:
  56. if(!bRet)
  57. Close();
  58. return bRet;
  59. }
  60. /*------------------------------------------------------------------------------*/
  61. BOOL CVolumeCtrl::Close()
  62. {
  63. MMRESULT mmr;
  64. if(m_h)
  65. mmr=mixerClose(m_h);
  66. m_h=0;
  67. if(mmr==MMSYSERR_NOERROR) return TRUE;
  68. else return FALSE;
  69. }
  70. /*------------------------------------------------------------------------------*/
  71. DWORD CVolumeCtrl::GetVolume()
  72. {
  73. if(!m_h) return 0;
  74. MIXERCONTROLDETAILS mxcd;
  75. MIXERCONTROLDETAILS_UNSIGNED mxcd_u;
  76. mxcd.cbStruct=sizeof(mxcd);
  77. mxcd.cChannels=1;
  78. mxcd.dwControlID=m_mxctrl.dwControlID;
  79. mxcd.paDetails=&mxcd_u;
  80. mxcd.cbDetails=4;
  81. mxcd.cMultipleItems=m_mxctrl.cMultipleItems;
  82. MMRESULT mmr;
  83. mmr=mixerGetControlDetails((HMIXEROBJ)m_h,&mxcd,MIXER_SETCONTROLDETAILSF_VALUE);
  84. if(mmr!=MMSYSERR_NOERROR)
  85. return 0;
  86. else
  87. return (mxcd_u.dwValue-m_mxctrl.Bounds.dwMinimum)*100/(m_mxctrl.Bounds.dwMaximum-m_mxctrl.Bounds.dwMinimum);
  88. }
  89. /*------------------------------------------------------------------------------*/
  90. BOOL CVolumeCtrl::SetVolume(DWORD dwValue)
  91. {
  92. if(!m_h) return FALSE;
  93. MIXERCONTROLDETAILS mxcd;
  94. MIXERCONTROLDETAILS_UNSIGNED mxcd_u;
  95. mxcd.cbStruct=sizeof(mxcd);
  96. mxcd.cChannels=1;
  97. mxcd.dwControlID=m_mxctrl.dwControlID;
  98. mxcd.paDetails=&mxcd_u;
  99. mxcd.cbDetails= sizeof(MIXERCONTROLDETAILS_UNSIGNED);
  100. mxcd.cMultipleItems=0;
  101. mxcd_u.dwValue=dwValue*(m_mxctrl.Bounds.dwMaximum-m_mxctrl.Bounds.dwMinimum)/100+m_mxctrl.Bounds.dwMinimum;
  102. MMRESULT mmr;
  103. mmr=mixerSetControlDetails((HMIXEROBJ)m_h,&mxcd,MIXER_SETCONTROLDETAILSF_VALUE);
  104. if(mmr!=MMSYSERR_NOERROR)
  105. return FALSE;
  106. return TRUE;
  107. }