示例#1
0
void SetVolumeControlIcons(HWND hwnd, HICON hiconPlay, HICON hiconMute)
{
    VolumeControlData *control = GetVolumeControlData(hwnd);
    if(!control)
        CrashError(TEXT("GetVolumeControlValue called on a control that's not a volume control"));

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

    HDC hDC = GetDC(hwnd);
    control->DrawVolumeControl(hDC);
    ReleaseDC(hwnd, hDC);
}
示例#2
0
float SetVolumeControlValue(HWND hwnd, float fVal)
{
    VolumeControlData *control = GetVolumeControlData(hwnd);
    if(!control)
        CrashError(TEXT("SetVolumeControlValue called on a control that's not a volume control"));

    float lastVal = control->curVolume;

    control->curVolume = fVal;

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

    return lastVal;
}
示例#3
0
float ToggleVolumeControlMute(HWND hwnd)
{
    VolumeControlData *control = GetVolumeControlData(hwnd);
    if(!control)
        CrashError(TEXT("ToggleVolumeControlMute called on a control that's not a volume control"));

    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;
    }

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

    return control->curVolume;
}
示例#4
0
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;
}
示例#5
0
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 < 0.05f)
                        {
                            if(control->lastUnmutedVol < 0.05f)
                                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 > 0.05f)
                            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 > 0.05f)
                    {
                        control->lastUnmutedVol = control->curVolume;
                        control->curVolume = 0.0f;
                        SendMessage(GetParent(hwnd), WM_COMMAND, MAKEWPARAM(id, VOLN_ADJUSTING), (LPARAM)hwnd);
                    }
                }
                else
                {
                    if(control->curVolume < 0.05f)
                    {
                        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;
            }

        default:
            return DefWindowProc(hwnd, message, wParam, lParam);
    }

    return 0;
}