6 个解决方案
#1
Invalidate /invalidateRect CDC::SetBkMode
#2
invalidateRect 导致OnDraw ,在OnDraw中SetBkMode/DrawText动态文字 会重叠
#3
CRect g_hWndRect;
void CXXDlg::OnPaint()
{
CPaintDC dc(this);
CDC dcMem;
dcMem.CreateCompatibleDC(&dc);
ASSERT(dcMem.GetSafeHdc());
CBitmap bmp;
CRect rc;
GetClientRect(&rc);
bmp.CreateCompatibleBitmap(&dc, rc.Width(), rc.Height());
ASSERT(bmp.GetSafeHandle());
CBitmap* pOldBitmap = (CBitmap*)dcMem.SelectObject(&bmp);
dcMem.FillSolidRect(&rc, GetSysColor(COLOR_3DFACE));
dcMem.SetTextColor(RGB(255, 0, 128));
dcMem.SetBkMode(TRANSPARENT);
CString strText(_T("Hello, World!"));
dcMem.DrawText(strText, &g_hWndRect, DT_CENTER | DT_SINGLELINE);
dc.BitBlt(0, 0, rc.Width(), rc.Height(), &dcMem, 0, 0, SRCCOPY);
dcMem.SelectObject(pOldBitmap);
dcMem.DeleteDC();
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CXXDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CXXDlg::OnOK()
{
// TODO: Add extra validation here
g_hWndRect.top = 0;
g_hWndRect.bottom = 30;
g_hWndRect.left = 100;
g_hWndRect.right = 300;
SetTimer(1, 100, NULL);
}
void CXXDlg::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
InvalidateRect(g_hWndRect);
CRect rc;
GetClientRect(&rc);
g_hWndRect.top += 10;
g_hWndRect.bottom = g_hWndRect.top + 30;
if(g_hWndRect.bottom >= rc.bottom)
{
g_hWndRect.top = 0;
g_hWndRect.bottom = g_hWndRect.top += 30;
}
CDialog::OnTimer(nIDEvent);
}
不用注释了吧
#4
谢谢!
VisualEleven的做法可以跑起来,
但是dcMem.FillSolidRect(&rc, GetSysColor(COLOR_3DFACE));这句话使得绘制的文字有的背景图啊, 我想达到的效果文字透明背景了。
VisualEleven的做法可以跑起来,
但是dcMem.FillSolidRect(&rc, GetSysColor(COLOR_3DFACE));这句话使得绘制的文字有的背景图啊, 我想达到的效果文字透明背景了。
#5
最简单的办法,
MODE 设置为TRANSPARENT
并且字符串中使用足够长的空格
MODE 设置为TRANSPARENT
并且字符串中使用足够长的空格
#6
问题解了 , 用内存DC保存第一次重绘时的背景至Cbitmap,以后再发生重绘的时候就用该Cbitmap作为背景
问题结晚了 ^^
问题结晚了 ^^
#1
Invalidate /invalidateRect CDC::SetBkMode
#2
invalidateRect 导致OnDraw ,在OnDraw中SetBkMode/DrawText动态文字 会重叠
#3
CRect g_hWndRect;
void CXXDlg::OnPaint()
{
CPaintDC dc(this);
CDC dcMem;
dcMem.CreateCompatibleDC(&dc);
ASSERT(dcMem.GetSafeHdc());
CBitmap bmp;
CRect rc;
GetClientRect(&rc);
bmp.CreateCompatibleBitmap(&dc, rc.Width(), rc.Height());
ASSERT(bmp.GetSafeHandle());
CBitmap* pOldBitmap = (CBitmap*)dcMem.SelectObject(&bmp);
dcMem.FillSolidRect(&rc, GetSysColor(COLOR_3DFACE));
dcMem.SetTextColor(RGB(255, 0, 128));
dcMem.SetBkMode(TRANSPARENT);
CString strText(_T("Hello, World!"));
dcMem.DrawText(strText, &g_hWndRect, DT_CENTER | DT_SINGLELINE);
dc.BitBlt(0, 0, rc.Width(), rc.Height(), &dcMem, 0, 0, SRCCOPY);
dcMem.SelectObject(pOldBitmap);
dcMem.DeleteDC();
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CXXDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CXXDlg::OnOK()
{
// TODO: Add extra validation here
g_hWndRect.top = 0;
g_hWndRect.bottom = 30;
g_hWndRect.left = 100;
g_hWndRect.right = 300;
SetTimer(1, 100, NULL);
}
void CXXDlg::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
InvalidateRect(g_hWndRect);
CRect rc;
GetClientRect(&rc);
g_hWndRect.top += 10;
g_hWndRect.bottom = g_hWndRect.top + 30;
if(g_hWndRect.bottom >= rc.bottom)
{
g_hWndRect.top = 0;
g_hWndRect.bottom = g_hWndRect.top += 30;
}
CDialog::OnTimer(nIDEvent);
}
不用注释了吧
#4
谢谢!
VisualEleven的做法可以跑起来,
但是dcMem.FillSolidRect(&rc, GetSysColor(COLOR_3DFACE));这句话使得绘制的文字有的背景图啊, 我想达到的效果文字透明背景了。
VisualEleven的做法可以跑起来,
但是dcMem.FillSolidRect(&rc, GetSysColor(COLOR_3DFACE));这句话使得绘制的文字有的背景图啊, 我想达到的效果文字透明背景了。
#5
最简单的办法,
MODE 设置为TRANSPARENT
并且字符串中使用足够长的空格
MODE 设置为TRANSPARENT
并且字符串中使用足够长的空格
#6
问题解了 , 用内存DC保存第一次重绘时的背景至Cbitmap,以后再发生重绘的时候就用该Cbitmap作为背景
问题结晚了 ^^
问题结晚了 ^^