Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Skin Based ActiveX Control to Change Mic and Speaker Voice Intensity

0.00/5 (No votes)
8 Jul 2005 1  
A skin based ActiveX control to change mic and speaker voice intensity.

Sample Image

Introduction

This control has been developed in order to facilitate controlling speaker and mic. volume in multimedia applications. It is written in MFC. It is skinned and its beauty really can be felt when hosted in a webpage. It just needs two images, one for the background of the control and the second for the knob to adjust the voice intensity.

Details

The control is based on Windows Multimedia SDK. To control volume of devices ::mixerSetControlDetails() API is used. Mmsystem.h and Winmm.lib are all we need to add for it. When the control is loaded, it auto resizes according to the background image's dimensions. It behaves just like the horizontal slider control.

You can set its background image with the method SetBackImage(LPCTSTR FilePath) and set the knob/buddy's image using SetBuddyImage(LPCTSTR FilePath). To set the buddy's position on the slider, the SetBuddyPos(long Position) method is available. The same control can be used for both controlling playback and recording devices. There is a property UseForMIC. Its default value is false, which means by default it works for playback devices. In order to use it for recording devices, UseForMIC has to be set to true.

The control handles mouse messages WM_LBUTTONDOWN, WM_LBUTTONUP and WM_MOUSEMOVE in order to move the knob of control to adjust the volume of devices.

WM_MOUSEDOWN

//

// //************************************************************************//

// /*------------------------------------------------------------------------//

// Message Handler of Left Mouse Button Down, it is called on WM_LBUTTONDOWN

// //------------------------------------------------------------------------*/

void CVoiceMeterCtrl::OnLButtonDown(UINT nFlags, CPoint point) 
{
    SetCapture();
    if(point.x > (m_BackImgSize.cx - m_BuddySize.cx))
        m_BuddyPos = m_BackImgSize.cx - m_BuddySize.cx;
    else
        m_BuddyPos = point.x;

    m_bDragging = true;
    InvalidateControl();    
    
    if(!m_useForMIC)
        UpdateSpkrVolume();
    else
    {
        UpdateMIC();    
        
    }
    COleControl::OnLButtonDown(nFlags, point);
}

WM_MOUSEUP

////**************************************************************************//

///*--------------------------------------------------------------------------//

//         Message Handler of Left Mouse Button Up, it is called on WM_LBUTTONUP

////-------------------------------------------------------------------------*/

void CVoiceMeterCtrl::OnLButtonUp(UINT nFlags, CPoint point) 
{
    ReleaseCapture();
    if(m_bDragging)
    {
        if(point.x > (m_BackImgSize.cx - m_BuddySize.cx))
            m_BuddyPos = m_BackImgSize.cx - m_BuddySize.cx;
        else
            m_BuddyPos = point.x;

        m_bDragging = false;
        InvalidateControl();

        if(!m_useForMIC)
            UpdateSpkrVolume();
        else
            UpdateMIC();
    }    
    COleControl::OnLButtonUp(nFlags, point);
}

WM_MOUSEMOVE

//***************************************************************************//

///*-------------------------------------------------------------------------//

//         Message Handler of Mouse Move, it is called on WM_MOUSEMOVE

////-------------------------------------------------------------------------*/

void CVoiceMeterCtrl::OnMouseMove(UINT nFlags, CPoint point) 
{
    if(m_bDragging)
    {
        if(point.x > (m_BackImgSize.cx - m_BuddySize.cx))
            m_BuddyPos = m_BackImgSize.cx - m_BuddySize.cx;
        else
            m_BuddyPos = point.x;

        if(point.x <= 0)
        {
            m_BuddyPos = 0;
            m_bDragging = false;
        }

        InvalidateControl();    
        if(!m_useForMIC)
            UpdateSpkrVolume();
        else
            UpdateMIC();
    }    
    COleControl::OnMouseMove(nFlags, point);
}

Using the code

ActiveX is wrapped in VoiceMeter.ocx. First of all, it is to be registered on the machine. In the command prompt, type regsvr32 [path of file]VoiceMeter.ocx. It generates a wrapper class CVoiceMeter in the project in which we add this control. The sample attached with this article contains two control instances (IDC_VOLUME and IDC_MIC) for a dialog. Control type variables (m_Ctrl and m_mic respectively) are attached. In OnInitDialog of the main dialog, the bitmaps are set to the controls (sample code as below).

//

//    .    .    .

//    .    .    .

//

     // for Playbeak device

    m_Ctrl.SetBackImage("back.bmp");
    m_Ctrl.SetBuddyImage("buddy.bmp");

    // for recording device

    m_mic.SetUseForMIC(true);
    m_mic.SetBackImage("back.bmp");
    m_mic.SetBuddyImage("buddy.bmp");

    return TRUE;
}

Using in a webpage

In an HTML page, it can be hosted with the object tag.

//
<object id="vMeter" name="vMeter" 
       classid="clsid:7499A590-FC1C-41BB-AD99-6764B1D7E599"
       align="bottom" border="0" width="240" height="12" >
     </object>
//

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here