I am moving a window (belonging to another process) to the front in order to take a screenshot of it. I am able to do this using SetForegroundWindow
, however that function returns immediately. The other process takes a varying amount of time to redraw its main window (which requires it to access a database) so I cannot be sure that when I take the screenshot the window is fully rendered. Sometimes all I get in the screenshot is the outline of the target window, on top of whatever window was previously in the foreground.
Is there a reliable way to wait until another process's window is fully painted? I suspect there isn't but it's worth a shot. Maybe there's a message I can send to the window that will have this effect?
Note: The implementation language is not important but I need a solution using the native Windows API, either directly from C/C++ code or via P/Invoke (e.g. from C# or VB.NET). Unfortunately I cannot use any WinForms functions.