c++ 使用TransparentBlt后为什么图片变大了?
BOOLCChildView::PreCreateWindow(CREATESTRUCT&cs){if(!CWnd::PreCreateWindow(cs))return...
BOOL CChildView::PreCreateWindow(CREATESTRUCT& cs)
{
if (!CWnd::PreCreateWindow(cs))
return FALSE;
cs.dwExStyle |= WS_EX_CLIENTEDGE;
cs.style &= ~WS_BORDER;
cs.lpszClass = AfxRegisterWndClass(CS_HREDRAW|CS_VREDRAW|CS_DBLCLKS,
::LoadCursor(NULL, IDC_ARROW), reinterpret_cast<HBRUSH>(COLOR_WINDOW+1), NULL);
//初始化背景上下文
m_bgCdc.CreateCompatibleDC(NULL);
m_bgCbitmap.LoadBitmap(IDB_BITMAP1);
m_bgCdc.SelectObject(&m_bgCbitmap);
m_bgCbitmap.GetBitmap(&m_bgBitmap);
m_gridCdc.CreateCompatibleDC(NULL);
m_gridCbitmap.LoadBitmap(IDB_BITMAP2);
m_gridCdc.SelectObject(&m_gridCbitmap);
//hook区域初始化,hook分辨率为60*60
m_hookCRt.left = 20;
m_hookCRt.right = 20+39;
m_hookCRt.top = 20;
m_hookCRt.bottom = 20+39;
return TRUE;
}
void CChildView::OnPaint()
{
CDC* cDc = this->GetDC();
GetClientRect(&m_clientCRt);
m_cacheCdc.CreateCompatibleDC(NULL);
m_cacheCbitmap.CreateCompatibleBitmap(cDc,m_clientCRt.Width(),m_clientCRt.Height());
m_cacheCdc.SelectObject(&m_cacheCbitmap);
m_cacheCdc.StretchBlt(0,0,m_clientCRt.Width(),m_clientCRt.Height(),&m_bgCdc,0,0,m_bgBitmap.bmWidth,m_bgBitmap.bmHeight,SRCCOPY);
//获取缓冲DC句柄
HDC cacheHdc = m_cacheCdc.m_hDC;
//获取hook DC句柄
HDC hookHdc = m_gridCdc.m_hDC;
///////////////////////////////////////////////////这里////////////////////////////////////////////////////////////////
TransparentBlt(cacheHdc, 0, 0, m_bgBitmap.bmWidth,m_bgBitmap.bmHeight,
hookHdc, 0, 0, m_hookCRt.Width(),m_hookCRt.Height(),
RGB(255,255,255));
////////////////////////////////////////////////////上面////////////////////////////////////////////////////////////////
cDc->BitBlt(0,0,m_clientCRt.Width(),m_clientCRt.Height(),&m_cacheCdc,0,0,SRCCOPY);
//释放缓冲区
m_cacheCdc.DeleteDC();
m_cacheCbitmap.DeleteObject();
//申明绘图区有效(绘制完成)
ValidateRect(&m_clientCRt);
} 展开
{
if (!CWnd::PreCreateWindow(cs))
return FALSE;
cs.dwExStyle |= WS_EX_CLIENTEDGE;
cs.style &= ~WS_BORDER;
cs.lpszClass = AfxRegisterWndClass(CS_HREDRAW|CS_VREDRAW|CS_DBLCLKS,
::LoadCursor(NULL, IDC_ARROW), reinterpret_cast<HBRUSH>(COLOR_WINDOW+1), NULL);
//初始化背景上下文
m_bgCdc.CreateCompatibleDC(NULL);
m_bgCbitmap.LoadBitmap(IDB_BITMAP1);
m_bgCdc.SelectObject(&m_bgCbitmap);
m_bgCbitmap.GetBitmap(&m_bgBitmap);
m_gridCdc.CreateCompatibleDC(NULL);
m_gridCbitmap.LoadBitmap(IDB_BITMAP2);
m_gridCdc.SelectObject(&m_gridCbitmap);
//hook区域初始化,hook分辨率为60*60
m_hookCRt.left = 20;
m_hookCRt.right = 20+39;
m_hookCRt.top = 20;
m_hookCRt.bottom = 20+39;
return TRUE;
}
void CChildView::OnPaint()
{
CDC* cDc = this->GetDC();
GetClientRect(&m_clientCRt);
m_cacheCdc.CreateCompatibleDC(NULL);
m_cacheCbitmap.CreateCompatibleBitmap(cDc,m_clientCRt.Width(),m_clientCRt.Height());
m_cacheCdc.SelectObject(&m_cacheCbitmap);
m_cacheCdc.StretchBlt(0,0,m_clientCRt.Width(),m_clientCRt.Height(),&m_bgCdc,0,0,m_bgBitmap.bmWidth,m_bgBitmap.bmHeight,SRCCOPY);
//获取缓冲DC句柄
HDC cacheHdc = m_cacheCdc.m_hDC;
//获取hook DC句柄
HDC hookHdc = m_gridCdc.m_hDC;
///////////////////////////////////////////////////这里////////////////////////////////////////////////////////////////
TransparentBlt(cacheHdc, 0, 0, m_bgBitmap.bmWidth,m_bgBitmap.bmHeight,
hookHdc, 0, 0, m_hookCRt.Width(),m_hookCRt.Height(),
RGB(255,255,255));
////////////////////////////////////////////////////上面////////////////////////////////////////////////////////////////
cDc->BitBlt(0,0,m_clientCRt.Width(),m_clientCRt.Height(),&m_cacheCdc,0,0,SRCCOPY);
//释放缓冲区
m_cacheCdc.DeleteDC();
m_cacheCbitmap.DeleteObject();
//申明绘图区有效(绘制完成)
ValidateRect(&m_clientCRt);
} 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询