这个问题困扰我1天了, 还没搞定 [已经搞定]
把桌面dc贴到内存dc, 然后把内存dc贴到窗口dc, 结果得到的图片是黑白色的, 程序如下程序代码:
#include <windows.h> #include <conio.h> int main (void) { HWND hWnd; HDC hdc; HDC hdcWnd; HDC hdcMem; HBITMAP hBmp; RECT rect; int iScrWidth, iScrHeight; iScrWidth = GetSystemMetrics (SM_CXSCREEN); iScrHeight = GetSystemMetrics (SM_CYSCREEN); hWnd = GetForegroundWindow (); GetClientRect (hWnd, &rect); hdc = CreateDC ("DISPLAY", NULL, NULL, NULL); hdcMem = CreateCompatibleDC (hdc); hBmp = CreateCompatibleBitmap (hdcMem, iScrWidth, iScrHeight); SelectObject (hdcMem, hBmp); BitBlt (hdcMem, 0, 0, iScrWidth, iScrHeight, hdc, 0, 0, SRCCOPY); hdcWnd = GetDC (hWnd); BitBlt (hdcWnd, 0, 0, rect.right, rect.bottom, hdcMem, 0, 0, SRCCOPY); ReleaseDC (hWnd, hdcWnd); getch (); DeleteObject (hBmp); DeleteDC (hdcMem); DeleteDC (hdc); return 0; } 如果不经过内存dc这个间接的过程, 直接把桌面dc贴到窗口dc上, 就可以得到预期效果, 程序如下
程序代码:
#include <windows.h> #include <conio.h> int main (void) { HWND hWnd; HDC hdc; HDC hdcWnd; RECT rect; int iScrWidth, iScrHeight; iScrWidth = GetSystemMetrics (SM_CXSCREEN); iScrHeight = GetSystemMetrics (SM_CYSCREEN); hWnd = GetForegroundWindow (); GetClientRect (hWnd, &rect); hdc = CreateDC ("DISPLAY", NULL, NULL, NULL); hdcWnd = GetDC (hWnd); BitBlt (hdcWnd, 0, 0, rect.right, rect.bottom, hdc, 0, 0, SRCCOPY); getch (); ReleaseDC (hWnd, hdcWnd); DeleteDC (hdc); return 0; }
我的疑惑: 为什么经过内存dc后的图片, 会成为黑白色的?, 怎么解决这个问题
[ 本帖最后由 瓦药墙 于 2011-1-13 15:25 编辑 ]