⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 playerwindow.cpp

📁 media player 控件源码 用EVC编译可以进行对WINCE下media player控制
💻 CPP
📖 第 1 页 / 共 5 页
字号:
        iHeight = GetDeviceCaps(hDC, VERTRES) - GetSystemMetrics(SM_CYMENU);
        ::ReleaseDC(NULL, hDC);
    }

    m_dwMinimumWidth  = (DWORD)iWidth;
    m_dwMinimumHeight = (DWORD)iHeight;

    if (x != iWidth || y != iHeight)
    {
        MoveWindow(m_hWnd, 0, 0, iWidth, iHeight, true);
    }
    else
    {
        // factor in the command bar
#ifdef UNDER_CE
        rcPos.top    = CommandBar_Height(m_hWndCB);
#else
        rcPos.top    = 0;
#endif // UNDER_CE
        rcPos.left   = 0;
        rcPos.right  = iWidth;
#ifdef CEPLAYER_SKIN
        rcPos.bottom = iHeight - SKIN_HEIGHT;
#else
        rcPos.bottom = iHeight;
#endif // CEPLAYER_SKIN

        // Save the control's window position.
        m_rcPos = rcPos;

        if (NULL != m_pIPOW)
        {
            m_pIPOW->SetObjectRects(&m_rcPos, &m_rcPos);
            InvalidateRect(&m_rcPos, FALSE);
        }
        else if (NULL != m_pIPO)
        {
            m_pIPO->SetObjectRects(&m_rcPos, &m_rcPos);
            InvalidateRect(&m_rcPos, FALSE);
        }
    }

    return;
}

void CPlayerWindow::OnMouseMove(int x, int y)
{
    POINT pt;
    bool  bStateChange = false;

    pt.x = x;
    pt.y = y;

#ifdef CEPLAYER_SKIN
    for (int i = 0; i < SKIN_SIZE; i++)
    {
        EnterCriticalSection( &m_csButtonInfoCritSec );
        if (TRUE != PtInRect(&m_binfo[i].rc, pt)
            && DOWN == m_binfo[i].eState
            && SKIN_SOUND != i)
        {
            m_binfo[i].eState = UP;
            bStateChange      = true;
        }
        LeaveCriticalSection( &m_csButtonInfoCritSec );
    }

    if (DOWN == m_binfoVolThumb.eState
        && m_rcVolBounds.left <= (x - m_iSkinMargin - m_binfoVolThumb.ptDim.x/2)
        && (x - m_iSkinMargin - m_binfoVolThumb.ptDim.x/2) <= m_rcVolBounds.right)
    {
        LONG  lVolume;

        m_binfoVolThumb.ptPos.x = x - m_iSkinMargin - m_binfoVolThumb.ptDim.x/2;
        bStateChange = true;

        if (m_binfoVolThumb.ptPos.x < m_rcVolBounds.left)
        {
            m_binfoVolThumb.ptPos.x = m_rcVolBounds.left;
        }
        else if (m_binfoVolThumb.ptPos.x > m_rcVolBounds.right)
        {
            m_binfoVolThumb.ptPos.x = m_rcVolBounds.right;
        }

        if (m_binfoVolThumb.ptPos.x <= m_rcVolBounds.left)
        {
            lVolume = MIN_VOLUME_RANGE;
        }
        else if (m_binfoVolThumb.ptPos.x >= m_rcVolBounds.right)
        {
            lVolume = MAX_VOLUME_RANGE;
        }
        else
        {
            lVolume = (m_binfoVolThumb.ptPos.x - m_rcVolBounds.left) * (MAX_VOLUME_RANGE - MIN_VOLUME_RANGE) / (m_rcVolBounds.right - m_rcVolBounds.left);
        }

        m_pMP->put_Volume(VolumeLinToLog((short)lVolume));

        //
        // If the volume is being changed, make sure mute isn't set
        //
        VARIANT_BOOL fMute = FALSE;

        m_pMP->get_Mute(&fMute);

        if (fMute)
        {
            m_pMP->put_Mute(FALSE);

            UpdateMenus();
        }
    }

    if (DOWN == m_binfoSeekThumb.eState
        && m_rcSeekBounds.left <= (x - m_iSkinMargin - m_binfoSeekThumb.ptDim.x/2)
        && (x - m_iSkinMargin - m_binfoSeekThumb.ptDim.x/2) <= m_rcSeekBounds.right)
    {
        m_binfoSeekThumb.ptPos.x = x - m_iSkinMargin - m_binfoSeekThumb.ptDim.x/2;
        bStateChange = true;

        if (m_binfoSeekThumb.ptPos.x < m_rcSeekBounds.left)
        {
            m_binfoSeekThumb.ptPos.x = m_rcSeekBounds.left;
        }
        else if (m_binfoSeekThumb.ptPos.x > m_rcSeekBounds.right)
        {
            m_binfoSeekThumb.ptPos.x = m_rcSeekBounds.right;
        }
    }
#endif /* CEPLAYER_SKIN */

    if (bStateChange)
    {
        ::InvalidateRect(m_hWnd, NULL, TRUE);
    }
}

