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

📄 playerwindow.cpp

📁 media player 控件源码 用EVC编译可以进行对WINCE下media player控制
💻 CPP
📖 第 1 页 / 共 5 页
字号:
                lVolume = 0;
            }

            m_binfoVolThumb.rc.left   = x + m_rcVolBounds.left;
            m_binfoVolThumb.rc.left   += lVolume;

            m_binfoVolThumb.ptPos.x = m_binfoVolThumb.rc.left - x;
        }
        else
        {
            m_binfoVolThumb.rc.left   = x + m_binfoVolThumb.ptPos.x;
        }

        m_binfoVolThumb.rc.right  = m_binfoVolThumb.rc.left + m_binfoVolThumb.ptDim.x;
        m_binfoVolThumb.rc.top    = y + m_binfoVolThumb.ptPos.y;
        m_binfoVolThumb.rc.bottom = m_binfoVolThumb.rc.top + m_binfoVolThumb.ptDim.y;

        TransparentImage(hdcBuf,
                         m_binfoVolThumb.rc.left - x,
                         m_binfoVolThumb.rc.top  - y,
                         m_binfoVolThumb.ptDim.x,
                         m_binfoVolThumb.ptDim.y,
                         hbitmap,
                         0, 0,
                         m_binfoVolThumb.ptDim.x,
                         m_binfoVolThumb.ptDim.y,
                         cTransColor);
    }

    //
    // Fill the background of the real window
    //

    rcFill.left   = 0;
    rcFill.right  = rc.right;
    rcFill.top    = y - 2;
    rcFill.bottom = rc.bottom;

    hbrush = CreateSolidBrush(cBkColor);

    FillRect(hdc, &rcFill, hbrush);

    DeleteObject(hbrush);

    //
    // Blt in the the buffered image
    //

    BitBlt(hdc,
           x,
           y,
           SKIN_WIDTH,
           SKIN_HEIGHT,
           hdcBuf,
           0,
           0,
           SRCCOPY);



    DeleteDC(hdcBuf);
#endif /* CEPLAYER_SKIN */

    return;
}

void CPlayerWindow::ApplyPlayCount( void )
{
    if( m_pMP )
    {
        if( m_bPlayForever )
        {
            m_pMP->put_PlayCount( 0 );
        }
        else
        {
            m_pMP->put_PlayCount( 1 );
        }
    }
}

void CPlayerWindow::ApplyZoomLevel( void )
{
    if( m_pMP )
    {
        m_pMP->put_AutoSize( TRUE );

        switch( m_dwZoomLevel )
        {
            case 0:
                m_pMP->put_DisplaySize( mpHalfSize );
            break;
            case 2:
                m_pMP->put_DisplaySize( mpDoubleSize );
            break;
            case 1:
            default:
                m_pMP->put_DisplaySize( mpDefaultSize );
            break;
        }
    }

    UpdateMenus();
}

void CPlayerWindow::SetMinimumRect( RECT &rect )
{
    DWORD width = rect.right - rect.left;
    DWORD height = rect.bottom - rect.top;

    if( width < m_dwMinimumWidth )
        m_dwMinimumWidth = (width < SKIN_WIDTH ? SKIN_WIDTH : width);
    if( height < m_dwMinimumHeight )
        m_dwMinimumHeight = height + SKIN_HEIGHT;
}

