我希望有一个透明窗口,它只有边框而不是捕获它(并查看它背后的所有窗口 - 因为它是透明的)到位图。 我设法创建透明窗口,但是当我尝试捕获它时,它不再是透明的,我得到它的原始背景。
这是我到目前为止所拥有的,
创建窗口:
//registering the window class with white backgournd
WNDCLASSEX wcex;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = ScreenCaptureROIWinProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = _WPModule.GetHInstance();
wcex.hIcon = NULL;
wcex.hCursor = NULL;
wcex.hbrBackground = CreateSolidBrush(0x00FFFFFF);//white brush;
wcex.lpszMenuName = NULL;
wcex.lpszClassName = g_lpszClassName;
wcex.hIconSm = NULL;
RegisterClassEx(&wcex);
//creating a layered window
m_hWnd = CreateWindowEx(WS_EX_CLIENTEDGE | WS_EX_LAYERED,g_lpszClassName, NULL,
WS_THICKFRAME, CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL,
NULL, hInstance(), NULL);
// Set white brushed sections of the window to be transparent
SetLayeredWindowAttributes(m_hWnd, 0x00FFFFFF, 0, LWA_COLORKEY);
捕捉窗口:
RECT ROIRect;
GetWindowRect(m_hWnd,ROIRect);
HDC hdcScreen = GetDC(m_hWnd);
HDC hdcMem = CreateCompatibleDC(hdcScreen);
BitBlt(
hdcMem,
0,
0,
ROIRect.right - ROIRect.left, //width of window
ROIRect.bottom - ROIRect.top, //height of window
hdcScreen,
0,
0,
SRCCOPY);