void CPlayerWindow::OnMouseDown(int x, int y)
{
    POINT pt;
    bool  bStateChange = false;

    pt.x = x;
    pt.y = y;

#ifdef CEPLAYER_SKIN
    for (int i = 0; i < SKIN_SIZE; i++)
    {
        EnterCriticalSection( &m_csButtonInfoCritSec );
        if (SKIN_VOLUME == i
                 && UP == m_binfo[SKIN_VOLUME].eState
                 && TRUE == PtInRect(&m_binfo[i].rc, pt))
        {
            if (DISABLED != m_binfoVolThumb.eState)
            {
                m_binfoVolThumb.eState = DOWN;
            }
        }
        else if (SKIN_SEEK == i
                 && UP == m_binfo[SKIN_SEEK].eState
                 && TRUE == PtInRect(&m_binfo[i].rc, pt))
        {
            if (DISABLED != m_binfoSeekThumb.eState)
            {
                m_binfoSeekThumb.eState = DOWN;
            }
        }
        else if (TRUE == PtInRect(&m_binfo[i].rc, pt))
        {
            if (UP == m_binfo[i].eState)
            {
                m_binfo[i].eState = DOWN;
                bStateChange      = true;
            }
        }
        else if (DOWN == m_binfo[i].eState && SKIN_SOUND != i)
        {
            m_binfo[i].eState = UP;
            bStateChange      = true;
        }
        LeaveCriticalSection( &m_csButtonInfoCritSec );
    }

    if (DOWN == m_binfoVolThumb.eState)
    {
        m_binfoVolThumb.ptPos.x = x - m_iSkinMargin - m_binfoVolThumb.ptDim.x/2;
        bStateChange = true;

        if (m_binfoVolThumb.ptPos.x < m_rcVolBounds.left)
        {
            m_binfoVolThumb.ptPos.x = m_rcVolBounds.left;
        }
        else if (m_binfoVolThumb.ptPos.x > m_rcVolBounds.right)
        {
            m_binfoVolThumb.ptPos.x = m_rcVolBounds.right;
        }
    }
    else if (UP == m_binfoVolThumb.eState
             && TRUE == PtInRect(&m_binfoVolThumb.rc, pt))
    {
        m_binfoVolThumb.eState = DOWN;
        bStateChange           = true;
    }

    if (DOWN == m_binfoSeekThumb.eState)
    {
        m_binfoSeekThumb.ptPos.x = x - m_iSkinMargin - m_binfoSeekThumb.ptDim.x/2;
        bStateChange = true;

        if (m_binfoSeekThumb.ptPos.x < m_rcSeekBounds.left)
        {
            m_binfoSeekThumb.ptPos.x = m_rcSeekBounds.left;
        }
        else if (m_binfoSeekThumb.ptPos.x > m_rcSeekBounds.right)
        {
            m_binfoSeekThumb.ptPos.x = m_rcSeekBounds.right;
        }
    }
    else if (UP == m_binfoSeekThumb.eState
             && m_fCanSeek
             && TRUE == PtInRect(&m_binfoSeekThumb.rc, pt))
    {
        m_binfoSeekThumb.eState = DOWN;
        bStateChange            = true;
    }
#endif /* CEPLAYER_SKIN */

    if (bStateChange)
    {
        ::InvalidateRect(m_hWnd, NULL, TRUE);
    }
}

