用双缓冲 处理文字

aerospace aerospace 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
用双缓冲 处理文字 .
我在内存缓冲中 输出文字,
MemDC.TextOut(0,46,stemp);
但是最后显示不出来?

但是我在内存缓冲中画线就可以.
MemDC.MoveTo(0,0);
MemDC.LineTo(60,60);


我想在内存缓冲中写文字, 然后利用选取不同的区域,实现文字被切割的样子.
代码如下:
int nWidth,nHeight;
nWidth = 120;
nHeight = 120;

CFont m_fntArial;
CFont* pOldFont;
BOOL bSuccess;
BOOL bUnderline;
BOOL bItalic;

bUnderline = FALSE;
bItalic = FALSE;
RECT ScrollRect;



PAINTSTRUCT ps;
CDC* pDc = this-> BeginPaint(&ps);
pDc-> SetBkMode(TRANSPARENT);


CDC MemDC;
CPen NewPen, *pOldPen;
NewPen.CreatePen(PS_SOLID, 2, BLUE);

CString stemp;

//pDc-> SelectObject(m_pBrush[m_nBrushColor]);

CBrush bBrush(BLACK);
CBitmap MemBitmap;
MemDC.CreateCompatibleDC(NULL);
MemBitmap.CreateCompatibleBitmap(pDc,100,60);
CBitmap *pOldBit=MemDC.SelectObject(&MemBitmap);
pOldPen = MemDC.SelectObject(&NewPen);

bSuccess = m_fntArial.CreateFont(NORMAL_TEXT_HEIGHT, 0, 0, 0,
FW_THIN, bItalic, bUnderline, 0,
ANSI_CHARSET,
OUT_DEFAULT_PRECIS,
CLIP_DEFAULT_PRECIS,
PROOF_QUALITY,
VARIABLE_PITCH ¦ 0x04 ¦ FF_DONTCARE,
(LPSTR) "Arial ");
MemDC.SetTextColor(NORMAL_TEXT_COLOR);
pOldFont = MemDC.SelectObject(&m_fntArial);

if (m_nPosition == 0)
{
if (m_nCurrLine < LINECOUNT)
{
ScrollRect.bottom = 15;
ScrollRect.left = 0;
ScrollRect.right = 100;
ScrollRect.top =0;
stemp = pArrCredit[m_nCurrLine];
MemDC.FillRect(&ScrollRect,&bBrush);
MemDC.DrawText((const char *)pArrCredit[m_nCurrLine],stemp.GetLength(),&ScrollRect,DT_TOP ¦DT_CENTER ¦
DT_NOPREFIX ¦ DT_SINGLELINE);
}

if ((m_nCurrLine + 1) < LINECOUNT)
{
ScrollRect.top = 16;
ScrollRect.bottom = 30;
stemp = pArrCredit[m_nCurrLine+1];
MemDC.FillRect(&ScrollRect,&bBrush);
MemDC.DrawText((const char *)pArrCredit[m_nCurrLine + 1],stemp.GetLength(),&ScrollRect,DT_TOP ¦DT_CENTER ¦
DT_NOPREFIX ¦ DT_SINGLELINE);
}

if ((m_nCurrLine + 2) < LINECOUNT)
{
ScrollRect.top = 31;
ScrollRect.bottom = 45;
stemp = pArrCredit[m_nCurrLine+2];
MemDC.FillRect(&ScrollRect,&bBrush);
MemDC.DrawText((const char *)pArrCredit[m_nCurrLine + 2],stemp.GetLength(),&ScrollRect,DT_TOP ¦DT_CENTER ¦
DT_NOPREFIX ¦ DT_SINGLELINE);
}

if ((m_nCurrLine + 3) < LINECOUNT)
{
ScrollRect.top = 46;
ScrollRect.bottom = 60;
stemp = pArrCredit[m_nCurrLine+3];
MemDC.FillRect(&ScrollRect,&bBrush);
MemDC.DrawText((const char *)pArrCredit[m_nCurrLine + 3],stemp.GetLength(),&ScrollRect,DT_TOP ¦DT_CENTER ¦
DT_NOPREFIX ¦ DT_SINGLELINE);
}

MemDC.SelectObject(pOldFont);
m_nPosition++;
}

ScrollRect.bottom = 15;
ScrollRect.left = 0;
ScrollRect.right = 100;
ScrollRect.top =0;
pDc-> FillRect(&ScrollRect,&bBrush);

ScrollRect.top = 20;
ScrollRect.bottom = 35;
pDc-> FillRect(&ScrollRect,&bBrush);

ScrollRect.top = 40;
ScrollRect.bottom = 55;
pDc-> FillRect(&ScrollRect,&bBrush);

pDc-> BitBlt(0,0,100,15,&MemDC,0,m_nPosition,SRCCOPY);
pDc-> BitBlt(0,20,100,15,&MemDC,0,m_nPosition+15,SRCCOPY);
pDc-> BitBlt(0,40,100,15,&MemDC,0,m_nPosition+30,SRCCOPY);

MemBitmap.DeleteObject();
MemDC.SelectObject(pOldPen);
MemDC.DeleteDC();


this-> EndPaint(&ps);

CDialog::OnPaint();

或者大家有没有什么别的好的实现方法啊?
...全文

相关推荐

评论 4
收藏 已收藏
分享
返回顶部
aerospace
界面 15,976 成员 115,866 内容