C++ 如何用c++;

C++ 如何用c++;,c++,windows,direct3d,C++,Windows,Direct3d,我尝试使用gdi来捕获特定的窗口,对于大多数窗口来说都没问题。 但对于某些窗口,如“VisualStudio代码”,它不起作用。 DX无法支持捕获特定窗口。 我该怎么办?谢谢 ::EnumWindows(EnumWindowsProc, NULL); if (hCapWnd == NULL) { return FALSE; } SwitchToThisWindow(hCapWnd, true); Sleep(1000); /

我尝试使用gdi来捕获特定的窗口,对于大多数窗口来说都没问题。 但对于某些窗口,如“VisualStudio代码”,它不起作用。 DX无法支持捕获特定窗口。 我该怎么办?谢谢

    ::EnumWindows(EnumWindowsProc, NULL);
    if (hCapWnd == NULL)
    {
        return FALSE;
    }
    SwitchToThisWindow(hCapWnd, true);
    Sleep(1000);
    //HWND hDesktopWnd = GetDesktopWindow();
    HDC hDesktopDC = GetWindowDC(hCapWnd);
    HDC hCaptureDC = CreateCompatibleDC(hDesktopDC);
    SetStretchBltMode(hCaptureDC, COLORONCOLOR);
     RECT rc;
    ::GetWindowRect(hCapWnd, &rc);
    int width = rc.right - rc.left;
    int height = rc.bottom - rc.top;
     HBITMAP hCaptureBitmap = CreateCompatibleBitmap(hDesktopDC, width, height);
     SelectObject(hCaptureDC, hCaptureBitmap);
     BOOL bRet = BitBlt(hCaptureDC, 0, 0, width, height, hDesktopDC, 0, 0, SRCCOPY);
     Init(width, height);
     int nRet = GetDIBits(hCaptureDC, hCaptureBitmap, 0, height, buf, (BITMAPINFO*)&m_bitmapInfo, DIB_RGB_COLORS);

    static int n = 0;
    //if (n++ % 10 == 0) 
    {
       // std::string name = ustd::format_string("%s\\%d.bmp", ustd::get_program_path().c_str(), n);
        SaveBitmapToFile(hCaptureBitmap);
    }

    ReleaseDC(hCapWnd, hDesktopDC);
    DeleteDC(hCaptureDC);
    DeleteObject(hCaptureBitmap);