又一個修改對話方塊背景顏色

來源:互聯網
上載者:User
 

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;}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.