zoukankan      html  css  js  c++  java
  • 双缓冲显示字幕(卡拉ok字幕)

    思路:

    1.设置定时器SetTime,在Ontime()里面确定显示矩形的大小,让后用DrawText把字铁道矩形上面;

    2.

    int nTextHei = dc.GetTextExtent( m_strText ).cy; // length of horizontal label文字的高度
    int nTextWei = dc.GetTextExtent( m_strText ).cx; // length of horizontal label文字的宽度

    获取文字高度和宽度。

    3.设置矩形的大小

    矩形的宽度可以每次都加1;

    void CShowFontView::OnTimer(UINT nIDEvent)
    {
         
        
        CClientDC dc(this);
        CFont font;
        CRect rt;
        GetClientRect( &rt );
        TEXTMETRIC tm;
        dc.GetTextMetrics(&tm);
        static int nindex = 0;
    
        m_nWithRect += 1;
        if( !nindex )
         m_strText = GetGeci( nindex );
        int nTextHei = dc.GetTextExtent( m_strText ).cy; // length of horizontal label文字的高度
        int nTextWei = dc.GetTextExtent( m_strText ).cx; // length of horizontal label文字的宽度
        RectShow.SetRect( 300 , 300 , 300+nTextWei+20 , 300+ nTextHei );
        
        
    
        if( m_nWithRect > nTextWei )
        {
            m_nWithRect = 10;
            nindex ++;
            m_strText = GetGeci( nindex );
            Sleep(1000);        
        }
    
        rectRetangle.SetRect( nTextWei +20 - m_nWithRect , 30 , nTextWei +20 , 30+nTextHei );
        rectColor.SetRect( 300 , 300 , 300+m_nWithRect , 300+nTextHei );
        Sleep(30);
        DrawText( m_strText );
        
        CView::OnTimer(nIDEvent);
    }

    然后呢就把字贴出来;怎样贴呢就根据需求;

    void CShowFontView::DrawText( CString strText )
    {
        if( strText.IsEmpty() )
        {
            return;
        }
        static int ncout = 0;
        CClientDC dc( this );
        CRect rtclient;
        GetClientRect( &rtclient );
        CBitmap MemBitmap;
        CDC MemDC; //首先定义一个显示设备对象
        MemDC.CreateCompatibleDC( &dc );
        MemBitmap.CreateCompatibleBitmap( &dc , rtclient.Width() , rtclient.Height() );
        MemDC.SelectObject( &MemBitmap );
        MemDC.FillSolidRect( 0  ,0 , rtclient.Width() , rtclient.Height() , RGB( 199 , 237 , 208));
        MemDC.SetTextColor( RGB( 255 , 0 , 0));
        MemDC.DrawText( strText , &rectRetangle , DT_LEFT );//字幕向左滚动;
    
    
        MemDC.SetTextColor( RGB( 0 , 0 , 0 ) );//先把这段歌词全部显示
        MemDC.DrawText( strText , &RectShow , DT_LEFT );
        
        MemDC.SetTextColor( RGB( 0, 0 , 255 ));//在把要变色的再显示一遍;
        MemDC.DrawText( strText , &rectColor , DT_LEFT );
    
    
        dc.BitBlt( 0 , 0 , rtclient.Width() , rtclient.Height() , &MemDC , 0, 0 , SRCCOPY );
        MemBitmap.DeleteObject();
        MemDC.DeleteDC();    
        ncout ++;
        
        
    }
    int CShowFontView::OnCreate(LPCREATESTRUCT lpCreateStruct)
    {
        if (CView::OnCreate(lpCreateStruct) == -1)
            return -1;
        readGeci();
        SetTimer( 0 , 3 ,0 );
        return 0;
    }
    
    BOOL CShowFontView::OnEraseBkgnd(CDC* pDC)
    {
        
        return CView::OnEraseBkgnd(pDC);
    }
    void CShowFontView::readGeci()
    {
        CStdioFile dlg;
        if(    dlg.Open("res\text.txt" , CFile::modeRead ) )
        {
            CString strText;
            while ( dlg.ReadString( strText ))
            {
                m_ListCtring.AddHead( strText );
            }
            dlg.Close();
        }
    }
    CString CShowFontView::GetGeci( int nindex )
    {
        CString strText;
        if( nindex < m_ListCtring.GetCount()&& m_ListCtring.GetCount()>0 )
            strText = m_ListCtring.GetAt( m_ListCtring.FindIndex( m_ListCtring.GetCount() -nindex -1  ));
        else
            KillTimer(0);
        return strText;
    }

     

  • 相关阅读:
    python中计算程序用时的方法
    既生list何生tuple
    SSAS-时间维度的标准设计
    1092 最好吃的月饼 (20 分
    1091 N-自守数 (15 分)
    1149 Dangerous Goods Packaging (25 分)
    1148 Werewolf
    1144 The Missing Number (20 分)
    1141 PAT Ranking of Institutions (25 分)
    1140 Look-and-say Sequence (20 分)
  • 原文地址:https://www.cnblogs.com/chenzuoyou/p/3361654.html
Copyright © 2011-2022 走看看