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(); }