vc 对话框 无标题栏

场景:VC 无际框无标题栏对话框的拖动

VC 无边框无标题栏对话框的拖动
我的对话框是无边框无标题栏的,本来对话框是不可以改变大小的,后来添加了以下代码:

C/C++ code

void CViewResultDlg::OnLButtonDown(UINT nFlags, CPoint point) 
{
    switch(m_mouseStates) 
    {
    case HTLEFT:
    case HTRIGHT:
        ::SetCursor(LoadCursor(NULL, IDC_SIZEWE));
        break;
    case HTTOP:
    case HTBOTTOM:
        ::SetCursor(LoadCursor(NULL, IDC_SIZENS));
        break;
    case HTTOPLEFT:
    case HTBOTTOMRIGHT:
        ::SetCursor(LoadCursor(NULL, IDC_SIZENWSE));
        break;
    case HTTOPRIGHT:
    case HTBOTTOMLEFT:
        ::SetCursor(LoadCursor(NULL, IDC_SIZENESW));
        break;
    default:
        ::SetCursor(LoadCursor(NULL, IDC_ARROW));
        break;
    }
    
    if (m_mouseStates == HTTOP)
        PostMessage(WM_SYSCOMMAND, SC_SIZE | WMSZ_TOP, MAKELPARAM(point.x, point.y));
    else if (m_mouseStates == HTBOTTOM)
        PostMessage(WM_SYSCOMMAND, SC_SIZE | WMSZ_BOTTOM, MAKELPARAM(point.x, point.y));
    else if (m_mouseStates == HTLEFT)
        PostMessage(WM_SYSCOMMAND, SC_SIZE | WMSZ_LEFT, MAKELPARAM(point.x, point.y));
    else if (m_mouseStates == HTRIGHT)
        PostMessage(WM_SYSCOMMAND, SC_SIZE | WMSZ_RIGHT, MAKELPARAM(point.x, point.y));
    else if (m_mouseStates == HTTOPLEFT)
        PostMessage(WM_SYSCOMMAND, SC_SIZE | WMSZ_TOPLEFT, MAKELPARAM(point.x, point.y));
    else if (m_mouseStates == HTBOTTOMRIGHT)
        PostMessage(WM_SYSCOMMAND, SC_SIZE | WMSZ_BOTTOMRIGHT, MAKELPARAM(point.x, point.y));
    else if (m_mouseStates == HTTOPRIGHT)
        PostMessage(WM_SYSCOMMAND, SC_SIZE | WMSZ_TOPRIGHT, MAKELPARAM(point.x, point.y));
    else if (m_mouseStates == HTBOTTOMLEFT)
        PostMessage(WM_SYSCOMMAND, SC_SIZE | WMSZ_BOTTOMLEFT, MAKELPARAM(point.x, point.y));
    else
    {
        //PostMessage(WM_NCLBUTTONDOWN,HTCAPTION,MAKELPARAM(point.x,point.y));
    }

    CDialog::OnLButtonDown(nFlags, point);
}

void CViewResultDlg::OnMouseMove(UINT nFlags, CPoint point) 
{
    if(m_bEnableWindowSize &&  !IsZoomed())
    {
        CRect rect;
        GetClientRect(&rect);    
        if (point.x <= rect.left + 5 && point.y <= rect.top + 5)
            m_mouseStates = HTTOPLEFT;
        else if (point.x >= rect.right - 5 && point.y >= rect.bottom - 5)
            m_mouseStates = HTBOTTOMRIGHT;
        else if (point.x >= rect.right - 5 && point.y <= rect.top + 5)
            m_mouseStates = HTTOPRIGHT;
        else if (point.x <= rect.left + 5 && point.y >= rect.bottom - 5)
            m_mouseStates = HTBOTTOMLEFT;
        else if (point.x <= rect.left + 5)
            m_mouseStates = HTLEFT;
        else if (point.x >= rect.right - 5)
            m_mouseStates = HTRIGHT;
        else if (point.y <= rect.top + 5)
            m_mouseStates = HTTOP;
        else if (point.y >= rect.bottom - 5)
            m_mouseStates = HTBOTTOM;
        else 
            m_mouseStates = 0;
        
        switch (m_mouseStates) 
        {
        case HTLEFT:
        case HTRIGHT:
            ::SetCursor(LoadCursor(NULL, IDC_SIZEWE));
            break;
        case HTTOP:
        case HTBOTTOM:
            ::SetCursor(LoadCursor(NULL, IDC_SIZENS));
            break;
        case HTTOPLEFT:
        case HTBOTTOMRIGHT:
            ::SetCursor(LoadCursor(NULL, IDC_SIZENWSE));
            break;
        case HTTOPRIGHT:
        case HTBOTTOMLEFT:
            ::SetCursor(LoadCursor(NULL, IDC_SIZENESW));
            break;
        default:
            ::SetCursor(LoadCursor(NULL, IDC_ARROW));
            break;
        }    
    }
    CDialog::OnMouseMove(nFlags, point);
}

