在 ID3D11Texture2D 纹理上添加自定义光标

Add Custom cursor on ID3D11Texture2D texture

我对 DirectX 完全陌生。但我正在将它用于我的屏幕捕获应用程序。我正在使用桌面复制 API 捕获屏幕。现在我想更新光标信息,而不是我想给自定义光标的原始光标(自定义光标可以是任何形状)。请帮我看看该怎么做?

我有 PTR_INFO(这包含指针的位置,DXGI_OUTDUPL_POINTER_SHAPE_INFO)、ID3D11DeviceContext、ID3D11Device 和 ID3D11Texture2D,我想在其上执行此操作操作。

提前致谢。

我找到了解决方案。我试图在下面解释它:

首先,使用以下方法获取 DXGISurface:

hr =ID3D11Texture2D->QueryInterface(IID_PPV_ARGS(&lIDXGISurface1)); // ID3D11Texture2D is the catured texture

下一步是为 CURSORINFO 创建一个对象来存储有关游标的信息:


lCursorInfo.cbSize = sizeof(lCursorInfo);

auto lBoolres = GetCursorInfo(&lCursorInfo);

if (lBoolres == TRUE)
{
    if (lCursorInfo.flags == CURSOR_SHOWING)
    {
        // currently lCursorInfo.hCursor has the shape of actual cursor that is coming to your system to modify it you can use the below line

        std::string path = "cursor.cur"; // this is path to the file where .cur file available in your system
        lCursorInfo.hCursor = LoadCursorFromFileA(path.c_str());
        // You can refer https://docs.microsoft.com/en-us/windows/win32/menurc/using-cursors for creating your own cursor

        auto lCursorPosition = lCursorInfo.ptScreenPos;
        auto lCursorSize = lCursorInfo.cbSize;
        HDC  lHDC;
        lIDXGISurface1->GetDC(FALSE, &lHDC); // getting handle to draw the cursor
        // Draw the cursor
        DrawIconEx(
            lHDC,
            lCursorPosition.x,
            lCursorPosition.y,
            lCursorInfo.hCursor,
            0,
            0,
            0,
            0,
            DI_NORMAL | DI_DEFAULTSIZE);
        // Release the handle
        lIDXGISurface1->ReleaseDC(nullptr);
    }
}