Hi @Alex Chashka ,
Thanks for sharing your details!
You're right, I couldn't find a single official Microsoft document that explains why Composition visuals lag during live window dragging or how to fix it. The existing docs cover the individual pieces (Graphics Capture APIs, Composition basics, window messages), but they don’t combine them into a guide for real-time mirroring.
As far as I can tell, the delay probably happens because EVENT_OBJECT_LOCATIONCHANGE fires slowly and sometimes in batches. It’s great for accessibility, but not for per-frame updates. Also, if your update logic runs on the UI thread, Windows pauses that thread during a drag, which adds more lag.
I would suggest these workarounds first:
Use live move messages instead of LOCATIONCHANGE.
Update your visuals on WM_MOVING (fires repeatedly while dragging), and use WM_ENTERSIZEMOVE / WM_EXITSIZEMOVE to know when drag starts and ends.
Reference: WM_MOVING
Make capture independent of the UI thread.
Create your frame pool with CreateFreeThreaded so frame updates don’t wait for the dispatcher.
Reference: CreateFreeThreaded
Get accurate bounds during drag.
Use DwmGetWindowAttribute with DWMWA_EXTENDED_FRAME_BOUNDS instead of GetWindowRect to avoid invisible borders and “snap” corrections.
Reference: DWM bounds
The GitHub sample you linked shows how to capture and display a window, but it doesn’t include live movement logic.
I also managed to find some related post regarding this issue, please do check it out when you have the time:
- https://stackoverflow.com/questions/79498679/problems-with-windows-graphics-capture
- https://stackoverflow.com/questions/28195487/why-does-setwineventhook-with-event-object-locationchange-trigger-on-mouse-movem
- https://stackoverflow.com/questions/18552487/determining-when-a-wpf-window-is-being-moved
- https://stackoverflow.com/questions/34139450/getwindowrect-returns-a-size-including-invisible-borders
If you are in a hurry, you could report an issue straight to the creator of the example you are referring to at: https://github.com/robmikh/Win32CaptureSample/issues
Disclaimer: This is a non-Microsoft website. The page appears to be providing accurate, safe information. Watch out for ads on the site that may advertise products frequently classifies as a PUP (Potentially Unwanted Products). Thoroughly research any product advertised on the site before you decide to download and install it.
I hope my suggestions help! If you have any question, please feel free to comment below. I'll be happy to help!