I have written a Win32 C++ program.
I would like to duplicate the visual content of the left window every frame, so it appears at another location on the screen. (One rectangle on the left side of the screen, and an identical rectangle on the right side of the screen.)
This is for stereo rendering, where the left rectangle is seen in the user's left eye, and the right rectangle in the right eye.
The two rectangles must be "frame synced", meaning that they must show the same frame at all times. Or to put it another way, if the right eye is behind the left by "one draw call", then the viewer becomes ill.
NOTE: I have the source code to both windows, because I created them. (Both windows reside within the same exe at the moment.)
What I have tried:
Potential Solutions:
In the left-window's WM_PAINT message, draw both windows with the same contents. Is this possible somehow?
Use one, single giant window to draw both rectangles. This would mean all drawing occurs in the same WM_PAINT call. However, I do not know how to copy part of a window to another part. I wish I could just tell Win32 to 'draw again', but this time start 1000 pixels to the right...
Do "something" with DirectX. (No idea what.)
Any help would be greatly appreciated!
I don’t know if you still need an answer, but I don’t think you can do it better than using the DWM Thumbnails API [1]. You basically do an association of a region on your window <-> a region of a foreign window, and then each time the windows are composed and presented on the screen, the specified rectangle of the foreign window will be painted on the specified rectangle of your window. DWM will do scaling if necessary and you can also specify a transparency level. This is the most efficient way to do it, as the compositor does all the heavy lifting, so it is at the lowest level you could go without writing kernel mode code (custom drivers etc). You can’t draw on top, and won’t “see” the foreign window data on your window if you BitBlt it for example, as the image is not actually drawn on your window, but overlaid on top when the final image of your window is composed and presented to the user by the window manager. But for most purposes, it works really well.
[1] https://learn.microsoft.com/en-us/windows/win32/dwm/thumbnail-ovw