|
BitBlt 函數(shù)用于在設(shè)備間傳遞某塊像素,例如向窗口表面呈現(xiàn)位圖,或是復(fù)制屏幕 (截屏) 。
這篇文字講述了復(fù)制屏幕過(guò)程中需要注意的問(wèn)題。 基本過(guò)程: 創(chuàng)建源設(shè)備上下文 (hDC = CreateDC,GetDC,GetWindowDC) 。 創(chuàng)建兼容的設(shè)備上下文 (hMemDC = CreateCompatibleDC) 。 創(chuàng)建兼容位圖 (hBmp = CreateCompatibleBitmap) 。 將 hBmp 選入 hMemDC (hOldBmp = SelectObject) 。 進(jìn)行拷貝 (BitBlt) 。 將 hOldBmp 還原給 hMemDC (hBmp = SelectObject) 。 刪除釋放設(shè)備上下文 (DeleteDC,ReleaseDC) 。 一般在 BitBlt 過(guò)程中指定 SRCCOPY 形式的光柵操作,這樣做沒(méi)有錯(cuò),事實(shí)上也得到了當(dāng)前屏幕的拷貝,現(xiàn)在觀察下面兩幅圖像: ![]() 這是整個(gè)屏幕的一部分,左邊的圖像指定了 SRCCOPY ,右邊的圖像似乎多了點(diǎn)東西,那是上下文菜單的陰影,截獲這層陰影需要用 CAPTUREBLT 與 SRCCOPY 合并。 CAPTUREBLT: Includes any windows that are layered on top of your window in the resulting image. By default, the image only contains your window. Note that this generally cannot be used for printing device contexts. (生成的圖像中包含您的窗口上層疊的那些窗口。默認(rèn)情況下,該圖像僅包含您的窗口。請(qǐng)注意,這通常無(wú)法用于打印設(shè)備上下文。) 另外,如果不使用 CAPTUREBLT 光柵操作,結(jié)果將不會(huì)包含透明度 < 255 的窗口。 C Code - : HDC hDC, hMemDC; HANDLE hBmp, hOldBmp; DWORD w, h; w = GetSystemMetrics(SM_CXSCREEN); h = GetSystemMetrics(SM_CYSCREEN); hDC = CreateDC("DISPLAY", NULL, NULL, NULL); hMemDC = CreateCompatibleDC(hDC); hBmp = CreateCompatibleBitmap(hDC, w, h); hOldBmp = SelectObject(hMemDC, hBmp); BitBlt(hMemDC, 0, 0, w, h, hDC, 0, 0, CAPTUREBLT | SRCCOPY); hBmp = SelectObject(hMemDC, hOldBmp); DeleteDC(hDC); DeleteDC(hMemDC); |
|
|