zoukankan      html  css  js  c++  java
  • Duilib 实现右下角弹出像QQ新闻窗口,3秒后窗口透明度渐变最后关闭,若在渐变过程中鼠标放到窗口上,窗口恢复最初状态(二)

    效果:

     

    1.定义两个个定时器ID  

    #define ID_TIMER_DISPLAY_DELAY 30
    #define ID_TIMER_DISPLAY_CLOSE 40

    2.添加一个成员函数和成员变量

    void SetAlpha(HWND hWnd,int Alpha);
    
    int m_nFlag ;

    void CPopUpWnd::SetAlpha(HWND hWnd,int Alpha)
    {

      HINSTANCE hInst = LoadLibrary(L"User32.DLL");
      if(hInst)
      {
        typedef BOOL (WINAPI *MYFUNC)(HWND,COLORREF,BYTE,DWORD);
        MYFUNC fun = NULL;
       //取得SetLayeredWindowAttributes函数指针
       fun=(MYFUNC)GetProcAddress(hInst, "SetLayeredWindowAttributes");
       if(fun)fun(hWnd,0,Alpha,2);
       FreeLibrary(hInst);
       }

    }

    3.修改窗口属性

    void CPopUpWnd::OnPrepare()
    {
        //直接显示在右下角
        MoveSelfWindow();
    
        //修改窗口属性为了窗口透明度
        SetWindowLong(m_hWnd,GWL_EXSTYLE,GetWindowLong(m_hWnd,GWL_EXSTYLE)^0x80000);

         //3秒后改变窗口透明度
         SetTimer(m_hWnd,ID_TIMER_DISPLAY_DELAY,3000,NULL);

    }

    4.在定时器响应函数里

    LRESULT CPopUpWnd::OnTimer(UINT uMsg, WPARAM wParam, LPARAM lParam,BOOL& bHandled)
    {
        
    
        switch(wParam)
        {//多个定时器
        
        case ID_TIMER_DISPLAY_DELAY:
            KillTimer(m_hWnd,ID_TIMER_DISPLAY_DELAY);
            SetTimer(m_hWnd,ID_TIMER_DISPLAY_CLOSE,60,NULL);
            break;
        case ID_TIMER_DISPLAY_CLOSE:
            {
                if(m_nFlag < 255)
                {
                    m_nFlag+= 5;
                    SetAlpha(m_hWnd,255-m_nFlag);
                }
                else
                {
                    KillTimer(m_hWnd,ID_TIMER_DISPLAY_CLOSE);
                    Close(IDCLOSE);
                    m_nFlag = 0;
                }
            }
            break;
        }
        return 0;
    }

    5.窗口渐变关闭过程中,鼠标经过窗口,关闭定时器,窗口恢复原状

    LRESULT CPopUpWnd::OnMouseEnter(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
    {
    
           .....
        
        //KillTimer(m_hWnd,ID_TIMER_DISPLAY_DELAY);
        KillTimer(m_hWnd,ID_TIMER_DISPLAY_CLOSE);
        if (m_nFlag < 255)
        {
            SetAlpha(m_hWnd,255);
        }
    
          ....
    
        return 0;
    }

    6.鼠标出了窗口,开启定时器继续渐变关闭窗口

    LRESULT CPopUpWnd::OnMouseLeave(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
    {
        .....
    
        SetTimer(m_hWnd,ID_TIMER_DISPLAY_CLOSE,30,NULL);
        m_nFlag = 0;
    
           ....
        return 0;
    }
  • 相关阅读:
    代码历险记2
    入园第一天打卡 滴滴
    Spring事务传播属性介绍(三).Nested
    Spring事务内方法调用自身事务 增强的三种方式
    Spring Aop AfterReturning接收返回值
    Spring Aop 注解方式参数传递
    Spring报错:Exception in thread "main" java.lang.IllegalArgumentException at org.springframework.asm.ClassReader.<init>(Unknown Source)
    Autowired使用说明
    在Linux驱动中使用input子系统
    高通UEFI中的I2C的方式读取TP的id
  • 原文地址:https://www.cnblogs.com/chechen/p/7356754.html
Copyright © 2011-2022 走看看