duilib无标题窗口拖动

简述

如题,因为在使用设置caption属性时会让整个窗口的可输入控件都不可触发焦点

解决办法

重载 LRESULT OnNcHitTest(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);这里有关于介绍这个函数的
https://blog.csdn.net/liuxiaomao1988/article/details/23421123

LRESULT CXmlWnd::OnNcHitTest(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)  
{  
    POINT           pt;  
    RECT            rcClient;  
    RECT            rcCaption;  
    CControlUI *    pControl = NULL;  

    rcCaption = m_PaintManager.GetCaptionRect();  
    GetClientRect(m_PaintManager.GetPaintWindow(), &rcClient);  
    pt.x = GET_X_LPARAM(lParam);  
    pt.y = GET_Y_LPARAM(lParam);  
    ::ScreenToClient(m_PaintManager.GetPaintWindow(), &pt);  

    if (-1 == rcCaption.bottom) ///< xml中描述bottom为-1时,整个窗口区域都可以拖动  
    {  
        rcCaption.bottom = rcClient.bottom;  
    }  

    if ((pt.x >= rcClient.left)  
        && (pt.x < rcClient.right)  
        && (pt.y >= rcCaption.top)   
        && (pt.y < rcCaption.bottom))   
    {  
        pControl = m_PaintManager.FindControl(pt);  
        if (IsInStaticControl(pControl))  
        {  
            return HTCAPTION;  
        }  
    }  

    return __super::OnNcHitTest(uMsg, wParam, lParam, bHandled);  
}  

BOOL CXmlWnd::IsInStaticControl(CControlUI * pControl)  
{  
    CDuiString strClassName;  
    std::vector<CDuiString> vctStaticName;  
    std::vector<CDuiString>::iterator it;  

    if (NULL == pControl)  
        return FALSE;  

    strClassName = pControl->GetClass();  
    strClassName.MakeLower();  
    vctStaticName.push_back(L"controlui");  
    vctStaticName.push_back(L"textui");  
    vctStaticName.push_back(L"labelui");  
    vctStaticName.push_back(L"containerui");  
    vctStaticName.push_back(L"horizontallayoutui");  
    vctStaticName.push_back(L"verticallayoutui");  
    vctStaticName.push_back(L"tablayoutui");  
    vctStaticName.push_back(L"childlayoutui");  
    vctStaticName.push_back(L"dialoglayoutui");  

    it = std::find(vctStaticName.begin(), vctStaticName.end(), strClassName);  
    return (it != vctStaticName.end());  
}  

猜你喜欢

转载自blog.csdn.net/wjh_init/article/details/80723887