只有向HorizontalLayout、VerticalLayout等容器种才可使用xml进行拖动改变控件的大小。
HorizontalLayout:
sepimm=“true” 允许拖动改变大小
sepwidth=“6” 响应的宽度
minwidth=“500” 最小宽度
maxwidth=“800” 最大宽度
VerticalLayout:
sepimm=“true” 允许拖动改变大小
sepheight=“6” 响应的高度
minheight=“500” 最小高度
maxheight=“800” 最大高度
遇到的bug:
1、能拖动,但是在HorizontalLayout容器种添加许多其他容器的时候鼠标放上去不会改变图标样式。
原因:
UIManager.cpp
case WM_SETCURSOR:
{
if( m_pRoot == NULL ) break;
if( LOWORD(lParam) != HTCLIENT ) break;
if( m_bMouseCapture ) return true;
POINT pt = { 0 };
::GetCursorPos(&pt);
::ScreenToClient(m_hWndPaint, &pt);
CControlUI* pControl = FindControl(pt);
if( pControl == NULL ) break;
if( (pControl->GetControlFlags() & UIFLAG_SETCURSOR) == 0 ) break;
TEventUI event = { 0 };
event.Type = UIEVENT_SETCURSOR;
event.pSender = pControl;
event.wParam = wParam;
event.lParam = lParam;
event.ptMouse = pt;
event.wKeyState = MapKeyState();
event.dwTimestamp = ::GetTickCount();
pControl->Event(event);
}
得到鼠标的“WM_SETCURSOR”事件消息时,pControl控件不是想要的容器,所以不会修改图标
修改方式:
void CHorizontalLayoutUI::DoEvent(TEventUI& event)
{
if( m_iSepWidth != 0 ) {
if( event.Type == UIEVENT_BUTTONDOWN && IsEnabled() )
{
RECT rcSeparator = GetThumbRect(false);
if( ::PtInRect(&rcSeparator, event.ptMouse) ) {
//添加代码
::SetCursor(::LoadCursor(NULL, MAKEINTRESOURCE(IDC_SIZEWE)));
//=====end======
m_uButtonState |= UISTATE_CAPTURED;
m_ptLastMouse = event.ptMouse;
m_rcNewPos = m_rcItem;
if( !m_bImmMode && m_pManager ) m_pManager->AddPostPaint(this);
return;
}
}
if( event.Type == UIEVENT_BUTTONUP )
{
if( (m_uButtonState & UISTATE_CAPTURED) != 0 ) {
m_uButtonState &= ~UISTATE_CAPTURED;
m_rcItem = m_rcNewPos;
if( !m_bImmMode && m_pManager ) m_pManager->RemovePostPaint(this);
NeedParentUpdate();
return;
}
}
if( event.Type == UIEVENT_MOUSEMOVE )
{
//添加代码
RECT rcSeparator = GetThumbRect(false);
if (IsEnabled() && ::PtInRect(&rcSeparator, event.ptMouse)) {
::SetCursor(::LoadCursor(NULL, MAKEINTRESOURCE(IDC_SIZEWE)));
}
//=====end======
if( (m_uButtonState & UISTATE_CAPTURED) != 0 ) {
LONG cx = event.ptMouse.x - m_ptLastMouse.x;
m_ptLastMouse = event.ptMouse;
RECT rc = m_rcNewPos;
if( m_iSepWidth >= 0 ) {
if( cx > 0 && event.ptMouse.x < m_rcNewPos.right - m_iSepWidth ) return;
if( cx < 0 && event.ptMouse.x > m_rcNewPos.right ) return;
rc.right += cx;
if( rc.right - rc.left <= GetMinWidth() ) {
if( m_rcNewPos.right - m_rcNewPos.left <= GetMinWidth() ) return;
rc.right = rc.left + GetMinWidth();
}
if( rc.right - rc.left >= GetMaxWidth() ) {
if( m_rcNewPos.right - m_rcNewPos.left >= GetMaxWidth() ) return;
rc.right = rc.left + GetMaxWidth();
}
}
else {
if( cx > 0 && event.ptMouse.x < m_rcNewPos.left ) return;
if( cx < 0 && event.ptMouse.x > m_rcNewPos.left - m_iSepWidth ) return;
rc.left += cx;
if( rc.right - rc.left <= GetMinWidth() ) {
if( m_rcNewPos.right - m_rcNewPos.left <= GetMinWidth() ) return;
rc.left = rc.right - GetMinWidth();
}
if( rc.right - rc.left >= GetMaxWidth() ) {
if( m_rcNewPos.right - m_rcNewPos.left >= GetMaxWidth() ) return;
rc.left = rc.right - GetMaxWidth();
}
}
CDuiRect rcInvalidate = GetThumbRect(true);
m_rcNewPos = rc;
m_cxyFixed.cx = m_rcNewPos.right - m_rcNewPos.left;
if( m_bImmMode ) {
m_rcItem = m_rcNewPos;
NeedParentUpdate();
}
else {
rcInvalidate.Join(GetThumbRect(true));
rcInvalidate.Join(GetThumbRect(false));
if( m_pManager ) m_pManager->Invalidate(rcInvalidate);
}
return;
}
}
if( event.Type == UIEVENT_SETCURSOR )
{
RECT rcSeparator = GetThumbRect(false);
if( IsEnabled() && ::PtInRect(&rcSeparator, event.ptMouse) ) {
::SetCursor(::LoadCursor(NULL, MAKEINTRESOURCE(IDC_SIZEWE)));
return;
}
}
}
CContainerUI::DoEvent(event);
}
在鼠标按下和移动的时候添加改变图标,造成一种错觉。