简体   繁体   中英

Winapi and half fadeout window

I want to fade out window using winapi in c++. I want to make the effect like windows when they are not responsible. They are become then whole gray and half transparent. I'm trying to do it using

AnimateWindow(hwnd, 1000, AW_BLEND | AW_HIDE);

but this make the window hide becouse of paramether AW_HIDE and I want to fade out for example only for 70%. Is there any way to do it using animate window or maybe I can do it another way?

您可以看一下UpdateLayeredWindow

This code changes the opacity of window, when WM_LBUTTONUP event occur. If you want to animate for 'fade out' effect, using Timer can be an effective method. In WM_TIMER handler, change the alpha_value which is third parameter of ::SetLayeredWindowAttributes() .

LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    PAINTSTRUCT ps;
    HDC hdc;
    LONG extend_style;
    BYTE alpha_value;

    switch (message)
    {
    case WM_COMMAND:
        ...
        break;
    case WM_LBUTTONUP:

        extend_style = ::GetWindowLong(hWnd, GWL_EXSTYLE );
        ::SetWindowLong(hWnd, GWL_EXSTYLE, extend_style | WS_EX_LAYERED );

        //0 ~ 255(Transparent Range, 0 is completely transparent)       
        alpha_value = 100; 

        ::SetLayeredWindowAttributes(hWnd, 0, alpha_value, LWA_ALPHA);

        break;
    case WM_PAINT:
         ...
         break;
    case WM_DESTROY:
        PostQuitMessage(0);
        break;
    default:
        return DefWindowProc(hWnd, message, wParam, lParam);
    }
    return 0;
}

I hope this will help you a little.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM