请问各位大虾如何使windows media player控件随着窗口大小而自动重绘?我尝试获取它的大小然后movewindow,但是这样不成功。希望能给出源代码,谢谢!

解决方案 »

  1.   

    简单的说,就是一个对话框上放了一个windows media player控件,如何让它随着对话框大小改变而改变。
      

  2.   

    我现在在OnSize事件里能够处理其他控件例如按钮和文本框控件的大小改变,但是没有办法去动态改变windows media player的大小。
      

  3.   

    借鉴了别人的做法,他是在OnSize里面这么处理的:
    void CRecordHWndDlg::OnSize(UINT nType, int cx, int cy) 
    {
    CDialog::OnSize(nType, cx, cy);
    /////////////////listRect:CListRect listRect;
    ////////////////对话框初始化时做了下面操作:
    ////////CRect rectWnd;                        //此段代码的作用是记录窗口初始时的矩阵,便于用于缩放窗口
    ////////GetWindowRect(&rectWnd);
    ////////listRect.AddTail(&rectWnd);
    ////////CWnd *pWndChild = GetWindow(GW_CHILD);
    ////////while(pWndChild)
    ////////{
    ////////pWndChild->GetWindowRect(&rectWnd);
    ////////listRect.AddTail(&rectWnd);
    ////////pWndChild = pWndChild->GetNextWindow();
    ////////}
    ////////////////////////
             int nCount=listRect.GetCount();
    if(nCount > 0)
    {
    //m_VedioPlayer.GetWindowRect(&wmpRect);
    CRect rectDlgNow;
    GetWindowRect(&rectDlgNow);
    POSITION mP = listRect.GetHeadPosition();
    CRect rectDlgSaved;
    rectDlgSaved = listRect.GetNext(mP);
    ScreenToClient(rectDlgSaved);
    ScreenToClient(rectDlgNow);
    float fRateScaleX = (float)(rectDlgNow.right-rectDlgNow.left)/(rectDlgSaved.right-rectDlgSaved.left);
    float fRateScaleY = (float)(rectDlgNow.bottom-rectDlgNow.top)/(rectDlgSaved.bottom-rectDlgSaved.top);
    ClientToScreen(rectDlgSaved);
    ClientToScreen(rectDlgNow);
    LOGFONT stFont;
    ::GetObject((HFONT)GetStockObject(DEFAULT_GUI_FONT), sizeof(stFont), &stFont);
    strcpy(stFont.lfFaceName,"Times New Roman");
    stFont.lfHeight = (long)(fRateScaleY*14);
    stFont.lfWidth = (long)(fRateScaleX*7);
    CFont * m_pCFont;
    m_pCFont = new CFont;
    m_pCFont->CreateFontIndirect(&stFont);
    CRect rectChildSaved;
    CWnd *pWndChild = GetWindow(GW_CHILD);
    while(pWndChild)
    {
    rectChildSaved = listRect.GetNext(mP);
    rectChildSaved.left = rectDlgNow.left+(int)((rectChildSaved.left-rectDlgSaved.left)* fRateScaleX);
    rectChildSaved.top = rectDlgNow.top+(int)((rectChildSaved.top-rectDlgSaved.top)*fRateScaleY);
    rectChildSaved.right = rectDlgNow.right+(int)((rectChildSaved.right-rectDlgSaved.right)* fRateScaleX);
    rectChildSaved.bottom = rectDlgNow.bottom+(int)((rectChildSaved.bottom-rectDlgSaved.bottom)* fRateScaleY);
    ScreenToClient(rectChildSaved);
    pWndChild->MoveWindow(rectChildSaved);
    pWndChild->SetFont(m_pCFont);
    pWndChild = pWndChild->GetNextWindow();
    }
    }
    Invalidate();
    }
    但是这么做只能让按钮等控件动态改变,却不能使window media player动态改变,不知道为什么。
      

  4.   

    使用 SetWindowPos 函数就可以void CDD2Dlg::OnSize(UINT nType, int cx, int cy) 
    {
    CDialog::OnSize(nType, cx, cy);

    // TODO: Add your message handler code here
    if(m_MMPlayer.GetSafeHwnd())
    {
    m_MMPlayer.SetWindowPos(&wndTop,0,0,cx,cy, SWP_NOZORDER);
    }
    }
      

  5.   

    这样可以吗?我的控件也不是充满在整个Dialog里面啊
      

  6.   

    响应 OnSize事件后,在里面操作。