void CPlayerWindow::OnMouseUp(int x, int y)
{
    POINT pt;
    bool  bStateChange = false;

    pt.x = x;
    pt.y = y;

#ifdef CEPLAYER_SKIN
    for (int i = 0; i < SKIN_SIZE; i++)
    {
        EnterCriticalSection( &m_csButtonInfoCritSec );
        if (TRUE == PtInRect(&m_binfo[i].rc, pt))
        {
            if (DOWN == m_binfo[i].eState)
            {
                m_binfo[i].eState = UP;
                bStateChange      = true;

                // Call the appropriate function for a button press
                switch (i)
                {
                    case SKIN_NEXT:
                        if (m_pPlaylist)
                        {
                            m_pPlaylist->CurrentTrackDonePlaying();
                            m_pPlaylist->NextTrack(
                                m_bShuffle ? true : false, true);
                            OnPlaySong(m_pPlaylist);
                        }
                        else
                        {
                            if (EState::PAUSE == m_eState)
                            {
                                SetState(PLAY);
                                UpdateMenus();
                            }

                            if (m_pMP) m_pMP->Next();
                        }
                    break;

                    case SKIN_PREV:
                        if (m_pPlaylist)
                        {
                            m_pPlaylist->CurrentTrackDonePlaying();
                            m_pPlaylist->PrevTrack(
                                m_bShuffle ? true : false, true);
                            OnPlaySong(m_pPlaylist);
                        }
                        else
                        {
                            if (EState::PAUSE == m_eState)
                            {
                                SetState(PLAY);
                                UpdateMenus();
                            }

                            if (m_pMP) m_pMP->Previous();
                        }
                    break;

                    case SKIN_FF:
                        if( m_currentRate < sizeof( ratesArray ) / sizeof( ratesArray[0] ) - 1 )
                        {
                            m_currentRate++;
                            if( m_pMP )
                            {
                                WCHAR wzBuffer[1024];
                                wsprintf( wzBuffer, L"WMP Debug: Setting playback rate %d", ratesArray[ m_currentRate ] );
                                m_pMP->put_Rate( ratesArray[ m_currentRate ] );

                                // Update the UI
                                ::InvalidateRect(m_hWnd, NULL, TRUE);
                            }
                        }
                        break;

                    case SKIN_FR:
                        if( m_currentRate > 0 )
                        {
                            m_currentRate--;
                            if( m_pMP )
                            {
                                WCHAR wzBuffer[1024];
                                wsprintf( wzBuffer, L"WMP Debug: Setting playback rate %d", ratesArray[ m_currentRate ] );
                                m_pMP->put_Rate( ratesArray[ m_currentRate ] );
                            }
                        }
                        break;

                    case SKIN_SOUND:
                        OnMute();
                    break;

                    case SKIN_STOP:
                        if (OPENING == m_eState)
                        {
                            if (m_pPlaylist)
                            {
                                m_pPlaylist->CurrentTrackDonePlaying();
                            }

                            if (NULL != m_pMP)
                            {
                                m_pMP->Cancel();
                            }
                        }
                        else
                        {
                            OnStop();
                        }
                    break;

                    case SKIN_PLAY:
                        OnPlay();
                    break;

                    case SKIN_PAUSE:
                        OnPause();
                    break;

                    case SKIN_VOLUME:
                    break;

                    case SKIN_SEEK:
                    break;
                }
            }
            else if (i == SKIN_SOUND)
            {
                OnMute();
                bStateChange = true;
            }
        }
        else if (DOWN == m_binfo[i].eState && SKIN_SOUND != i)
        {
            m_binfo[i].eState = UP;
            bStateChange      = true;
        }
        LeaveCriticalSection( &m_csButtonInfoCritSec );
    }

    if (DOWN == m_binfoVolThumb.eState)
    {
        LONG  lVolume;

        m_binfoVolThumb.eState = UP;

        m_binfoVolThumb.ptPos.x = x - m_iSkinMargin - m_binfoVolThumb.ptDim.x/2;
        bStateChange = true;

        if (m_binfoVolThumb.ptPos.x <= m_rcVolBounds.left)
        {
              lVolume = MIN_VOLUME_RANGE;
        }
        else if (m_binfoVolThumb.ptPos.x >= m_rcVolBounds.right)
        {
              lVolume = MAX_VOLUME_RANGE;
        }
        else
        {
            lVolume = (m_binfoVolThumb.ptPos.x - m_rcVolBounds.left) * (MAX_VOLUME_RANGE - MIN_VOLUME_RANGE) / (m_rcVolBounds.right - m_rcVolBounds.left);
        }

        m_pMP->put_Volume(VolumeLinToLog((short)lVolume));

        //
        // If the volume is being changed, make sure mute isn't set
        //
        VARIANT_BOOL fMute = FALSE;

        m_pMP->get_Mute(&fMute);

        if (fMute)
        {
            m_pMP->put_Mute(FALSE);

            UpdateMenus();
        }
    }

    if (DOWN == m_binfoSeekThumb.eState)
    {
        double dPosition = 0.0;

        m_binfoSeekThumb.eState = UP;

        m_binfoSeekThumb.ptPos.x = x - m_iSkinMargin - m_binfoVolThumb.ptDim.x/2;
        bStateChange = true;

        if (m_binfoSeekThumb.ptPos.x < m_rcSeekBounds.left)
        {
            m_binfoSeekThumb.ptPos.x = m_rcSeekBounds.left;
        }
        else if (m_binfoSeekThumb.ptPos.x > m_rcSeekBounds.right)
        {
            m_binfoSeekThumb.ptPos.x = m_rcSeekBounds.right;
        }

        dPosition = (m_binfoSeekThumb.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -