예제 #1
0
void STDCALL OBS::MuteDesktopHotkey(DWORD hotkey, UPARAM param, bool bDown)
{
    if(!bDown) return;

    App->desktopVol = ToggleVolumeControlMute(GetDlgItem(hwndMain, ID_DESKTOPVOLUME));
    App->ReportDesktopVolumeChange(App->desktopVol, App->desktopVol < VOLN_MUTELEVEL, true);
}
예제 #2
0
void STDCALL OBS::MuteMicHotkey(DWORD hotkey, UPARAM param, bool bDown)
{
    if(!bDown) return;

    if(App->micAudio)
    {
        App->micVol = ToggleVolumeControlMute(GetDlgItem(hwndMain, ID_MICVOLUME));
        App->ReportMicVolumeChange(App->micVol, App->micVol < VOLN_MUTELEVEL, true);
    }
}
예제 #3
0
파일: VolumeControl.cpp 프로젝트: desg/OBS
LRESULT CALLBACK VolumeControlProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    VolumeControlData *control;

    switch(message)
    {
        case WM_NCCREATE:
            {
                CREATESTRUCT *pCreateData = (CREATESTRUCT*)lParam;

                control = (VolumeControlData*)malloc(sizeof(VolumeControlData));
                zero(control, sizeof(VolumeControlData));
                SetWindowLongPtr(hwnd, 0, (LONG_PTR)control);

                control->curVolume = 1.0f;
                control->bDisabled = ((pCreateData->style & WS_DISABLED) != 0);

                control->cx = pCreateData->cx;
                control->cy = pCreateData->cy;

                return TRUE;
            }

        case WM_DESTROY:
            {
                control = GetVolumeControlData(hwnd);
                if(control)
                    free(control);

                break;
            }

        case WM_PAINT:
            {
                control = GetVolumeControlData(hwnd);

                PAINTSTRUCT ps;

                HDC hDC = BeginPaint(hwnd, &ps);
                control->DrawVolumeControl(hDC);
                EndPaint(hwnd, &ps);

                break;
            }

        case WM_LBUTTONDOWN:
        case WM_LBUTTONUP:
            {
                control = GetVolumeControlData(hwnd);

                short x = short(LOWORD(lParam));
                short y = short(HIWORD(lParam));

                UINT id = (UINT)GetWindowLongPtr(hwnd, GWLP_ID);

                if(message == WM_LBUTTONDOWN && !control->bDisabled)
                {
                    if(control->cy == 32 && x >= (control->cx-32))
                    {
                        if(control->curVolume < VOLN_MUTELEVEL)
                        {
                            if(control->lastUnmutedVol < VOLN_MUTELEVEL)
                                control->lastUnmutedVol = 1.0f;
                            control->curVolume = control->lastUnmutedVol;
                        }
                        else
                        {
                            control->lastUnmutedVol = control->curVolume;
                            control->curVolume = 0.0f;
                        }

                        SendMessage(GetParent(hwnd), WM_COMMAND, MAKEWPARAM(id, VOLN_FINALVALUE), (LPARAM)hwnd);
                    }
                    else
                    {
                        SetCapture(hwnd);
                        control->bHasCapture = true;

                        if(control->curVolume > VOLN_MUTELEVEL)
                            control->lastUnmutedVol = control->curVolume;

                        int cxAdjust = control->cx;
                        if(control->bDrawIcon) cxAdjust -= 32;
                        control->curVolume = float(x) / cxAdjust;

                        SendMessage(GetParent(hwnd), WM_COMMAND, MAKEWPARAM(id, VOLN_ADJUSTING), (LPARAM)hwnd);
                    }

                    HDC hDC = GetDC(hwnd);
                    control->DrawVolumeControl(hDC);
                    ReleaseDC(hwnd, hDC);
                }
                else if(control->bHasCapture)
                {
                    UINT id = (UINT)GetWindowLongPtr(hwnd, GWLP_ID);
                    SendMessage(GetParent(hwnd), WM_COMMAND, MAKEWPARAM(id, VOLN_FINALVALUE), (LPARAM)hwnd);

                    ReleaseCapture();
                    control->bHasCapture = false;
                }
                
                break;
            }

        case WM_MOUSEMOVE:
            {
                control = GetVolumeControlData(hwnd);
                if(control->bHasCapture)
                {
                    int cxAdjust = control->cx;
                    if(control->bDrawIcon) cxAdjust -= 32;
                    control->curVolume = float(short(LOWORD(lParam))) / cxAdjust;

                    if(control->curVolume < 0.0f)
                        control->curVolume = 0.0f;
                    else if(control->curVolume > 1.0f)
                        control->curVolume = 1.0f;

                    HDC hDC = GetDC(hwnd);
                    control->DrawVolumeControl(hDC);
                    ReleaseDC(hwnd, hDC);

                    UINT id = (UINT)GetWindowLongPtr(hwnd, GWLP_ID);
                    SendMessage(GetParent(hwnd), WM_COMMAND, MAKEWPARAM(id, VOLN_ADJUSTING), (LPARAM)hwnd);
                }
                break;
            }

        case WM_ENABLE:
            {
                UINT id = (UINT)GetWindowLongPtr(hwnd, GWLP_ID);
                control = GetVolumeControlData(hwnd);

                if(control->bDisabled == !wParam)
                    break;

                control->bDisabled = !control->bDisabled;

                if(control->bDisabled)
                {
                    if(control->curVolume > VOLN_MUTELEVEL)
                    {
                        control->lastUnmutedVol = control->curVolume;
                        control->curVolume = 0.0f;
                        SendMessage(GetParent(hwnd), WM_COMMAND, MAKEWPARAM(id, VOLN_ADJUSTING), (LPARAM)hwnd);
                    }
                }
                else
                {
                    if(control->curVolume < VOLN_MUTELEVEL)
                    {
                        control->curVolume = control->lastUnmutedVol;
                        SendMessage(GetParent(hwnd), WM_COMMAND, MAKEWPARAM(id, VOLN_ADJUSTING), (LPARAM)hwnd);
                    }
                }

                HDC hDC = GetDC(hwnd);
                control->DrawVolumeControl(hDC);
                ReleaseDC(hwnd, hDC);
                break;
            }

        case WM_SIZE:
            {
                control = GetVolumeControlData(hwnd);
                control->cx = LOWORD(lParam);
                control->cy = HIWORD(lParam);

                control->bDrawIcon = (control->cy == 32) && control->hiconPlay;

                HDC hDC = GetDC(hwnd);
                control->DrawVolumeControl(hDC);
                ReleaseDC(hwnd, hDC);
                break;
            }

        case WM_COMMAND:
            {
                switch(HIWORD(wParam))
                {
                    /* 
                       Handle API Volume Adjustments 
                       Updates control values and sends message to obsproc to update
                       application volume.
                     */
                    case VOLN_FINALVALUE:
                    case VOLN_ADJUSTING:
                        {
                            float val = *(float*)lParam;
                            SetVolumeControlValue(hwnd, val);
                            
                            /* free volume value on heap */
                            free((void*) lParam);
                            
                            /* send message to obsproc to update volumes */
                            UINT id = (UINT)GetWindowLongPtr(hwnd, GWLP_ID);
                            SendMessage(GetParent(hwnd), WM_COMMAND, MAKEWPARAM(id, HIWORD(wParam)), (LPARAM)hwnd);
                            break;
                        }
                    case VOLN_TOGGLEMUTE:
                        {
                            UINT id = (UINT)GetWindowLongPtr(hwnd, GWLP_ID);
                            ToggleVolumeControlMute(GetDlgItem(hwndMain, id));

                            SendMessage(GetParent(hwnd), WM_COMMAND, MAKEWPARAM(id, VOLN_FINALVALUE), (LPARAM)hwnd);
                        }    
                }
                    
            }
        default:
            return DefWindowProc(hwnd, message, wParam, lParam);
    }

    return 0;
}