BOOL CTestKEYDlg::OnEraseBkgnd(CDC* pDC){// TODO: Add your message handler code here and/or call defaultCDialog::OnEraseBkgnd(pDC);HBITMAP h_bitMap;h_bitMap = SHLoadImageFile(L"bg.gif");if(h_bitMap == NULL){return false;}BITMAP bm;GetObject(&h_bitMap,sizeof(HBITMAP),&bm);/*為一個圖片賦值。*/HDC hDc = CreateCompatibleDC(pDC->GetSafeHdc());/*記憶體中的DC是僅僅儲存在記憶體中的。當一個DC被建立的時候,它的外觀(顯示模式)只是一個象素大小。所以,在應用程式使用DC之前,要先將一個大小合適的圖片用"CreateCompatiableBitmap"“選擇”到記憶體中,這樣DC的大小就是圖片的大小。當記憶體中的一個DC被建立的時候,所有的屬性都是預設值 ,如果想把它當做一個普通的DC,使用者必須設定它的屬性,獲得當前的設定,和當前選中的畫圖用的畫筆、畫刷,的地區的大小。CreateCompatibleDC函數只能用於支援光柵操作的裝置。應用程式是否支援光柵操作,可以用"GetDeviceCaps"函數來獲得。當DC使用完後,用DeleteDC去銷毀這個DC。*//*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. 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.The CreateCompatibleDC function can only be used with devices that support raster operations. An application can determine whether a device supports these operations by calling the GetDeviceCaps function. When you no longer need the memory DC, call the DeleteDC function. */HBITMAP hOldBmp = NULL;hOldBmp = (HBITMAP)SelectObject(hDc,&h_bitMap);/*儲存原先的圖片資訊,以便恢複。(用完後,需要對系統的資訊進行恢複)*//*This function returns the previously selected object of the specified type. An application should always replace a new object with the original, default object after it has finished drawing with the new object. */CRect rect;GetClientRect(&rect);/*擷取當前客戶區的大小。*/StretchBlt(pDC->GetSafeHdc(),rect.left,rect.top,rect.Width(),rect.Height(),hDc,0,0,bm.bmWidth,bm.bmHeight,SRCCOPY);/*Draw the Picture .*/SelectObject(hDc,hOldBmp);DeleteDC(hDc);hDc = NULL;if(h_bitMap != NULL){DeleteObject(h_bitMap);}return TRUE;}