如题。大放血!50分!想用VC实现像网页中文字移动(滚动)的效果。还有文字由正在播放(开启)的文件决定。即读取文件信息出现在固定的显示栏。

解决方案 »

  1.   

    http://www.codeguru.com/Cpp/controls/staticctrl/scrollingtext/article.php/c5809/
    http://www.codeguru.com/Cpp/controls/staticctrl/article.php/c2903/
      

  2.   

    void CMyStatic::OnTimer(UINT nIDEvent) 
    {
    // TODO: Add your message handler code here and/or call default
    CString strText;
    GetWindowText(strText);
    if (strText == m_strText)
    {
    CDC* pDC = GetDC();
    pDC->SelectObject(&m_font);
    CSize size = pDC->GetTextExtent(strText);
    ReleaseDC(pDC);
    CRect rect;
    GetClientRect(rect);
    int iWidth = rect.Width();
    if (size.cx > iWidth)
    { Invalidate();
    UpdateWindow();
    m_iExtend += 2;
    if (m_iExtend > size.cx)
    m_iExtend -= size.cx + 8;
    }
    }
    else
    {
    m_iExtend = 0;
    m_strText = strText;
    }
    CStatic::OnTimer(nIDEvent);
    }
    void CMyStatic::OnPaint() 
    {
    // TODO: Add your message handler code here

    CPaintDC dc(this);
    CRect rc;
    GetClientRect(rc);
    CString strText;
    GetWindowText(strText);
    CDC memDC;
    memDC.CreateCompatibleDC(&dc);
    CBitmap bmp;
    bmp.CreateCompatibleBitmap(&dc, rc.Width(), rc.Height());
    memDC.SelectObject(&bmp);
    memDC.SelectObject(&m_font);
    dc.SelectObject(&m_font);
             memDC.FillSolidRect(rc, RGB(255, 255, 255);
    CSize size = memDC.GetTextExtent(strText);
    if (size.cx > rc.Width())
    {
    if (size.cx - m_iExtend > 0)
    memDC.TextOut(rc.left - m_iExtend, rc.top + (rc.Height() - size.cy)/2, strText);
    if (rc.left - m_iExtend + 8 +size.cx < rc.right)
    memDC.TextOut(rc.left - m_iExtend + 8+size.cx , rc.top + (rc.Height() - size.cy)/2, strText);
    }
    else
    memDC.TextOut(rc.left, rc.top + (rc.Height() - size.cy)/2, strText);
    dc.BitBlt(rc.left, rc.top, rc.Width(), rc.Height(), &memDC, rc.left, rc.top, SRCCOPY);
    memDC.DeleteDC();
    bmp.DeleteObject();
    }