16,472
社区成员
发帖
与我相关
我的任务
分享
void CFirstPageDlg::OnPaint()
{
CPaintDC dc(this);
Graphics graphics;
}
void CFirstPageDlg::OnPaint()
{
// 创建内存DC
CPaintDC dc(this); //你写的时候CClientDC dc(this);
CDC memdc;
memdc.CreateCompatibleDC(&dc);
CBitmap bmp;
CRect rc;
GetClientRect(&rc);
bmp.CreateCompatibleBitmap(&dc, rc.Width(), rc.Height());
memdc.SelectObject(&bmp);
bmp.DeleteObject();
// 创建GDI+画图对象
Graphics graphics(memdc);
Image image( ToWChar("china.jpg"));
Point ShowMatrix[3] =
{
Point(0, 0),
Point(image.GetWidth(), 0),
Point(0, image.GetHeight())
};
// 开始画图
graphics.DrawImage(&image, ShowMatrix, 3);
dc.BitBlt(0, 0, rc.Width(), rc.Height(), &memdc, 0, 0, SRCCOPY);
// 清理内存
memdc.DeleteDC();
}
WCHAR* ToWChar(char * str)
{
//在GDI+中,有关字符的参数类型全部都是WCHAR类型
//该函数是将传统字符串进行转换
static WCHAR buffer[1024];
wcsset(buffer,0);
MultiByteToWideChar(CP_ACP, 0, str, strlen(str), buffer, 1024);
return buffer;
}
// 创建内存DC
CClientDC dc(this);
CDC memdc;
memdc.CreateCompatibleDC(&dc);
CBitmap bmp;
CRect rc;
GetClientRect(&rc);
bmp.CreateCompatibleBitmap(&dc, rc.Width(), rc.Height());
memdc.SelectObject(&bmp);
bmp.DeleteObject();
// 创建GDI+画图对象
Graphics graphics(memdc);
Image image( ToWChar("1.jpg"));
Point ShowMatrix[3] =
{
Point(0, 0),
Point(image.GetWidth(), 0),
Point(0, image.GetHeight())
};
// 开始画图
graphics.DrawImage(&image, ShowMatrix, 3);
dc.BitBlt(0, 0, rc.Width(), rc.Height(), &memdc, 0, 0, SRCCOPY);
// 清理内存
memdc.DeleteDC();
void CMsgTipDlg::DrawMsg(CDC *pDC)
{
CRect rc;
GetClientRect(&rc);
CDC memDC;
memDC.CreateCompatibleDC(pDC);
CBitmap bmp;
bmp.CreateCompatibleBitmap(pDC,rc.Width(),rc.Height());
CBitmap *pOldBmp = memDC.SelectObject(&bmp);
memDC.FillSolidRect(rc,theApp.m_sysINIFile.GetMsgTipConfig().nMsgTipBkColor);
DrawGrid(&memDC,rc);//用兼容DC绘制你的图形内容
pDC->BitBlt(0, 0, rc.Width(),rc.Height(), &memDC, 0, 0, SRCCOPY) ;
pDC->SelectObject(pOldBmp);
bmp.DeleteObject();
memDC.DeleteDC();
}