zoukankan      html  css  js  c++  java
  • 对话框透明,控件不透明(控件显示背景图)

        virtual BOOL OnInitDialog();
        afx_msg HBRUSH OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor);
    
    
    
    ON_WM_CTLCOLOR()
    
    
    
    
    
    BOOL CDlgXXX::OnInitDialog()
    {
        CBCGPDialog::OnInitDialog();
        COLORREF maskColor = RGB(255, 255, 255);
        m_brush_.CreateSolidBrush(maskColor);
    
        LONG nExStyle = ::GetWindowLong(m_hWnd, GWL_EXSTYLE);
        nExStyle |= WS_EX_LAYERED;
        ::SetWindowLong(m_hWnd, GWL_EXSTYLE, nExStyle);
        SetLayeredWindowAttributes(maskColor, 128, LWA_COLORKEY); // 透明度范围是0~255
    
        CRect rtClient(0, 0, 22, 42);
        MoveWindow(&rtClient);
        m_btn_arrow_.MoveWindow(rtClient);
        m_btn_arrow_.m_nFlatStyle = CBCGPButton::FlatStyle::BUTTONSTYLE_NOBORDERS;
        m_btn_arrow_.m_bTransparent = TRUE;
        m_btn_arrow_.SetMouseCursorHand();
        if (m_nDir_ == 0)  //左边
        {
            m_btn_arrow_.SetImage(IDB_PNG_LEFT_CLOSE,IDB_PNG_LEFT_CLOSE_HOT,0,IDB_PNG_LEFT_CLOSE_HOT);
        }
        else if (m_nDir_ == 1)  //右边
        {
            m_btn_arrow_.SetImage(IDB_PNG_RIGHT_CLOSE,IDB_PNG_RIGHT_CLOSE_HOT,0,IDB_PNG_RIGHT_CLOSE_HOT);
        }
    
        return TRUE;
    }
    
    HBRUSH CDlgXXX::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
    {
        HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
    
        if(nCtlColor == CTLCOLOR_DLG)
        {  
            return (HBRUSH)(m_brush_.m_hObject);  
        }
        else if (nCtlColor == CTLCOLOR_BTN)
        {
            pDC->SetBkMode(TRANSPARENT);
            pDC->SetTextColor(RGB(0, 0, 0)); 
            return HBRUSH(GetStockObject(HOLLOW_BRUSH));
        }
        
        return hbr;
    }
    
    
    
    
    别忘了析构
    
    CDlgXXX::~CDlgXXX()
    {
        m_brush_.DeleteObject();
    }
  • 相关阅读:
    static关键字总结
    C、C++的内存分区与存储
    new、delete、malloc、free、realloc的区别
    Python3连接MySQL数据库之mysql-client
    Linux系统配置
    Windows环境下进行socket编程
    jQuery学习-事件之绑定事件(七)
    jQuery学习-事件之绑定事件(六)
    jQuery学习-事件之绑定事件(五)
    jQuery学习-事件之绑定事件(四)
  • 原文地址:https://www.cnblogs.com/XiHua/p/13303939.html
Copyright © 2011-2022 走看看