void CViewResultDlg::OnSizing(UINT fwSide, LPRECT pRect)
{
    CDialog::OnSizing(fwSide, pRect);
    if ((pRect->right - pRect->left)<= m_nDlgDefaultWidth || (pRect->bottom - pRect->top) >= m_nDlgDefaultHeight)
    {
        return;
    }
    if(m_bEnableWindowSize)
    {    
        switch(fwSide) 
        {
        case WMSZ_LEFT:
            pRect->left = min(pRect->left, pRect->right - m_nSizeX);
            break;
        case WMSZ_RIGHT:
            pRect->right = max(pRect->right, pRect->left + m_nSizeX);
            break;
        case WMSZ_TOP:
            pRect->top = min(pRect->top, pRect->bottom - m_nSizeY);
            break;
        case WMSZ_BOTTOM:
            pRect->bottom = max(pRect->bottom, pRect->top + m_nSizeY);
            break;
        case WMSZ_TOPLEFT:
            pRect->left = min(pRect->left, pRect->right - m_nSizeX);
            pRect->top = min(pRect->top, pRect->bottom - m_nSizeY);
            break;
        case WMSZ_BOTTOMRIGHT:
            pRect->right = max(pRect->right, pRect->left + m_nSizeX);
            pRect->bottom = max(pRect->bottom, pRect->top + m_nSizeY);
            break;
        case WMSZ_TOPRIGHT:
            pRect->right = max(pRect->right, pRect->left + m_nSizeX);
            pRect->top = min(pRect->top, pRect->bottom - m_nSizeY);
            break;
        case WMSZ_BOTTOMLEFT:
            pRect->bottom = max(pRect->bottom, pRect->top + m_nSizeY);
            pRect->left = min(pRect->left, pRect->right - m_nSizeX);
            break;
        default:
            break;
        }    
    }
}


对话框可以拖动了,但是在拖动时又会自动加上一个边框,请问如何解决?

------解决方案--------------------
不用这么麻烦吧,你设置对话框无边框,在OnLButtonDown事件里就一句话可以拖动了
C/C++ code

void CMoveAnyWhereDlg::OnLButtonDown(UINT nFlags, CPoint point) 
{
    // TODO: Add your message handler code here and/or call default
    //发送WM_NCLBUTTONDOWN消息,使Windows认为鼠标在标题条上
    PostMessage(WM_NCLBUTTONDOWN,HTCAPTION,MAKELPARAM(point.x,point.y));
    CDialog::OnLButtonDown(nFlags, point);
}

------解决方案--------------------
探讨
不用这么麻烦吧,你设置对话框无边框,在OnLButtonDown事件里就一句话可以拖动了

C/C++ code

void CMoveAnyWhereDlg::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
……

------解决方案--------------------
那个虚框是系统属性吧
你拖动别的窗口没有框么?
------解决方案--------------------
C/C++ code

LRESULT CxxDlg::OnNcHitTest(CPoint point)
{
    CRect rect;
    GetClientRect(&rect);
    ScreenToClient(&point);
    if ((point.x >rect.Width()  -6) && (point.y >rect.Height()  - 6))
        return HTBOTTOMRIGHT;
    else if((point.x > rect.Width() -6) && (point.y <= rect.Height() - 6))
        return HTRIGHT;
    else if((point.x <= rect.Width() -6) && (point.y > rect.Height() - 6))
        return HTBOTTOM;
    else
        return HTCAPTION;
}

------解决方案--------------------
if (!IsZoomed() && !IsIconic())
{
SendMessage(WM_NCLBUTTONDOWN, HTCAPTION, MAKELPARAM(point.x, point.y));
CRect rect,rect1;
this->GetClientRect(rect);
this->GetWindowRect(rect1);


}

CDialog::OnLButtonDown(nFlags, point);
------解决方案--------------------
探讨
C/C++ code

LRESULT CxxDlg::OnNcHitTest(CPoint point)
{
CRect rect;
GetClientRect(&amp;rect);
ScreenToClient(&amp;point);
if ((point.x >rect.Width() -6) &amp;&amp; (point.y >re……

------解决方案--------------------
试试处理 WM_NCHITTEST,
根据位置返回 HT_TOP,HT_BOTTOM,HT_LEFT,HT_RIGHT,HT_TOPLEFT,HT_TOPRIGHT,HT_BOTTOMLEFT,HT_BOTTOMRIGHT。
完整的返回值和含义可查msdn WM_NCHITTEST