我找了段编辑框背景图的代码,用资源位图加载后刷新很正常,但是后来改成了截取对话框背景再贴图刷新时出现错误,不知道怎么办,求教大神指点。
文件地址: http://d.1tpan.com/tp0864900050
Image imgBox(L"images\\Stripe.png", FALSE);
int imgcx = imgBox.GetWidth();
int imgcy = imgBox.GetHeight();
CRect rect(GetSystemMetrics(SM_CXSCREEN)/2-imgBox.GetWidth()/2+5,
GetSystemMetrics(SM_CYSCREEN)/2-imgBox.GetHeight()/2+3,
GetSystemMetrics(SM_CXSCREEN)/2-imgBox.GetWidth()/2+5+imgcx-10,
GetSystemMetrics(SM_CYSCREEN)/2-imgBox.GetHeight()/2+3+imgcy-6);    
HDC hdc = ::GetDC(0);
HDC memDC = CreateCompatibleDC(hdc); // 绘图内存DC
HBITMAP mybitmap = CreateCompatibleBitmap(hdc, rect.Width(), rect.Height());
SelectObject(memDC,mybitmap);
BitBlt(memDC,0,0, rect.right-rect.left+1, rect.bottom-rect.top+1, hdc,0,0,SRCCOPY);
bitmap.Attach((HBITMAP)mybitmap); //创建一个透明的画刷
//bitmap.LoadBitmap(IDB_BMP);//这是原本的代码
m_brush.CreateStockObject(NULL_BRUSH);