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

问题描述 投票:0回答:1

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

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

谢谢。

c++ graphics gpu directx dda
1个回答
0
投票

我找到了解决方案。我想在下面解释一下:

首先,使用以下命令获得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);
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.