【发布时间】:2012-02-01 20:53:40
【问题描述】:
此代码试图在光标周围最大 100x100 的框中捕获绘制在窗口上的图像。 BitBlt 在这里的任何一个位置都没有返回 0,我很确定问题出在 BitBlt 的第一个函数调用上,我试图将图像从窗口的背景复制到 meta,这是一个全局声明的 HDC .除了尝试完全在内存中创建 HDC 之外,我还尝试创建并加载空白位图并将新图像捕获到与之关联的句柄中,但所做的只是像橡皮擦一样画一个白框移动时围绕光标。相关代码如下,mouseRect 和 clientRect 分别是与光标周围的框和客户矩形相关的全局变量。任何帮助表示赞赏,谢谢!
case WM_CREATE:
hInstance = ((LPCREATESTRUCT) lParam)->hInstance;
GetClientRect(hWnd, &clientRect);
hdc = GetDC(hWnd);
meta = CreateCompatibleDC(hdc);
return 0;
case WM_MOUSEMOVE:
x = LOWORD(lParam);
y = HIWORD(lParam);
hdc = GetDC(hWnd);
BitBlt(hdc, mouseRect.left, mouseRect.top, mouseRect.right-mouseRect.left, mouseRect.bottom-mouseRect.top, meta, 0, 0, SRCCOPY);
ReleaseDC(hWnd, meta);
meta = CreateCompatibleDC(hdc);
if(y<50)
mouseRect.top = 0;
else
mouseRect.top = y-50;
if(x<50)
mouseRect.left = 0;
else
mouseRect.left = x-50;
if(clientRect.right-x<50)
mouseRect.right = clientRect.right;
else
mouseRect.right = x+50;
if(clientRect.bottom-y<50)
mouseRect.bottom = clientRect.bottom;
else
mouseRect.bottom = y+50;
BitBlt(meta, 0, 0, mouseRect.right-mouseRect.left, mouseRect.bottom-mouseRect.top, hdc, mouseRect.left, mouseRect.top, SRCCOPY);
ReleaseDC(hWnd, hdc);
return 0;
【问题讨论】: