锘??xml version="1.0" encoding="utf-8" standalone="yes"?>
]]>
綆浠嬶細(xì)鍐呭瓨DC錛屽張鍚嶁滃弻緙撳啿鈥濓紝鏄В鍐硍indows紿楀彛鑷粯涓嚭鐜扳滈棯灞忊濈殑甯歌鎵嬫銆?/p>
1)銆佷負(fù)灞忓箷 DC 鍒涘緩鍏煎鐨勫唴瀛?DC
2)銆佸垱寤轟綅鍥?br>3)銆佹妸浣嶅浘閫夊叆璁懼鐜
4)銆佹妸緇樺埗濂界殑鍥懼艦鈥滄嫹璐濃滃埌灞忓箷涓?
鐪嬭繖涓唬鐮侊細(xì)
棣栧厛鐪嬫瀯閫狅紝浠庝竴涓狢DC鏋勯犮傜劧鍚庣湅浜?jiǎn)涓涓嬫垚鍛樺嚱鏁幫紝濂藉儚娌″嚑涓紝浼拌榪欐槸涓涓彲浠ュ畬鍏ㄦ浛鎹㈢殑CDC鐨勭渷蹇?jī)鐨勪笢涓溿?/p>
鐒跺悗鐪嬫瀽鏋勶細(xì)鏋愭瀯鏄竴涓狟itBit錛岃仈鎯寵嚜宸卞仛鍐呭瓨DC鐨勬椂鍊欙紝鏈鍚庝竴姝ヤ篃鏄唴瀛樺埌DC鐨勮創(chuàng)鍥懼姩浣溿?/p>
鍏紑鎺ュ彛灝變袱涓紝閲嶈澆鐨凜DC* 鍜?->鎿嶄綔錛岀洿鎺ヨ兘褰撲綔CDC浣跨敤銆?/p>
榪欏嚑涓粏鑺傞渶瑕佹敞鎰忥細(xì)
1.m_bMemDC = !pDC->IsPrinting(); // 浠ュ墠鍏蟲敞涓嶅錛岃繖鏄敤浜庡垽鏂繖涓狣C鏄笉鏄敤浜巔rint錛屽鏋滄槸灝變笉浣跨敤鈥滃唴瀛楧C鈥濓紝鑷充簬涓轟粈涔堣繕涓嶄簡(jiǎn)瑙c傛垜鐞嗚В鏄病鏈夐渶瑕併?/p>
2.FillSolidRect(m_rect, pDC->GetBkColor()); // WM_ERASEBKGND錛岄拡瀵硅繖涓秷鎭殑緇嗚妭澶勭悊銆?/p>
榪欎釜綾繪寔鏈変簡(jiǎn)涓涓滃墠鍙扳滵C錛屽畠鏈韓鏄竴涓滃悗鍙扳滵C錛屾瘡嬈″悗鍙板厠闅嗗墠鍙版墽琛岀粯鐢葷劧鍚庢妸緇撴灉璐村洖鍘匯?/p>
榪欓噷榪樻湁涓涓粏鑺傦紝灝辨槸SelectObject銆備負(fù)浜?jiǎn)淇濊瘉涓嶆硠婕忓Q屾渶濂界殑鍔炴硶鏄紝姣忔宸ヤ綔瀹屾垚灝嗘墍鏈夌殑GDI瀵硅薄澶嶄綅銆?/p>
///////////////////////////////////////////////////////////////
class CMemDC : public CDC
{
public:
// constructor sets up the memory DC
CMemDC(CDC* pDC) : CDC()
{
ASSERT(pDC != NULL);
m_pDC = pDC;
m_pOldBitmap = NULL;
#ifndef _WIN32_WCE_NO_PRINTING
m_bMemDC = !pDC->IsPrinting();
#else
m_bMemDC = FALSE;
#endif
if (m_bMemDC) // Create a Memory DC
{
pDC->GetClipBox(&m_rect);
CreateCompatibleDC(pDC);
m_bitmap.CreateCompatibleBitmap(pDC, m_rect.Width(), m_rect.Height());
m_pOldBitmap = SelectObject(&m_bitmap);
#ifndef _WIN32_WCE
SetWindowOrg(m_rect.left, m_rect.top);
#endif
// EFW - Bug fix - Fill background in case the user has overridden
// WM_ERASEBKGND. We end up with garbage otherwise.
// CJM - moved to fix a bug in the fix.
FillSolidRect(m_rect, pDC->GetBkColor());
}
else // Make a copy of the relevent parts of the current DC for printing
{
#if !defined(_WIN32_WCE) || ((_WIN32_WCE > 201) && !defined(_WIN32_WCE_NO_PRINTING))
m_bPrinting = pDC->m_bPrinting;
#endif
m_hDC = pDC->m_hDC;
m_hAttribDC = pDC->m_hAttribDC;
}
}
// Destructor copies the contents of the mem DC to the original DC
~CMemDC()
{
if (m_bMemDC)
{
// Copy the offscreen bitmap onto the screen.
m_pDC->BitBlt(m_rect.left, m_rect.top, m_rect.Width(), m_rect.Height(),
this, m_rect.left, m_rect.top, SRCCOPY);
//Swap back the original bitmap.
SelectObject(m_pOldBitmap);
} else {
// All we need to do is replace the DC with an illegal value,
// this keeps us from accidently deleting the handles associated with
// the CDC that was passed to the constructor.
m_hDC = m_hAttribDC = NULL;
}
}
// Allow usage as a pointer
CMemDC* operator->() {return this;}
// Allow usage as a pointer
operator CMemDC*() {return this;}
private:
CBitmap m_bitmap; // Offscreen bitmap
CBitmap* m_pOldBitmap; // bitmap originally found in CMemDC
CDC* m_pDC; // Saves CDC passed in constructor
CRect m_rect; // Rectangle of drawing area.
BOOL m_bMemDC; // TRUE if CDC really is a Memory DC.
};