简体   繁体   English

Winapi和半淡出窗口

[英]Winapi and half fadeout window

I want to fade out window using winapi in c++. 我想使用c ++中的winapi淡出窗口。 I want to make the effect like windows when they are not responsible. 当它们不负责任时,我想使效果像Windows。 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%. 但这会因为AW_HIDE参数使窗口隐藏起来,因此我只想淡出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. 发生WM_LBUTTONUP事件时,此代码更改窗口的不透明度。 If you want to animate for 'fade out' effect, using Timer can be an effective method. 如果要动画化“淡出”效果,则使用Timer是一种有效的方法。 In WM_TIMER handler, change the alpha_value which is third parameter of ::SetLayeredWindowAttributes() . WM_TIMER处理程序中,更改alpha_value,它是::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. 希望对您有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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