0
votes

I am completely new to DirectX. But I am using it into my screen capture application. I am capturing the screen using desktop duplication API. Now I want to update the cursor information, instead of the original cursor I want to give custom cursor (custom cursor could be any shape). Please help me out how to do that?

I have PTR_INFO(this contain the position of the pointer, DXGI_OUTDUPL_POINTER_SHAPE_INFO), ID3D11DeviceContext, ID3D11Device and ID3D11Texture2D on which I want to perform this operation.

Thanks in advance.

1

1 Answers

1
votes

I found the solution for this. I am trying to explain it below:

First, get the DXGISurface by using:

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

Next step is to make an object for CURSORINFO to store the information about the cursor:


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);
    }
}