Java – get screenshot of StartMenu
•
Java
I'm using BitBlt to capture a window If aviation theme is enabled, the background of the captured image is black If I disable DWM and capture the window, the captured image is very good
This is part of my code
HDC hdcMemDC = GDI32.INSTANCE.CreateCompatibleDC(desktopDC); HDC windowDC = User32.INSTANCE.GetDC(window); HWND window= User32Extra.INSTANCE.FindWindow(null,"Start menu"); GDI32Extra.INSTANCE.BitBlt(hdcMemDC,width,height,desktopDC,WinGDIExtra.SRCCOPY ); GDI32Extra.INSTANCE.BitBlt(hdcMemDC,windowBounds.left,windowBounds.top,windowWidth,windowHeight,windowDC,windowBounds.left+windowBounds1.right-windowBounds.right+(windowExtraGap/2),windowBounds.top+windowBounds1.bottom-windowBounds.bottom+(windowExtraGap/2),WinGDIExtra.SRCCOPY);
How do I capture the start menu with the appropriate background?
Is there any other way to obtain appropriate aerial window images?
Solution
Use desktop DC and cut to window
RECT rc,rc2; GetClientRect(hWnd,&rc); GetWindowRect(hWnd,&rc2); int width = rc2.right - rc2.left; int height = rc2.bottom - rc2.top; HDC hdcScreen = GetDC(NULL); //!!!! Get desktop DC HDC hBmpFileDC = CreateCompatibleDC(hdcScreen); HBITMAP hBmpFileBitmap = CreateCompatibleBitmap(hdcScreen,height); HBITMAP hOldBitmap = (HBITMAP)SelectObject(hBmpFileDC,hBmpFileBitmap); BitBlt(hBmpFileDC,hdcScreen,rc2.left,rc2.top,SRCCOPY | CAPTUREBLT); HGdioBJ prev = SelectObject(hBmpFileDC,hOldBitmap); SaveBitmap(szLogFilename,hBmpFileBitmap); DeleteDC(hBmpFileDC); DeleteObject(hBmpFileBitmap);
Another variant
RECT rc; GetClientRect(hWnd,&rc); int width = rc.right - rc.left; int height = rc.bottom - rc.top; HDC hdcScreen = GetDC(hWnd); //////////////////////////// PrintWindow(hWnd,0); PrintWindow(hWnd,PW_CLIENTONLY); //////////////////////////// HDC hBmpFileDC = CreateCompatibleDC(hdcScreen); HBITMAP hBmpFileBitmap = CreateCompatibleBitmap(hdcScreen,hBmpFileBitmap); DeleteDC(hBmpFileDC); DeleteObject(hBmpFileBitmap);
I call printwindow before calling any capture methods It is used to redraw its own window Therefore, the screenshot will have the correct picture I get the most stable result through the double call of printwindow
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码