对话框对应的类为CFormView类,在重绘里给对话框加背景,程序运行时,改变对话框大小时,背景重叠出错,在线急等之
如题所示,代码如下:
void CMonitorTopView::OnPaint()
{
CRect temprect;//(0,0,0,0);
GetWindowRect(&temprect);
CWnd::SetWindowPos(NULL,0,0,temprect.Width(),temprect.Height(),SWP_NOZORDER|SWP_NOMOVE);
PAINTSTRUCT ps;
CDC *dc = BeginPaint(&ps);
CDC memdc;
CRect rect;
CBitmap bitmap;
BITMAP szbitmap;
bitmap.LoadBitmap(IDB_BITMAP1);
bitmap.GetObject( sizeof(BITMAP),&szbitmap );
CSize size( szbitmap.bmWidth,szbitmap.bmHeight );
memdc.CreateCompatibleDC(dc);
CBitmap *oldbitmap=memdc.SelectObject(&bitmap);
GetClientRect(&rect);
dc->StretchBlt(0,0,rect.Width(),rect.Height(),
&memdc,0,0,size.cx,size.cy,SRCCOPY);
memdc.SelectObject(oldbitmap);
memdc.DeleteDC();
EndPaint(&ps);
}
如题所示,代码如下:
void CMonitorTopView::OnPaint()
{
CRect temprect;//(0,0,0,0);
GetWindowRect(&temprect);
CWnd::SetWindowPos(NULL,0,0,temprect.Width(),temprect.Height(),SWP_NOZORDER|SWP_NOMOVE);
PAINTSTRUCT ps;
CDC *dc = BeginPaint(&ps);
CDC memdc;
CRect rect;
CBitmap bitmap;
BITMAP szbitmap;
bitmap.LoadBitmap(IDB_BITMAP1);
bitmap.GetObject( sizeof(BITMAP),&szbitmap );
CSize size( szbitmap.bmWidth,szbitmap.bmHeight );
memdc.CreateCompatibleDC(dc);
CBitmap *oldbitmap=memdc.SelectObject(&bitmap);
GetClientRect(&rect);
dc->StretchBlt(0,0,rect.Width(),rect.Height(),
&memdc,0,0,size.cx,size.cy,SRCCOPY);
memdc.SelectObject(oldbitmap);
memdc.DeleteDC();
EndPaint(&ps);
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货