I've made an expose-clone for Vista that sometimes need to restore a minimized window. I've managed to do this with the SetWindowPlacement function. The problem is that this also repaints the window which looks like crap after the window nicely has slided into the screen.
This is the code i use to bring a window to the top and give it focus:
private static void ActivateWindow(IntPtr windowToShow)
{
RectAPI r = new RectAPI();
Win32.GetWindowRect(windowToShow, ref r);
if (r.top == -32000) //r.top is -32000 if the window is in minimized state
{
WINDOWPLACEMENT wp = new WINDOWPLACEMENT();
Win32.GetWindowPlacement(windowToShow, ref wp);
if (wp.flags == WindowPlacementFlags.WPF_RESTORETOMAXIMIZED)
wp.showCmd = cmdShow.SW_SHOWMAXIMIZED;
else
wp.showCmd = cmdShow.SW_RESTORE;
Win32.SetWindowPlacement(windowToShow, ref wp);
}
Win32.SetForegroundWindow(windowToShow);
}
If i use it on a window that is already restored it will only call SetForegroundWindow and the window will get to the top of the z-order and get focus without any flicker.
But if i call it on a minimized window I also have to use SetWindowPlacement to bring back the window to restored state. This is what causes the window to repaint and flicker :/
There has to be a way to restore a minimized window without the flicker because the built in window manager does this.