16,472
社区成员
发帖
与我相关
我的任务
分享
void CMapData::ReSize(int w,int h)
{
if(w==Width&&h==Height)
return;
CDC myDC ;
CBitmap myMap ,*oldmyMap;
CBrush b;
int ww = w>Width?w:Width ;
int hh = h>Height?h:Height ;
myDC.CreateCompatibleDC(&pDC) ;
myMap.CreateCompatibleBitmap(&pDC,ww,hh) ;
oldmyMap = myDC.SelectObject(&myMap) ;
b.CreateSolidBrush(RGB(0,0,255)) ;
myDC.FillRect(CRect(0,0,ww,hh),&b) ;
myDC.BitBlt(0,0,Width,Height,&pDC,0,0,SRCCOPY) ;/////备份当前绘图
pDC.SelectObject(oldmap) ;
map.DeleteObject() ;
map.CreateCompatibleBitmap(&pDC,w,h) ;
oldmap = pDC.SelectObject(&map) ;
pDC.BitBlt(0,0,w,h,&myDC,0,0,SRCCOPY) ;///恢复到新尺寸的位图;
Width = w ;
Height = h ;
myDC.SelectObject(oldmyMap) ;
myDC.DeleteDC() ;
myMap.DeleteObject() ;
b.DeleteObject() ;
oldPoint = newPoint =CPoint(-1,-1) ;
}
void CLeftView::OnDraw(CDC* pDC)
{
CVC60Doc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
//
if(pDoc->GetLeftBitmap())//m_hBmpLeft)
{// not client rect only !
SIZE sz=GetTotalSize();
sz.cx-=10;//gap
sz.cy-=10;
CDC memDC;
memDC.CreateCompatibleDC(pDC);
HBITMAP hOldBitmap = (HBITMAP)memDC.SelectObject(pDoc->GetLeftBitmap());//m_hBmpLeft);
pDC->BitBlt(4, 4, sz.cx, sz.cy, &memDC, 0, 0, SRCCOPY);// may bigger then client
memDC.SelectObject(hOldBitmap);
}
else
{
pDC->TextOut(10, 10, "Open a 24bits bitmap!");
}
}
void CLeftView::OnDraw(CDC* pDC)// 这个dc是彩色 DC
CDC memDC;
memDC.CreateCompatibleDC(pDC); // 这个dc是彩色 DC
virtual BOOL CreateCompatibleDC( CDC* pDC );
Return Value
Nonzero if the function is successful; otherwise 0.
Parameters
pDC
A pointer to a device context. If pDC is NULL, the function creates a memory device context that is compatible with the system display.
Remarks
Creates a memory device context that is compatible with the device specified by pDC. A memory device context is a block of memory that represents a display surface. It can be used to prepare images in memory before copying them to the actual device surface of the compatible device.
When a memory device context is created, GDI automatically selects a 1-by-1 monochrome stock bitmap for it. GDI output functions can be used with a memory device context only if a bitmap has been created and selected into that context.
When a memory device context is created, GDI automatically selects a 1-by-1 monochrome stock bitmap for it.