This question may be a bit of a mouthful. I would like to access any windows application that a user launch that has some UI, and re-render those windows in a game engine (each window on its own texture). In essence, I am trying to cast every application running on my machine into a 3D world (onto their own Texture).
I am using Unity and found a workaround to obtain this behavior using WIN32 API, but it comes with major caveat:
- I use EnumWindows() to get the list of Windows - unfortunately lots of Windows without UI get iterated
- For each Window, a script containing the Window coordinate (using GetWindowRect()) is called
- Each script then calls GetForegroundWindow() to figure out if this Window is being manipulated with from the user. If so, it accesses the frame buffer by calling Graphics CopyFromScreen() and using the position returned from GetWindowRect()
Essentially, when the user interacts with a Window, I copy the part of the screen where the window is located, and when the user does not interact with an application Window, he essentially has a screenshot.
Issues are that:
- EnumWindows() return windows that do not have UI (EDIT: solution here is pretty great and fixed this issue)
- If a Window refreshes its content (like a video playing), I will not refresh in time
- I have to call EnumWindows() over and over to figure out if a new Window has been created
- It also breaks if part of the Window is located partly outside the screen
- If two windows are on top of each other, it breaks
Is there a better way to access the rendering of every app on Windows, or is the partial screen capture the best solution for my case please?