smasherprog / screen_capture_lite

cross platform screen/window capturing library
MIT License
616 stars 156 forks source link

draw mouse pointer on every new frame #75

Closed xfirefly closed 4 years ago

xfirefly commented 4 years ago

Thank you for this amazing project. I use the data which is received from callback framgrabber.onNewFrame() to feed to ffmpeg to generate a h.264 video. It works OK.

But I encountered a problem when drawing the mouse pointer. Can you help me, please?

in GDIFrameProcessor.cpp, Not working

        if (Width(currentmonitorinfo) == Width(SelectedMonitor) && Height(currentmonitorinfo) == Height(SelectedMonitor)) {
            DeviceContext->CopyResource(StagingSurf.Get(), aquireddesktopimage.Get());
+         drawCursor();
        }
        else {
    void DXFrameProcessor::drawCursor( ) {
        Microsoft::WRL::ComPtr<IDXGISurface1> surface1;
        auto hr = StagingSurf->QueryInterface(__uuidof(IDXGISurface1), reinterpret_cast<void **>(surface1.GetAddressOf()));
        if (FAILED(hr))
        {
            return  ;
        }

        CURSORINFO cursorInfo = { 0 };
        cursorInfo.cbSize = sizeof(CURSORINFO);
        if (GetCursorInfo(&cursorInfo) == TRUE)
        {
            if (cursorInfo.flags == CURSOR_SHOWING)
            {
                auto cursorPosition = cursorInfo.ptScreenPos;
                auto lCursorSize = cursorInfo.cbSize;
                HDC  hdc;
                surface1->GetDC(FALSE, &hdc);
                DrawIconEx(hdc, cursorPosition.x, cursorPosition.y, cursorInfo.hCursor, 0, 0, 0, 0, DI_NORMAL | DI_DEFAULTSIZE);
                surface1->ReleaseDC(nullptr);
            }
        }
    }
smasherprog commented 4 years ago

I have found drawiconex to be difficult to work with so i am unsure why its not working.

smasherprog commented 4 years ago

Maybe this might help? https://docs.microsoft.com/en-us/windows/win32/direct3ddxgi/desktop-dup-api#updating-the-desktop-pointer

xfirefly commented 4 years ago

Thank you for your kind reply. I will try to fix