用双缓冲 处理文字
用双缓冲 处理文字 .
我在内存缓冲中 输出文字,
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();
或者大家有没有什么别的好的实现方法啊?