用双缓冲 处理文字

aerospace 2007-11-21 02:28:22
用双缓冲 处理文字 .
我在内存缓冲中 输出文字,
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();

或者大家有没有什么别的好的实现方法啊?
...全文
61 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
aerospace 2007-11-21
  • 打赏
  • 举报
回复
楼上的正解,谢谢了.
wanshi131 2007-11-21
  • 打赏
  • 举报
回复
你好像没有设置MemDC->SetBkMode(TRANSPARENT);
BBirdlyh 2007-11-21
  • 打赏
  • 举报
回复
MemDC.CreateCompatibleDC(NULL); 创建了一个DISPLAYDC 兼容的MEM DC
pDc-> BitBlt(0,0,100,15,&MemDC,0,m_nPosition,SRCCOPY); //却用它来BLT到了一个窗口DC上


这样肯定是不行的,具体什么后果不太清楚,没想过这样的问题
passionhip 2007-11-21
  • 打赏
  • 举报
回复
不懂,一看DC就头痛,我们都用GDI.呵呵

15,979

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 界面
社区管理员
  • 界面
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