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) ;
}
uj5u.com熱心網友回復:
請教各位大嬸,代碼中沒發現有什么問題啊,粘貼后只有黑白色,原圖中的彩色沒有了。uj5u.com熱心網友回復:
CClientDC myDC(this) ;uj5u.com熱心網友回復:
該函式只是想實作當前pDC上的map的大小。其中pDC,map都是初始化沒問題的。uj5u.com熱心網友回復:
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.
uj5u.com熱心網友回復:
沒看懂,你是說我不用重新選一個MyMap到MyDC嗎?uj5u.com熱心網友回復:
如
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
uj5u.com熱心網友回復:
想問問 你那個pDC 是全域的嗎 也是個memdc嗎 我也遇到這個了 兄臺怎么破的?轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/129738.html
標籤:基礎類
上一篇:VC或QT怎么能直接列印檔案?
