6

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.

3 Answers 3

2

One way to do it is to use double-buffering technique: paint to an off-screen bitmap, then restore, then blit the bitmap to the screen. But it seems like overkill if restoring a minimized window is the only scenario where it's needed. Maybe others will have better ideas?..

Also, if you paint entire window client area, you can disable WM_ERASEBKGND (or rather, say that you processed it but don't do anything) to avoid unneeded fill-with-background-then-redraw sequence.

1

This link on MSDN will explain how you would want to handle the window painting in your case. Window events like window refresh or minimize/maximize will require repainting of your window or a region of the window.

Happy Coding!!

0

I'm OP...accidentaly ate my cookie.

Studied how windows flip3d and the taskbar manages this a bit closer and they actually repaint the window before they start the animation of the thumb. Try to minimize a window and then restore it with flip3d, you will see a small blink on the 3d-window before it get restored.

Tried the same thing with my app and it looks alot better, not perfect but acceptable :/