///////////////////////////////////////////////////////////////////////////////
// Name: CPlayerWindow::OnSize()
// Desc: This function is called when a WM_SIZE message is received.  It
//       calculates how much area is available for the MediaPlayer control.
///////////////////////////////////////////////////////////////////////////////
void CPlayerWindow::OnSize(int x, int y)
{
    RECT rcPos, rcWnd;
    bool bTooLarge  = false;
    bool bTooSmall  = false;
    bool bOffScreen = false;
    
    if( !m_pMP )
    {
        GetWindowRect(m_hWnd, &rcPos);

        x = (int)m_dwMinimumWidth;
        y = (int)m_dwMinimumHeight;

        if ( (x != rcPos.right - rcPos.left)
            || (y != rcPos.bottom - rcPos.top) )
        {
            MoveWindow(m_hWnd ,rcPos.left, rcPos.top, x, y, true);
        }
        return;
    }

#ifdef UNDER_CE
    // Refresh the command bar
    SendMessage(m_hWndCB, TB_AUTOSIZE, 0, 0);
    CommandBar_AlignAdornments(m_hWndCB);
#endif // UNDER_CE
    
    // Check this new size against the maximum display size of our device
    int iWidth, iHeight;
    RECT rcWorkArea;
    if( SystemParametersInfo( SPI_GETWORKAREA, 0, &rcWorkArea, 0 ) )
    {
        iWidth = rcWorkArea.right - rcWorkArea.left;
        iHeight = rcWorkArea.bottom - rcWorkArea.top;
    }
    else
    {
        HDC hDC = ::GetDC(NULL);
        iWidth = GetDeviceCaps(hDC, HORZRES);
        iHeight = GetDeviceCaps(hDC, VERTRES) - GetSystemMetrics(SM_CYMENU);
        ::ReleaseDC(NULL, hDC);

        rcWorkArea.left   = 0;
        rcWorkArea.top    = 0;
        rcWorkArea.right  = iWidth;
        rcWorkArea.bottom = iHeight;
    }

    if( y > iHeight )
    {
        y         = iHeight;
        bTooLarge = true;
    }
    if( x > iWidth )
    {
        x         = iWidth;
        bTooLarge = true;
    }

    if( y < (LONG)m_dwMinimumHeight
       && (LONG)m_dwMinimumHeight <= iHeight )
    {
        y         = (int)m_dwMinimumHeight;
        bTooSmall = true;
    }
    if( x < (LONG)m_dwMinimumWidth
       && (LONG)m_dwMinimumWidth <= iWidth )
    {
        x         = (int)m_dwMinimumWidth;
        bTooSmall = true;
    }

    // Factor in the height of the command bar when telling the control how
    // much area it has to deal with.
#ifdef UNDER_CE
    rcPos.top    = CommandBar_Height(m_hWndCB);
#else
    rcPos.top    = 0;
#endif // UNDER_CE
    rcPos.left   = 0;
    rcPos.right  = x;
#ifdef CEPLAYER_SKIN
    rcPos.bottom = y - SKIN_HEIGHT;
#else /* !CEPLAYER_SKIN */
    rcPos.bottom = y;
#endif /* CEPLAYER_SKIN */

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

    // Attempt the call the windowless control, and if it is not available
    // use a windowed control
    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);
    }

    GetWindowRect(m_hWnd, &rcWnd);

    if (rcWnd.right < rcWorkArea.left
        || rcWnd.left > rcWorkArea.right
        || rcWnd.top + GetSystemMetrics(SM_CYMENU) < rcWorkArea.top
        || rcWnd.top > rcWorkArea.bottom)
    {
        bOffScreen = true;
    }

    // If we're too big or small, resize the window
    if ( bTooLarge || bTooSmall || bOffScreen)
    {
        RECT rcClient;

        GetClientRect(m_hWnd, &rcClient);

        iWidth  = (rcWnd.right - rcWnd.left) - (rcClient.right - rcClient.left);
        iHeight = (rcWnd.bottom - rcWnd.top) - (rcClient.bottom - rcClient.top);

        iWidth += rcPos.right;
#ifdef CEPLAYER_SKIN
        iHeight += rcPos.bottom + SKIN_HEIGHT;
#else /* !CEPLAYER_SKIN */
        iHeight += rcPos.bottom;
#endif /* CEPLAYER_SKIN */

        //
        // Check for the maximum size of the player
        //
        if (iWidth > rcWorkArea.right - rcWorkArea.left)
            iWidth = rcWorkArea.right - rcWorkArea.left;
        if (iHeight > rcWorkArea.bottom - rcWorkArea.top)
            iHeight = rcWorkArea.bottom - rcWorkArea.top;

        //
        // It's possible that the player can resize itself to be completely
        // off the screen, so if it looks like it won't be on the screen, move
        // it somewhere else
        //

        if (rcWnd.left + iWidth < rcWorkArea.left)
        {
            rcWnd.left = rcWorkArea.left;
        }
        else if (rcWnd.left > rcWorkArea.right)
        {
            rcWnd.left = rcWorkArea.right - iWidth;
        }

        if (rcWnd.top + GetSystemMetrics(SM_CYMENU) < rcWorkArea.top)
        {
            rcWnd.top = rcWorkArea.top;
        }
        else if (rcWnd.top > rcWorkArea.bottom)
        {
            rcWnd.top = rcWorkArea.bottom - iHeight;
        }

        MoveWindow(m_hWnd,
            rcWnd.left,
            rcWnd.top,
            iWidth,
            iHeight,
            true);
    }

    return;
}

