英文原文來自MSDN,我自己翻譯了一下。
關(guān)于內(nèi)存DC:
To enable applications to place output in memory rather than 
sending it to an actual device, use a special device context for bitmap 
operations called a memory device context. A memory DC enables the system to 
treat a portion of memory as a virtual device. It is an array of bits in memory 
that an application can use temporarily to store the color data for bitmaps 
created on a normal drawing surface. Because the bitmap is compatible with the 
device, a memory DC is also sometimes referred to as a compatible device 
context. 
為了能夠讓應(yīng)用程序在內(nèi)存中而不是在實(shí)際設(shè)備中繪圖,使用一種稱作內(nèi)存設(shè)備內(nèi)容(memory device 
context)的特殊設(shè)備內(nèi)容來針對(duì)位圖操作。內(nèi)存DC允許系統(tǒng)分配一部分內(nèi)存來作為虛擬DC,內(nèi)存DC是應(yīng)用程序可以臨時(shí)為在普通繪圖區(qū)域創(chuàng)建的位圖保存色彩數(shù)據(jù)而在內(nèi)存中保存的一系列的比特。由于位圖和設(shè)備是兼容的,所以一個(gè)內(nèi)存DC有時(shí)也被稱作兼容設(shè)備內(nèi)容。
The memory DC stores bitmap images for a particular device. An application 
can create a memory DC by calling the CreateCompatibleDC function. 
內(nèi)存DC為特定的設(shè)備保存位圖,一個(gè)應(yīng)用程序可以通過調(diào)用CreateCompatibleDC函數(shù)創(chuàng)建一個(gè)內(nèi)存DC。
關(guān)于CreateCompatibleDC函數(shù):
A memory DC exists only in memory. When the memory 
DC is created, its display surface is exactly one monochrome pixel wide and one 
monochrome pixel high. Before an application can use a memory DC for drawing 
operations, it must select a bitmap of the correct width and height into the DC. 
To select a bitmap into a DC, use the CreateCompatibleBitmap function, 
specifying the height, width, and color organization required. 
內(nèi)存DC只在內(nèi)存中存在。當(dāng)一個(gè)內(nèi)存DC被創(chuàng)建時(shí),它的顯示區(qū)域只有一個(gè)像素寬一個(gè)像素高。在一個(gè)應(yīng)用程序使用內(nèi)存DC進(jìn)行繪圖操作之前,必須選入一副正確高度和寬度的位圖到內(nèi)存DC中。為了選入一副位圖到內(nèi)存DC中,可以使用CreateCompatibleBitmap函數(shù)。使用CreateCompatibleBitmap函數(shù),指定所需位圖的高度,寬度和色彩組織。
When 
a memory DC is created, all attributes are set to normal default values. The 
memory DC can be used as a normal DC. You can set the attributes; obtain the 
current settings of its attributes; and select pens, brushes, and 
regions.
當(dāng)一個(gè)內(nèi)存DC被創(chuàng)建之后,所有的屬性都被設(shè)置為默認(rèn)屬性。內(nèi)存DC可以像普通的DC那樣使用。你可以設(shè)置屬性,獲得當(dāng)前的設(shè)置或者當(dāng)前屬性,并且可以選入筆,畫刷和區(qū)域。
The original bitmap in a memory DC is simply a placeholder. Its dimensions 
are one pixel by one pixel. Before an application can begin drawing, it must 
select a bitmap with the appropriate width and height into the DC by calling the 
SelectObject function. To create a bitmap of the appropriate dimensions, use the 
CreateBitmap, CreateBitmapIndirect, or CreateCompatibleBitmap function. After 
the bitmap is selected into the memory DC, the system replaces the single-bit 
array with an array large enough to store color information for the specified 
rectangle of pixels.
內(nèi)存DC中最初的位圖只是簡(jiǎn)單的一個(gè)放置場(chǎng)所。它的只有1 x 
1大小,在一個(gè)應(yīng)用程序開始繪圖之前,必須通過SelectObject函數(shù)選入一個(gè)適當(dāng)高度和寬度大小的位圖到內(nèi)存DC中。如果想要?jiǎng)?chuàng)建一個(gè)合適大小的位圖,可以使用 
CreateBitmap, CreateBitmapIndirect, 或者CreateCompatibleBitmap 
函數(shù)。當(dāng)一個(gè)位圖被選入到內(nèi)存DC中,系統(tǒng)會(huì)使用能夠保存特定大小的色彩信息的足夠大的數(shù)組來替換原先單獨(dú)位數(shù)的數(shù)組。
CreateCompatibleBitmap函數(shù):
Note: When a memory device context is created, 
it initially has a 1-by-1 monochrome bitmap selected into it. If this memory 
device context is used in CreateCompatibleBitmap, the bitmap that is created is 
a monochrome bitmap. To create a color bitmap, use the hDC that was used to 
create the memory device context, as shown in the following code:
注意:當(dāng)一個(gè)內(nèi)存DC被創(chuàng)建時(shí),它最初只有一個(gè)1X1的單色位圖在里面,如果這個(gè)內(nèi)存DC被CreateCompatibleBitmap函數(shù)使用的話,返回的位圖就只能是單色的。所以為了創(chuàng)建一個(gè)彩色的位圖,就要使用創(chuàng)建內(nèi)存DC時(shí)所使用的hDC來創(chuàng)建。就像以下代碼一樣:
    HDC memDC = CreateCompatibleDC ( hDC );
    HBITMAP memBM = 
