双缓冲显示字幕(卡拉ok字幕)

摘要:
想法:1.设置计时器SetTime,在Ontime()中确定显示矩形的大小,然后使用DrawText将字符放置在矩形上;2.intnTextHei=dc.GetTextExtent(m_strText)。cy;//水平高度标签的长度文本intnTextWei=dc的高度。GetTextExtent(m_strText)。cx//水平标签长度

思路:

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;
}

 

免责声明:文章转载自《双缓冲显示字幕(卡拉ok字幕)》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇Chrome调试sysbench安装及使用下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

随便看看

Kafka监控工具——Kafka-Eagle

Kafka监控工具官网https://www.kafka-eagle.org/是什么KafkaEagle是一款用于监控和管理ApacheKafka的完全开源系统,目前托管在Github,由笔者和一些开源爱好者共同维护。而且,在使用消费者API时,尽量#客户端KafkaAPI版本和Kafka服务端的版本保持#一致性。...

docker run hangs问题排查记录

1.故障描述过去两天遇到了一个非常奇怪的问题。现在完整的故障描述如下:1)首先,我的同事告诉我,K8S集群中的一个工作节点将其状态更改为NoReady,并且在节点kubelet_truntime的错误日志中发现了大量此类日志E060301:50:51.45511776268remote。go:332]ExecSync1f0e3ac13faf224129bc4...

input框输入金额处理的解决办法

最近,已经启动的项目在删除输入输入量时突然出现问题。各种在线搜索都没有找到你想要的。今天,我将以react框架为例进行代码贡献。我会写下需求和解决方案,希望对我的朋友有用。如果有更好的方法实现它,请给我一些建议!”在“:”下;n=数学。防抱死制动系统;vars=“”;对于{s+=.replace;}S=S||“整数”;n=数学。地板对于{varp=“”;对于...

Ubuntu 18.04 安装微信(附企业微信)

Ubuntu软件市场也是有的,所以安全性不用担心开源地址:https://github.com/geeeeeeeeek/electronic-wechat下面介绍几种安装的方式:1.直接解压运行先选择你系统版本:解压一下:tar-zxvfxxx.tar.gz算了,还是简单为新手分析一下==》tar命令可以解包.tar和.tar.gz。为啥我的没有微信图标?...

利用油猴插件实现全网VIP视频免费看

利用油猴插件实现全网VIP视频免费看第一步:首先打开谷歌应用商店搜索tampermonkey安装这个插件第二步:在百度搜索框搜索油猴可以看到以下页面,点击进入。下载谷歌上网助手解压后,将后缀为crx的文件拖入即可。之后注册一个谷歌上网助手账后登录即可进入谷歌应用商店油猴插件...

nginx重启

方法二:在启动命令-c前加-t2、重启Nginx服务方法一:进入nginx可执行目录sbin下,输入命令./nginx-sreload即可方法二:查找当前nginx进程号,然后输入命令:kill-HUP进程号实现重启nginx服务...