void CPlayerWindow::OnMeasureItem(MEASUREITEMSTRUCT * pmis)
{
    DrawMenuStruct * pMenuStruct;

    pMenuStruct = (DrawMenuStruct *)pmis->itemData;

    // we have fixed height menu items
    pmis->itemHeight = MENU_ITEM_HEIGHT;

    // calculate the required width for this item's text
    HDC hdc = ::GetDC(NULL);

    LPTSTR szMenuItem = NULL;

    if (NULL != pMenuStruct)
    {
        szMenuItem = pMenuStruct->szText;
    }
    else
    {
        szMenuItem = (LPTSTR)pmis->itemData;
    }

    SIZE size;

    if (NULL != szMenuItem)
    {
        GetTextExtentPoint32(hdc, szMenuItem, _tcslen(szMenuItem), &size);
    }
    else
    {
        size.cx = 0;
    }

    ::ReleaseDC(NULL, hdc);

    pmis->itemWidth = size.cx + MENU_ICON_WIDTH + 3*MENU_ITEM_HORZ_MARGIN;
    pmis->itemWidth = min(pmis->itemWidth, MAX_MENU_ITEM_WIDTH);
}

void CPlayerWindow::OnDrawItem(DRAWITEMSTRUCT * pdis)
{
    HDC              hdc         = pdis->hDC;
    RECT             rcItem      = pdis->rcItem;
    DrawMenuStruct * pMenuStruct = NULL;

    pMenuStruct = (DrawMenuStruct *)pdis->itemData;

    // Draw menu item background
    if ((ODA_SELECT == pdis->itemAction) || (ODA_DRAWENTIRE == pdis->itemAction))
    {
        if (0 != (pdis->itemState & ODS_SELECTED))
        {
            SetTextColor(hdc, GetSysColor(COLOR_HIGHLIGHTTEXT));
            FillRect(hdc, &rcItem, GetSysColorBrush(COLOR_HIGHLIGHT));
        }
        else
        {
            SetTextColor(hdc, GetSysColor(COLOR_MENUTEXT));
            FillRect(hdc, &rcItem, GetSysColorBrush(COLOR_MENU));
        }
    }

    // Draw the appropriate item
    int iImage = 0;

    if (pMenuStruct)
    {
        iImage = pMenuStruct->iImage;
    }

    ImageList_DrawEx(
        m_himgLocationList,
        iImage,
        hdc,
        rcItem.left + MENU_ITEM_HORZ_MARGIN,
        rcItem.top + 1,
        0,
        0,
        CLR_NONE,
        CLR_NONE,
        ILD_TRANSPARENT);

    // Draw the menu item text
    RECT rcText = rcItem;

    rcText.left += MENU_ICON_WIDTH + (2 * MENU_ITEM_HORZ_MARGIN);

    LPTSTR szMenuItem = NULL;
    if (NULL != pMenuStruct)
    {
        szMenuItem = pMenuStruct->szText;
    }
    else
    {
        szMenuItem = (LPTSTR) pdis->itemData;
    }

    int cchMenuItem = 0;

    if (NULL != szMenuItem)
    {
        cchMenuItem = _tcslen(szMenuItem);
    }
    else
    {
        szMenuItem = TEXT("");
    }

    int iOldMode = SetBkMode(hdc, TRANSPARENT);

    DrawEllipsisText(
        hdc,
        szMenuItem,
        cchMenuItem,
        &rcText,
        DT_LEFT | DT_SINGLELINE | DT_VCENTER | DT_NOPREFIX | DT_NOCLIP);

    // clean up
    if (0 != iOldMode) SetBkMode(hdc, iOldMode);
}

void CPlayerWindow::OnSizeSmall(int x, int y)
{
    RECT rcPos, rcWorkArea;
    int iWidth, iHeight;

    if (!m_pMP)
        return;

#ifdef UNDER_CE
    SendMessage(m_hWndCB, TB_AUTOSIZE, 0, 0);
    CommandBar_AlignAdornments(m_hWndCB);
#endif // UNDER_CE

    if (SystemParametersInfo(SPI_GETWORKAREA, 0, &rcWorkArea, 0))
    {
        iWidth  = rcWorkArea.right - rcWorkArea.left;
        iHeight = rcWorkArea.bottom - rcWorkArea.top;
    }
    else
    {
        HDC hDC = ::GetDC(NULL);
        iWidth  = GetDeviceCaps(hDC, HORZRES);

⌨️ 快捷键说明

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