CreateCompatibleBitmap ( hDC, nWidth, nHeight );//注意這里的hDC就是創(chuàng)建內(nèi)存DC時(shí)使用的DC
    
SelectObject ( memDC, memBM );
When an application passes the handle returned by CreateCompatibleDC to one 
of the drawing functions, the requested output does not appear on a device's 
drawing surface. Instead, the system stores the color information for the 
resultant line, curve, text, or region in the array of bits. The application can 
copy the image stored in memory back onto a drawing surface by calling the 
BitBlt function, identifying the memory DC as the source device context and a 
window or screen DC as the target device context.
當(dāng)應(yīng)用程序把通過CreateCompatibleDC函數(shù)返回的句柄傳遞到繪圖函數(shù)中,請(qǐng)求的輸出并不是在設(shè)備的繪圖表面上,相反,系統(tǒng)會(huì)把響應(yīng)的直線,弧線,文本的色彩信息保存到內(nèi)存中。應(yīng)用程序可以使用BitBlt函數(shù)從內(nèi)存中把圖像復(fù)制到一個(gè)繪圖表面,把內(nèi)存DC作為源DC,窗口或者屏幕DC作為目標(biāo)DC。
所有,截取屏幕的代碼應(yīng)為(在WM_PAINT消息的處理過程中添加):
   hdc = BeginPaint(hWnd, 
&ps);
   HDC hMemDC;
   HDC hScreenDC;
   HBITMAP hBitmap;
   
HBITMAP bitmap;
   hMemDC=CreateCompatibleDC(hdc);
   
hBitmap=CreateCompatibleBitmap(hdc,1024,768);
   
SelectObject(hMemDC,hBitmap);
  
   //獲取屏幕DC,并且將屏幕DC的內(nèi)容復(fù)制到內(nèi)存DC中
   
hScreenDC=GetDC(NULL);
   
BitBlt(hMemDC,0,0,1024,768,hScreenDC,0,0,SRCCOPY);
   
//將內(nèi)存DC復(fù)制到窗體的DC中,在窗體中顯示屏幕內(nèi)容
   
BitBlt(hdc,0,0,1024,768,hMemDC,0,0,SRCCOPY);
   //創(chuàng)建一個(gè)兼容位圖來保存內(nèi)存DC中的圖像
   
hBitmap=CreateCompatibleBitmap(hdc,1024,768);
   
bitmap=(HBITMAP)SelectObject(hMemDC,hBitmap);
   //將位圖放入剪貼板
   
OpenClipboard(hWnd);
   EmptyClipboard();
   
SetClipboardData(CF_BITMAP,bitmap);
   CloseClipboard();
   //釋放DC
   
ReleaseDC(NULL,hScreenDC);
   DeleteDC(hMemDC);
   EndPaint(hWnd, 
&ps);