void CVisionTest::OnPaint()
{
//CPaintDC dc(this); // device context for painting
// TODO: 在此处添加消息处理程序代码
// 不为绘图消息调用 CDialog::OnPaint()
UpdateWindow();
m_userDirection=m_direction;
CRect dlgRect,staticRect,groupRect;
this->GetWindowRect (&dlgRect);
CStatic *pStatic=(CStatic *) GetDlgItem( IDC_STATIC1);
CStatic *pGroup=(CStatic *)GetDlgItem(IDC_STATIC2);
//CStatic *pDlg=(CStatic *)GetDlgItem(IDD_TEST_DIALOG);
//pDlg->GetWindowRect(&dlgRect);
pGroup->GetClientRect(&groupRect);
pStatic->GetClientRect(&staticRect);//得到静态文本框的尺寸
int x,y,z;
x=dlgRect.Width();
y=dlgRect.Height ();
z=groupRect.Width();
pStatic->MoveWindow(CRect((x-z-staticWidth)/2,(y-staticHeight)/2,staticWidth,staticHeight));
CDC* pDC=pStatic->GetDC();//获得当前DC
CBitmap bitmap;
bitmap.LoadBitmap(m_bmpId);//将位图对象加载到bitmap对象中
BITMAP bmp;//位图结构,位图的数据,包括大小等
bitmap.GetBitmap(&bmp);//得到位图的数据
CDC dcCompatible;
dcCompatible.CreateCompatibleDC(pDC);//创建一个与当前DC兼容的DC,与位图相关的信息保存到dcCompatible中了,要显示的目标区域则由当前DC:pDC所指示出来
CBitmap *pOldbitmap = dcCompatible.SelectObject(&bitmap);
dcCompatible.FillSolidRect(0,0,bmp.bmWidth,bmp.bmHeight,RGB(255,255,255));//将背景设为白色
dcCompatible.SelectObject(&bitmap);
pDC->StretchBlt(0,0,staticWidth,staticHeight , &dcCompatible,0,0,bmp.bmWidth,bmp.bmHeight,SRCCOPY);//加载图片
//绘图完成后的清理
dcCompatible.SelectObject(pOldbitmap);
bitmap.DeleteObject();
Invalidate();
ReleaseDC(pDC);
}
背景抑制是白色的,可是我已经重画图了