Very top of window gets cut off in image capture on Windows 7
We have some code inside our application that captures an image of a w开发者_Go百科indow and saves it to a PNG file and copies it to the clipboard (C++ API code).
Works perfectly on Windows XP. It also works on Windows 7, except that it looks as if the top few pixel lines of the image have been chopped off, as if the area that was captured did not include the top few lines of the window. Yet our code clearly copies from the top of the image, shown below.
(On Windows XP you see the full X on the right hand side plus the top border of the Window)
Is this some aero or other display effect on Windows 7, or is there a way to compensate for this?Or could something in our code possibly be causing this?
Sure, we can determine the window area and capture it from the client window, and capture a few lines higher up, but how may lines, and that seems arbitrary.
There must be some fundamental flaw or issue here?
Our code is roughly as follows:
RECT wndRect;
GetWindowRect(hwnd, &wndRect);
int Width = wndRect.right - wndRect.left;
int Height = wndRect.bottom - wndRect.top;
BYTE *pBits = 0;
BITMAPINFO bmpinfo = {sizeof(BITMAPINFO)};
bmpinfo.bmiHeader.biWidth = Width;
bmpinfo.bmiHeader.biHeight = Height;
bmpinfo.bmiHeader.biPlanes = 1;
bmpinfo.bmiHeader.biBitCount = 24;
bmpinfo.bmiHeader.biCompression = BI_RGB;
HBITMAP hBmp = CreateDIBSection(NULL, &bmpinfo, DIB_RGB_COLORS, (void**)&pBits, NULL, 0);
HDC hWndDC = GetWindowDC(hwnd);
HDC hDC = CreateCompatibleDC(hWndDC);
HBITMAP hOldBmp = (HBITMAP)SelectObject(hDC, hBmp);
BitBlt(hDC, 0, 0, Width, Height, hWndDC, 0, 0, SRCCOPY);
I read once that the RECT coords cut off the bottom pixel but never heard of the top pixel...There may be some api call somewhere to get the size of the window decoration or what not.
GetDCEx might help as well.
精彩评论