MFC CEdit背景透明,文字透明实现

2018-6-17

需求:不规则输入框实现

实现:

1. 响应对话框的WM_CTLCOLOR消息

获取EDIT对应的窗口背景色,设置画刷为NULL

if (nCtlColor == CTLCOLOR_EDIT)

 {
        pDC->SetTextColor(RGB(255, 255, 255));
        pDC->SetBkMode(TRANSPARENT);
        CDC* dc = GetDC();
        CRect rc;
        pWnd->GetWindowRect(rc);
        ScreenToClient(rc);

        pDC->BitBlt(0, 0, rc.Width(), rc.Height(), dc, rc.left, rc.top, SRCCOPY);
        return (HBRUSH)::GetStockObject(NULL_BRUSH);

}
2. 响应EN_CHANGE消息

获取控件所在的位置,通知窗口进行刷新

     CRect rc;
    GetDlgItem(IDC_EDIT_USER_NAME)->GetWindowRect(&rc);
    ScreenToClient(&rc);
    InvalidateRect(&rc, TRUE);
    

标签: MFC CEdit 背景透明

评论(0) 浏览(1782)

Powered by EMLOG Copyright @ 狼酒 版权所有. 闽ICP备14012694号-2