zoukankan      html  css  js  c++  java
  • 窗口透明

    bool m_bTracking;   // 当鼠标被捕捉时设置为TRUE
    HWND m_hCurrWnd;    // 鼠标所在窗口的句柄
    HCURSOR m_hCursor;  // 棒型光标句柄
    // 全局变量
    typedef BOOL (WINAPI *lpfn) (HWND hWnd, COLORREF cr, BYTE bAlpha, DWORD dwFlags);
    lpfn g_pSetLayeredWindowAttributes;
        HMODULE hUser32 = GetModuleHandle(_T("USER32.DLL"));
        g_pSetLayeredWindowAttributes = (lpfn)GetProcAddress(hUser32,
            "SetLayeredWindowAttributes");
        if (g_pSetLayeredWindowAttributes == NULL)
            AfxMessageBox (
            "Layering is not supported in this version of Windows",
            MB_ICONEXCLAMATION);
        
        // 装入棒形光标
        HINSTANCE hInstResource = AfxFindResourceHandle(
            MAKEINTRESOURCE(IDC_SIZEALL), RT_GROUP_CURSOR);
        m_hCursor = ::LoadCursor( NULL, MAKEINTRESOURCE(IDC_CROSS) );
    void CLayeredWindowAttributesDlg::OnLButtonDown(UINT nFlags, CPoint point) 
    {
        // TODO: Add your message handler code here and/or call default
           SetCapture();      //鼠标捕获设置到指定的窗口。在鼠标按钮按下的时候,这个窗口会为//当前应用程序或整个系统接收所有鼠标输入
           m_hCurrWnd = NULL; //现在还没有窗口透明
           m_bTracking = true;     // 设置track标志
            ::SetCursor(m_hCursor); // 将光标改为棒形    
        CDialog::OnLButtonDown(nFlags, point);
    }
    void CLayeredWindowAttributesDlg::OnMouseMove(UINT nFlags, CPoint point) 
    {
        // TODO: Add your message handler code here and/or call default
        if (m_bTracking)
        {
           
                //  获取鼠标位置
                ClientToScreen(&point);
          
                // 获取鼠标下面所在的窗口句柄
                m_hCurrWnd = ::WindowFromPoint(point);
           
                // 显示该窗口的类、标题等信息…
                
        }
        CDialog::OnMouseMove(nFlags, point);
    }
    void CLayeredWindowAttributesDlg::OnLButtonUp(UINT nFlags, CPoint point) 
    {
        // TODO: Add your message handler code here and/or call default
           //释放鼠标捕获
        ReleaseCapture();
        m_bTracking = false;
        //如果鼠标下面的窗口不是本程序WinTrans,我们就要设置层次样式并且通过设置滑动条来实现透明化。
        
        if (g_pSetLayeredWindowAttributes && m_hCurrWnd != m_hWnd)
        {
            ::SetWindowLong(m_hCurrWnd, GWL_EXSTYLE, GetWindowLong(m_hCurrWnd, 
                GWL_EXSTYLE) ^ /*WS_EX_LAYERED*/0x00080000);
            g_pSetLayeredWindowAttributes(m_hCurrWnd, 0,
        (BYTE)m_slider.GetPos(), /*LWA_ALPHA*/2);
            
            ::RedrawWindow(m_hCurrWnd, NULL, NULL,
                RDW_ERASE | RDW_INVALIDATE | 
                RDW_FRAME | RDW_ALLCHILDREN);
        }
        CDialog::OnLButtonUp(nFlags, point);
    }
  • 相关阅读:
    CentOS 8配置Java环境
    记录一个免费的开源API接口管理工具
    WebAPI 查询lookup字段的属性
    Windows环境变量配置与读取
    The specified Active Directory user already exists as a Dynamics 365 user
    QueryExpression之GreaterEqual和LessEqual
    Dynamics CRM Plugin Use Config
    【转】Reports SPN/SSPI Problems
    【转】Report Server cannot load the TERADATA / SQLPDW extension
    iOS 自动布局
  • 原文地址:https://www.cnblogs.com/klxll/p/3333167.html
Copyright © 2011-2022 走看看