11 个解决方案
#1
这个,自己baidu/google下吧...
#2
嗯,baidu上就找到本站2005年的那个,再去google看看,google搜出的信息和合百度还真有些不一样。
#3
方法一:添加WM_NCHITTEST消息响应
UINT CXXXDialog::OnNcHitTest(CPoint point)
{
CRect rc;
GetClientRect(&rc);
CRect rcTitle(0,0,rc.Width(),TITLE_HEIGHT);//rcTitle为虚拟标题栏,即能通过鼠标拖动窗口
//的区域,高度为TITLE_HEIGHT
ClientToScreen(&rcTitle);
return rcTitle.PtInRect(point) ? HTCAPTION : CDialog::OnNcHitTest(point);
}
//方法二:添加WM_LBUTTONDOWN、WM_LBUTTONUP、WM_MOUSEMOVE消息响应移动窗口,大致如下
void CBTFDialog::OnMouseMove(CPoint point)
{
if (!m_bDragTitle)
{
return;
}
int offleft = point.x - m_pointDown.x;
int offtop = point.y - m_pointDown.y;
CRect wrc;
GetWindowRect(&wrc);
wrc.OffsetRect(offleft, offtop);
MoveWindow(&wrc, TRUE );
}
void CBTFDialog::OnLButtonDown(CPoint point)
{
if (point.y < 0 || point.y > TITLE_HEIGHT)
{
return;
}
m_bDragTitle = TRUE;
m_pointDown = point;
SetCapture();
}
void CBTFDialog::OnLButtonUp(CPoint point)
{
if (!m_bDragTitle)
{
return;
}
m_bDragTitle = FALSE;
ReleaseCapture();
}
UINT CXXXDialog::OnNcHitTest(CPoint point)
{
CRect rc;
GetClientRect(&rc);
CRect rcTitle(0,0,rc.Width(),TITLE_HEIGHT);//rcTitle为虚拟标题栏,即能通过鼠标拖动窗口
//的区域,高度为TITLE_HEIGHT
ClientToScreen(&rcTitle);
return rcTitle.PtInRect(point) ? HTCAPTION : CDialog::OnNcHitTest(point);
}
//方法二:添加WM_LBUTTONDOWN、WM_LBUTTONUP、WM_MOUSEMOVE消息响应移动窗口,大致如下
void CBTFDialog::OnMouseMove(CPoint point)
{
if (!m_bDragTitle)
{
return;
}
int offleft = point.x - m_pointDown.x;
int offtop = point.y - m_pointDown.y;
CRect wrc;
GetWindowRect(&wrc);
wrc.OffsetRect(offleft, offtop);
MoveWindow(&wrc, TRUE );
}
void CBTFDialog::OnLButtonDown(CPoint point)
{
if (point.y < 0 || point.y > TITLE_HEIGHT)
{
return;
}
m_bDragTitle = TRUE;
m_pointDown = point;
SetCapture();
}
void CBTFDialog::OnLButtonUp(CPoint point)
{
if (!m_bDragTitle)
{
return;
}
m_bDragTitle = FALSE;
ReleaseCapture();
}
#4
//响应WM_NCHITTEST消息
//实现无边框的对话框移动
LRESULT CTestDlg::OnNcHitTest(CPoint point)
{
CRect rc;
GetClientRect( &rc );
ClientToScreen( &rc );
return rc.PtInRect( point ) ? HTCAPTION : CDialog::OnNcHitTest( point );
}
#5
你的对话框属性Border:设置为Resizing,去掉Title bar就可以了。
不过有点遗憾的就是窗口四周还是有个边框。
不过有点遗憾的就是窗口四周还是有个边框。
#6
无边框窗口实现拖拉效果 收藏
实现效果需要处理以下这三个消息:
WM_NCHITTEST WM_SETCURSOR WM_NCLBUTTONDOWN
消息处理函数:
UINT CXXXDlg::OnNcHitTest(UINT nHitTest, CPoint point)
{
CRect rect;
GetWindowRect(&rect);
if(point.x <= rect.left+3)
return HTLEFT;
else if(point.x >= rect.right-3)
return HTRIGHT;
else if(point.y <= rect.top+3)
return HTTOP;
else if(point.y >= rect.bottom-3)
return HTBOTTOM;
else if(point.x <= rect.left+10 && point.y <= rect.top+10)
return HTTOPLEFT;
else if(point.x >= rect.right-10 && point.y <= rect.top+10)
return HTTOPRIGHT;
else if(point.x <= rect.left+10 && point.y >= rect.bottom-10)
return HTBOTTOMLEFT;
else if(point.x >= rect.right-10 && point.y >= rect.bottom-10)
return HTBOTTOMRIGHT;
return 0;
}
BOOL CXXXDlg::OnSetCursor(HWND hWnd, UINT nHitTest, UINT message)
{
if(nHitTest == HTCAPTION || nHitTest == HTSYSMENU ||
nHitTest == HTMENU || nHitTest == HTCLIENT)
{
SetCursor(LoadCursor(NULL, MAKEINTRESOURCE(IDC_ARROW)));
}
else if(nHitTest == HTTOP || nHitTest == HTBOTTOM)
{
SetCursor(LoadCursor(NULL, MAKEINTRESOURCE(IDC_SIZENS)));
}
else if(nHitTest == HTLEFT || nHitTest == HTRIGHT)
{
SetCursor(LoadCursor(NULL, MAKEINTRESOURCE(IDC_SIZEWE)));
}
else if(nHitTest == HTTOPLEFT || nHitTest == HTBOTTOMRIGHT)
{
SetCursor(LoadCursor(NULL, MAKEINTRESOURCE(IDC_SIZENWSE)));
}
else if(nHitTest == HTTOPRIGHT || nHitTest == HTBOTTOMLEFT)
{
SetCursor(LoadCursor(NULL, MAKEINTRESOURCE(IDC_SIZENESW)));
}
else
{
SetCursor(LoadCursor(NULL, MAKEINTRESOURCE(IDC_ARROW)));
}
}
void CXXXDlg::OnNcLButtonDown(UINT nHitTest, CPoint point)
{
if(nHitTest == HTTOP)
SendMessage( WM_SYSCOMMAND, SC_SIZE | WMSZ_TOP, MAKELPARAM(point.x, point.y));
else if(nHitTest == HTBOTTOM)
SendMessage( WM_SYSCOMMAND, SC_SIZE | WMSZ_BOTTOM, MAKELPARAM(point.x, point.y));
else if(nHitTest == HTLEFT)
SendMessage( WM_SYSCOMMAND, SC_SIZE | WMSZ_LEFT, MAKELPARAM(point.x, point.y));
else if(nHitTest == HTRIGHT)
SendMessage( WM_SYSCOMMAND, SC_SIZE | WMSZ_RIGHT, MAKELPARAM(point.x, point.y));
else if(nHitTest == HTTOPLEFT)
SendMessage( WM_SYSCOMMAND, SC_SIZE | WMSZ_TOPLEFT, MAKELPARAM(point.x, point.y));
else if(nHitTest == HTTOPRIGHT)
SendMessage( WM_SYSCOMMAND, SC_SIZE | WMSZ_TOPRIGHT, MAKELPARAM(point.x, point.y));
else if(nHitTest == HTBOTTOMLEFT)
SendMessage( WM_SYSCOMMAND, SC_SIZE | WMSZ_BOTTOMLEFT, MAKELPARAM(point.x, point.y));
else if(nHitTest == HTBOTTOMRIGHT)
SendMessage(WM_SYSCOMMAND, SC_SIZE | WMSZ_BOTTOMRIGHT, MAKELPARAM(point.x, point.y));
}
#7
谢谢兄弟们。6楼的方法,以前实验过,从下往上移动到一定距离就不能再上下移动了。
#8
兄弟的方法可行,我又实验了一把,在OnSetCursor函数中每个if的SetCursor后边加上了一句return 0,要不然提示必须返回一个值,而且如果返回默认语句:return CDialog::OnSetCursor(pWnd, nHitTest, message);的话光标就设置不成功,设置后立马就被系统又重新设置了。别的没改直接用,谢谢!
#9
唉!这个方法是别人的,不是我写的。查到原来的出处了,补回来。罪过!向原作者道歉。
出处:http://blog.csdn.net/carl2380/archive/2009/08/31/4502526.aspx
出处:http://blog.csdn.net/carl2380/archive/2009/08/31/4502526.aspx
#10
#11
前面的做法,有一些问题吧, 像在作那么判断时, 左右,上下先判断了,那下面,左上,左下,右上,右下就没法做了,重复,感觉逻辑有些问题。思想还是挺好的。还有在坐标系可能会有些出入。
我整体了一下,给大家看看:
UINT CTestDlg::OnNcHitTest( CPoint point )
{
CPoint ptCur;
CRect rect;
GetCursorPos( &ptCur );
GetWindowRect( &rect );
if ( rect.Width() >= m_nCxFullScreen-3 && rect.Height() >= m_nCyFullScreen-3 )
return CDialog::OnNcHitTest(point);
// rect.left = rect.right - 4;
// rect.top = rect.bottom - 4;
// 右下角一个 4*4 小块
// if ( rect.PtInRect( ptCur ) )
// return HTBOTTOMRIGHT;
if( CRect(rect.left, rect.top, rect.left+3, rect.top+3).PtInRect( ptCur ) )
return HTTOPLEFT;
else if( CRect(rect.right-3, rect.top, rect.right, rect.top+3).PtInRect( ptCur ) )
return HTTOPRIGHT;
else if( CRect(rect.left, rect.bottom-3, rect.left+3, rect.bottom).PtInRect( ptCur ) )
return HTBOTTOMLEFT;
else if( CRect(rect.right-3, rect.bottom-3, rect.right, rect.bottom).PtInRect( ptCur ) )
return HTBOTTOMRIGHT;
else if ( CRect(rect.left, rect.top, rect.left+3, rect.bottom).PtInRect( ptCur ) )
return HTLEFT;
else if( CRect(rect.right-3, rect.top, rect.right, rect.bottom).PtInRect( ptCur ) )
return HTRIGHT;
else if( CRect(rect.left, rect.top, rect.right-128, rect.top+3).PtInRect( ptCur ) ) // 128 Min,Max,Close
return HTTOP;
else if( CRect(rect.left, rect.bottom-3, rect.right, rect.bottom).PtInRect( ptCur ) )
return HTBOTTOM;
return CDialog::OnNcHitTest(point);
}
BOOL CTestDlg::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
{
CPoint ptCur;
CRect rect;
GetCursorPos( &ptCur );
GetWindowRect( &rect );
if ( rect.Width() >= m_nCxFullScreen-3 && rect.Height() >= m_nCyFullScreen-3 )
return CDialog::OnSetCursor(pWnd, nHitTest, message);
// rect.left = rect.right - 4;
// rect.top = rect.bottom - 4;
// if ( rect.PtInRect( ptCur ) )
// {
// SetCursor(LoadCursor(NULL, MAKEINTRESOURCE(IDC_SIZENWSE)));
// return 0;
// }
if( CRect(rect.left, rect.top, rect.left+3, rect.top+3).PtInRect( ptCur ) || CRect(rect.right-3, rect.bottom-3, rect.right, rect.bottom).PtInRect( ptCur ) )
{
SetCursor(LoadCursor(NULL, MAKEINTRESOURCE(IDC_SIZENWSE)));
return 0;
}
else if( CRect(rect.left, rect.bottom-3, rect.left+3, rect.bottom).PtInRect( ptCur ) || CRect(rect.left, rect.bottom-3, rect.left+3, rect.bottom).PtInRect( ptCur ) )
{
SetCursor(LoadCursor(NULL, MAKEINTRESOURCE(IDC_SIZENESW)));
return 0;
}
else if( CRect(rect.left, rect.top, rect.right-128, rect.top+3).PtInRect( ptCur ) || CRect(rect.left, rect.bottom-3, rect.right, rect.bottom).PtInRect( ptCur ) )
{
SetCursor(LoadCursor(NULL, MAKEINTRESOURCE(IDC_SIZENS)));
return 0;
}
else if( CRect(rect.left, rect.top, rect.left+3, rect.bottom).PtInRect( ptCur ) || CRect(rect.right-3, rect.top, rect.right, rect.bottom).PtInRect( ptCur ) )
{
SetCursor(LoadCursor(NULL, MAKEINTRESOURCE(IDC_SIZEWE)));
return 0;
}
return CDialog::OnSetCursor(pWnd, nHitTest, message);
}
void CTestDlg::OnNcLButtonDown(UINT nHitTest, CPoint point)
{
switch( nHitTest )
{
case HTTOP:
SendMessage( WM_SYSCOMMAND, SC_SIZE | WMSZ_TOP, MAKELPARAM(point.x, point.y));
return;
case HTBOTTOM:
SendMessage( WM_SYSCOMMAND, SC_SIZE | WMSZ_BOTTOM, MAKELPARAM(point.x, point.y));
return;
case HTLEFT:
SendMessage( WM_SYSCOMMAND, SC_SIZE | WMSZ_LEFT, MAKELPARAM(point.x, point.y));
return;
case HTRIGHT:
SendMessage( WM_SYSCOMMAND, SC_SIZE | WMSZ_RIGHT, MAKELPARAM(point.x, point.y));
return;
case HTTOPLEFT:
SendMessage( WM_SYSCOMMAND, SC_SIZE | WMSZ_TOPLEFT, MAKELPARAM(point.x, point.y));
return;
case HTTOPRIGHT:
SendMessage( WM_SYSCOMMAND, SC_SIZE | WMSZ_TOPRIGHT, MAKELPARAM(point.x, point.y));
return;
case HTBOTTOMLEFT:
SendMessage( WM_SYSCOMMAND, SC_SIZE | WMSZ_BOTTOMLEFT, MAKELPARAM(point.x, point.y));
return;
case HTBOTTOMRIGHT:
SendMessage( WM_SYSCOMMAND, SC_SIZE | WMSZ_BOTTOMRIGHT, MAKELPARAM(point.x, point.y));
return;
default:
CDialog::OnNcLButtonDown( nHitTest, point );
}
CDialog::OnNcLButtonDown( nHitTest, point );
}
我整体了一下,给大家看看:
UINT CTestDlg::OnNcHitTest( CPoint point )
{
CPoint ptCur;
CRect rect;
GetCursorPos( &ptCur );
GetWindowRect( &rect );
if ( rect.Width() >= m_nCxFullScreen-3 && rect.Height() >= m_nCyFullScreen-3 )
return CDialog::OnNcHitTest(point);
// rect.left = rect.right - 4;
// rect.top = rect.bottom - 4;
// 右下角一个 4*4 小块
// if ( rect.PtInRect( ptCur ) )
// return HTBOTTOMRIGHT;
if( CRect(rect.left, rect.top, rect.left+3, rect.top+3).PtInRect( ptCur ) )
return HTTOPLEFT;
else if( CRect(rect.right-3, rect.top, rect.right, rect.top+3).PtInRect( ptCur ) )
return HTTOPRIGHT;
else if( CRect(rect.left, rect.bottom-3, rect.left+3, rect.bottom).PtInRect( ptCur ) )
return HTBOTTOMLEFT;
else if( CRect(rect.right-3, rect.bottom-3, rect.right, rect.bottom).PtInRect( ptCur ) )
return HTBOTTOMRIGHT;
else if ( CRect(rect.left, rect.top, rect.left+3, rect.bottom).PtInRect( ptCur ) )
return HTLEFT;
else if( CRect(rect.right-3, rect.top, rect.right, rect.bottom).PtInRect( ptCur ) )
return HTRIGHT;
else if( CRect(rect.left, rect.top, rect.right-128, rect.top+3).PtInRect( ptCur ) ) // 128 Min,Max,Close
return HTTOP;
else if( CRect(rect.left, rect.bottom-3, rect.right, rect.bottom).PtInRect( ptCur ) )
return HTBOTTOM;
return CDialog::OnNcHitTest(point);
}
BOOL CTestDlg::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
{
CPoint ptCur;
CRect rect;
GetCursorPos( &ptCur );
GetWindowRect( &rect );
if ( rect.Width() >= m_nCxFullScreen-3 && rect.Height() >= m_nCyFullScreen-3 )
return CDialog::OnSetCursor(pWnd, nHitTest, message);
// rect.left = rect.right - 4;
// rect.top = rect.bottom - 4;
// if ( rect.PtInRect( ptCur ) )
// {
// SetCursor(LoadCursor(NULL, MAKEINTRESOURCE(IDC_SIZENWSE)));
// return 0;
// }
if( CRect(rect.left, rect.top, rect.left+3, rect.top+3).PtInRect( ptCur ) || CRect(rect.right-3, rect.bottom-3, rect.right, rect.bottom).PtInRect( ptCur ) )
{
SetCursor(LoadCursor(NULL, MAKEINTRESOURCE(IDC_SIZENWSE)));
return 0;
}
else if( CRect(rect.left, rect.bottom-3, rect.left+3, rect.bottom).PtInRect( ptCur ) || CRect(rect.left, rect.bottom-3, rect.left+3, rect.bottom).PtInRect( ptCur ) )
{
SetCursor(LoadCursor(NULL, MAKEINTRESOURCE(IDC_SIZENESW)));
return 0;
}
else if( CRect(rect.left, rect.top, rect.right-128, rect.top+3).PtInRect( ptCur ) || CRect(rect.left, rect.bottom-3, rect.right, rect.bottom).PtInRect( ptCur ) )
{
SetCursor(LoadCursor(NULL, MAKEINTRESOURCE(IDC_SIZENS)));
return 0;
}
else if( CRect(rect.left, rect.top, rect.left+3, rect.bottom).PtInRect( ptCur ) || CRect(rect.right-3, rect.top, rect.right, rect.bottom).PtInRect( ptCur ) )
{
SetCursor(LoadCursor(NULL, MAKEINTRESOURCE(IDC_SIZEWE)));
return 0;
}
return CDialog::OnSetCursor(pWnd, nHitTest, message);
}
void CTestDlg::OnNcLButtonDown(UINT nHitTest, CPoint point)
{
switch( nHitTest )
{
case HTTOP:
SendMessage( WM_SYSCOMMAND, SC_SIZE | WMSZ_TOP, MAKELPARAM(point.x, point.y));
return;
case HTBOTTOM:
SendMessage( WM_SYSCOMMAND, SC_SIZE | WMSZ_BOTTOM, MAKELPARAM(point.x, point.y));
return;
case HTLEFT:
SendMessage( WM_SYSCOMMAND, SC_SIZE | WMSZ_LEFT, MAKELPARAM(point.x, point.y));
return;
case HTRIGHT:
SendMessage( WM_SYSCOMMAND, SC_SIZE | WMSZ_RIGHT, MAKELPARAM(point.x, point.y));
return;
case HTTOPLEFT:
SendMessage( WM_SYSCOMMAND, SC_SIZE | WMSZ_TOPLEFT, MAKELPARAM(point.x, point.y));
return;
case HTTOPRIGHT:
SendMessage( WM_SYSCOMMAND, SC_SIZE | WMSZ_TOPRIGHT, MAKELPARAM(point.x, point.y));
return;
case HTBOTTOMLEFT:
SendMessage( WM_SYSCOMMAND, SC_SIZE | WMSZ_BOTTOMLEFT, MAKELPARAM(point.x, point.y));
return;
case HTBOTTOMRIGHT:
SendMessage( WM_SYSCOMMAND, SC_SIZE | WMSZ_BOTTOMRIGHT, MAKELPARAM(point.x, point.y));
return;
default:
CDialog::OnNcLButtonDown( nHitTest, point );
}
CDialog::OnNcLButtonDown( nHitTest, point );
}
#1
这个,自己baidu/google下吧...
#2
嗯,baidu上就找到本站2005年的那个,再去google看看,google搜出的信息和合百度还真有些不一样。
#3
方法一:添加WM_NCHITTEST消息响应
UINT CXXXDialog::OnNcHitTest(CPoint point)
{
CRect rc;
GetClientRect(&rc);
CRect rcTitle(0,0,rc.Width(),TITLE_HEIGHT);//rcTitle为虚拟标题栏,即能通过鼠标拖动窗口
//的区域,高度为TITLE_HEIGHT
ClientToScreen(&rcTitle);
return rcTitle.PtInRect(point) ? HTCAPTION : CDialog::OnNcHitTest(point);
}
//方法二:添加WM_LBUTTONDOWN、WM_LBUTTONUP、WM_MOUSEMOVE消息响应移动窗口,大致如下
void CBTFDialog::OnMouseMove(CPoint point)
{
if (!m_bDragTitle)
{
return;
}
int offleft = point.x - m_pointDown.x;
int offtop = point.y - m_pointDown.y;
CRect wrc;
GetWindowRect(&wrc);
wrc.OffsetRect(offleft, offtop);
MoveWindow(&wrc, TRUE );
}
void CBTFDialog::OnLButtonDown(CPoint point)
{
if (point.y < 0 || point.y > TITLE_HEIGHT)
{
return;
}
m_bDragTitle = TRUE;
m_pointDown = point;
SetCapture();
}
void CBTFDialog::OnLButtonUp(CPoint point)
{
if (!m_bDragTitle)
{
return;
}
m_bDragTitle = FALSE;
ReleaseCapture();
}
UINT CXXXDialog::OnNcHitTest(CPoint point)
{
CRect rc;
GetClientRect(&rc);
CRect rcTitle(0,0,rc.Width(),TITLE_HEIGHT);//rcTitle为虚拟标题栏,即能通过鼠标拖动窗口
//的区域,高度为TITLE_HEIGHT
ClientToScreen(&rcTitle);
return rcTitle.PtInRect(point) ? HTCAPTION : CDialog::OnNcHitTest(point);
}
//方法二:添加WM_LBUTTONDOWN、WM_LBUTTONUP、WM_MOUSEMOVE消息响应移动窗口,大致如下
void CBTFDialog::OnMouseMove(CPoint point)
{
if (!m_bDragTitle)
{
return;
}
int offleft = point.x - m_pointDown.x;
int offtop = point.y - m_pointDown.y;
CRect wrc;
GetWindowRect(&wrc);
wrc.OffsetRect(offleft, offtop);
MoveWindow(&wrc, TRUE );
}
void CBTFDialog::OnLButtonDown(CPoint point)
{
if (point.y < 0 || point.y > TITLE_HEIGHT)
{
return;
}
m_bDragTitle = TRUE;
m_pointDown = point;
SetCapture();
}
void CBTFDialog::OnLButtonUp(CPoint point)
{
if (!m_bDragTitle)
{
return;
}
m_bDragTitle = FALSE;
ReleaseCapture();
}
#4
//响应WM_NCHITTEST消息
//实现无边框的对话框移动
LRESULT CTestDlg::OnNcHitTest(CPoint point)
{
CRect rc;
GetClientRect( &rc );
ClientToScreen( &rc );
return rc.PtInRect( point ) ? HTCAPTION : CDialog::OnNcHitTest( point );
}
#5
你的对话框属性Border:设置为Resizing,去掉Title bar就可以了。
不过有点遗憾的就是窗口四周还是有个边框。
不过有点遗憾的就是窗口四周还是有个边框。
#6
无边框窗口实现拖拉效果 收藏
实现效果需要处理以下这三个消息:
WM_NCHITTEST WM_SETCURSOR WM_NCLBUTTONDOWN
消息处理函数:
UINT CXXXDlg::OnNcHitTest(UINT nHitTest, CPoint point)
{
CRect rect;
GetWindowRect(&rect);
if(point.x <= rect.left+3)
return HTLEFT;
else if(point.x >= rect.right-3)
return HTRIGHT;
else if(point.y <= rect.top+3)
return HTTOP;
else if(point.y >= rect.bottom-3)
return HTBOTTOM;
else if(point.x <= rect.left+10 && point.y <= rect.top+10)
return HTTOPLEFT;
else if(point.x >= rect.right-10 && point.y <= rect.top+10)
return HTTOPRIGHT;
else if(point.x <= rect.left+10 && point.y >= rect.bottom-10)
return HTBOTTOMLEFT;
else if(point.x >= rect.right-10 && point.y >= rect.bottom-10)
return HTBOTTOMRIGHT;
return 0;
}
BOOL CXXXDlg::OnSetCursor(HWND hWnd, UINT nHitTest, UINT message)
{
if(nHitTest == HTCAPTION || nHitTest == HTSYSMENU ||
nHitTest == HTMENU || nHitTest == HTCLIENT)
{
SetCursor(LoadCursor(NULL, MAKEINTRESOURCE(IDC_ARROW)));
}
else if(nHitTest == HTTOP || nHitTest == HTBOTTOM)
{
SetCursor(LoadCursor(NULL, MAKEINTRESOURCE(IDC_SIZENS)));
}
else if(nHitTest == HTLEFT || nHitTest == HTRIGHT)
{
SetCursor(LoadCursor(NULL, MAKEINTRESOURCE(IDC_SIZEWE)));
}
else if(nHitTest == HTTOPLEFT || nHitTest == HTBOTTOMRIGHT)
{
SetCursor(LoadCursor(NULL, MAKEINTRESOURCE(IDC_SIZENWSE)));
}
else if(nHitTest == HTTOPRIGHT || nHitTest == HTBOTTOMLEFT)
{
SetCursor(LoadCursor(NULL, MAKEINTRESOURCE(IDC_SIZENESW)));
}
else
{
SetCursor(LoadCursor(NULL, MAKEINTRESOURCE(IDC_ARROW)));
}
}
void CXXXDlg::OnNcLButtonDown(UINT nHitTest, CPoint point)
{
if(nHitTest == HTTOP)
SendMessage( WM_SYSCOMMAND, SC_SIZE | WMSZ_TOP, MAKELPARAM(point.x, point.y));
else if(nHitTest == HTBOTTOM)
SendMessage( WM_SYSCOMMAND, SC_SIZE | WMSZ_BOTTOM, MAKELPARAM(point.x, point.y));
else if(nHitTest == HTLEFT)
SendMessage( WM_SYSCOMMAND, SC_SIZE | WMSZ_LEFT, MAKELPARAM(point.x, point.y));
else if(nHitTest == HTRIGHT)
SendMessage( WM_SYSCOMMAND, SC_SIZE | WMSZ_RIGHT, MAKELPARAM(point.x, point.y));
else if(nHitTest == HTTOPLEFT)
SendMessage( WM_SYSCOMMAND, SC_SIZE | WMSZ_TOPLEFT, MAKELPARAM(point.x, point.y));
else if(nHitTest == HTTOPRIGHT)
SendMessage( WM_SYSCOMMAND, SC_SIZE | WMSZ_TOPRIGHT, MAKELPARAM(point.x, point.y));
else if(nHitTest == HTBOTTOMLEFT)
SendMessage( WM_SYSCOMMAND, SC_SIZE | WMSZ_BOTTOMLEFT, MAKELPARAM(point.x, point.y));
else if(nHitTest == HTBOTTOMRIGHT)
SendMessage(WM_SYSCOMMAND, SC_SIZE | WMSZ_BOTTOMRIGHT, MAKELPARAM(point.x, point.y));
}
#7
谢谢兄弟们。6楼的方法,以前实验过,从下往上移动到一定距离就不能再上下移动了。
#8
兄弟的方法可行,我又实验了一把,在OnSetCursor函数中每个if的SetCursor后边加上了一句return 0,要不然提示必须返回一个值,而且如果返回默认语句:return CDialog::OnSetCursor(pWnd, nHitTest, message);的话光标就设置不成功,设置后立马就被系统又重新设置了。别的没改直接用,谢谢!
#9
唉!这个方法是别人的,不是我写的。查到原来的出处了,补回来。罪过!向原作者道歉。
出处:http://blog.csdn.net/carl2380/archive/2009/08/31/4502526.aspx
出处:http://blog.csdn.net/carl2380/archive/2009/08/31/4502526.aspx
#10
#11
前面的做法,有一些问题吧, 像在作那么判断时, 左右,上下先判断了,那下面,左上,左下,右上,右下就没法做了,重复,感觉逻辑有些问题。思想还是挺好的。还有在坐标系可能会有些出入。
我整体了一下,给大家看看:
UINT CTestDlg::OnNcHitTest( CPoint point )
{
CPoint ptCur;
CRect rect;
GetCursorPos( &ptCur );
GetWindowRect( &rect );
if ( rect.Width() >= m_nCxFullScreen-3 && rect.Height() >= m_nCyFullScreen-3 )
return CDialog::OnNcHitTest(point);
// rect.left = rect.right - 4;
// rect.top = rect.bottom - 4;
// 右下角一个 4*4 小块
// if ( rect.PtInRect( ptCur ) )
// return HTBOTTOMRIGHT;
if( CRect(rect.left, rect.top, rect.left+3, rect.top+3).PtInRect( ptCur ) )
return HTTOPLEFT;
else if( CRect(rect.right-3, rect.top, rect.right, rect.top+3).PtInRect( ptCur ) )
return HTTOPRIGHT;
else if( CRect(rect.left, rect.bottom-3, rect.left+3, rect.bottom).PtInRect( ptCur ) )
return HTBOTTOMLEFT;
else if( CRect(rect.right-3, rect.bottom-3, rect.right, rect.bottom).PtInRect( ptCur ) )
return HTBOTTOMRIGHT;
else if ( CRect(rect.left, rect.top, rect.left+3, rect.bottom).PtInRect( ptCur ) )
return HTLEFT;
else if( CRect(rect.right-3, rect.top, rect.right, rect.bottom).PtInRect( ptCur ) )
return HTRIGHT;
else if( CRect(rect.left, rect.top, rect.right-128, rect.top+3).PtInRect( ptCur ) ) // 128 Min,Max,Close
return HTTOP;
else if( CRect(rect.left, rect.bottom-3, rect.right, rect.bottom).PtInRect( ptCur ) )
return HTBOTTOM;
return CDialog::OnNcHitTest(point);
}
BOOL CTestDlg::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
{
CPoint ptCur;
CRect rect;
GetCursorPos( &ptCur );
GetWindowRect( &rect );
if ( rect.Width() >= m_nCxFullScreen-3 && rect.Height() >= m_nCyFullScreen-3 )
return CDialog::OnSetCursor(pWnd, nHitTest, message);
// rect.left = rect.right - 4;
// rect.top = rect.bottom - 4;
// if ( rect.PtInRect( ptCur ) )
// {
// SetCursor(LoadCursor(NULL, MAKEINTRESOURCE(IDC_SIZENWSE)));
// return 0;
// }
if( CRect(rect.left, rect.top, rect.left+3, rect.top+3).PtInRect( ptCur ) || CRect(rect.right-3, rect.bottom-3, rect.right, rect.bottom).PtInRect( ptCur ) )
{
SetCursor(LoadCursor(NULL, MAKEINTRESOURCE(IDC_SIZENWSE)));
return 0;
}
else if( CRect(rect.left, rect.bottom-3, rect.left+3, rect.bottom).PtInRect( ptCur ) || CRect(rect.left, rect.bottom-3, rect.left+3, rect.bottom).PtInRect( ptCur ) )
{
SetCursor(LoadCursor(NULL, MAKEINTRESOURCE(IDC_SIZENESW)));
return 0;
}
else if( CRect(rect.left, rect.top, rect.right-128, rect.top+3).PtInRect( ptCur ) || CRect(rect.left, rect.bottom-3, rect.right, rect.bottom).PtInRect( ptCur ) )
{
SetCursor(LoadCursor(NULL, MAKEINTRESOURCE(IDC_SIZENS)));
return 0;
}
else if( CRect(rect.left, rect.top, rect.left+3, rect.bottom).PtInRect( ptCur ) || CRect(rect.right-3, rect.top, rect.right, rect.bottom).PtInRect( ptCur ) )
{
SetCursor(LoadCursor(NULL, MAKEINTRESOURCE(IDC_SIZEWE)));
return 0;
}
return CDialog::OnSetCursor(pWnd, nHitTest, message);
}
void CTestDlg::OnNcLButtonDown(UINT nHitTest, CPoint point)
{
switch( nHitTest )
{
case HTTOP:
SendMessage( WM_SYSCOMMAND, SC_SIZE | WMSZ_TOP, MAKELPARAM(point.x, point.y));
return;
case HTBOTTOM:
SendMessage( WM_SYSCOMMAND, SC_SIZE | WMSZ_BOTTOM, MAKELPARAM(point.x, point.y));
return;
case HTLEFT:
SendMessage( WM_SYSCOMMAND, SC_SIZE | WMSZ_LEFT, MAKELPARAM(point.x, point.y));
return;
case HTRIGHT:
SendMessage( WM_SYSCOMMAND, SC_SIZE | WMSZ_RIGHT, MAKELPARAM(point.x, point.y));
return;
case HTTOPLEFT:
SendMessage( WM_SYSCOMMAND, SC_SIZE | WMSZ_TOPLEFT, MAKELPARAM(point.x, point.y));
return;
case HTTOPRIGHT:
SendMessage( WM_SYSCOMMAND, SC_SIZE | WMSZ_TOPRIGHT, MAKELPARAM(point.x, point.y));
return;
case HTBOTTOMLEFT:
SendMessage( WM_SYSCOMMAND, SC_SIZE | WMSZ_BOTTOMLEFT, MAKELPARAM(point.x, point.y));
return;
case HTBOTTOMRIGHT:
SendMessage( WM_SYSCOMMAND, SC_SIZE | WMSZ_BOTTOMRIGHT, MAKELPARAM(point.x, point.y));
return;
default:
CDialog::OnNcLButtonDown( nHitTest, point );
}
CDialog::OnNcLButtonDown( nHitTest, point );
}
我整体了一下,给大家看看:
UINT CTestDlg::OnNcHitTest( CPoint point )
{
CPoint ptCur;
CRect rect;
GetCursorPos( &ptCur );
GetWindowRect( &rect );
if ( rect.Width() >= m_nCxFullScreen-3 && rect.Height() >= m_nCyFullScreen-3 )
return CDialog::OnNcHitTest(point);
// rect.left = rect.right - 4;
// rect.top = rect.bottom - 4;
// 右下角一个 4*4 小块
// if ( rect.PtInRect( ptCur ) )
// return HTBOTTOMRIGHT;
if( CRect(rect.left, rect.top, rect.left+3, rect.top+3).PtInRect( ptCur ) )
return HTTOPLEFT;
else if( CRect(rect.right-3, rect.top, rect.right, rect.top+3).PtInRect( ptCur ) )
return HTTOPRIGHT;
else if( CRect(rect.left, rect.bottom-3, rect.left+3, rect.bottom).PtInRect( ptCur ) )
return HTBOTTOMLEFT;
else if( CRect(rect.right-3, rect.bottom-3, rect.right, rect.bottom).PtInRect( ptCur ) )
return HTBOTTOMRIGHT;
else if ( CRect(rect.left, rect.top, rect.left+3, rect.bottom).PtInRect( ptCur ) )
return HTLEFT;
else if( CRect(rect.right-3, rect.top, rect.right, rect.bottom).PtInRect( ptCur ) )
return HTRIGHT;
else if( CRect(rect.left, rect.top, rect.right-128, rect.top+3).PtInRect( ptCur ) ) // 128 Min,Max,Close
return HTTOP;
else if( CRect(rect.left, rect.bottom-3, rect.right, rect.bottom).PtInRect( ptCur ) )
return HTBOTTOM;
return CDialog::OnNcHitTest(point);
}
BOOL CTestDlg::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
{
CPoint ptCur;
CRect rect;
GetCursorPos( &ptCur );
GetWindowRect( &rect );
if ( rect.Width() >= m_nCxFullScreen-3 && rect.Height() >= m_nCyFullScreen-3 )
return CDialog::OnSetCursor(pWnd, nHitTest, message);
// rect.left = rect.right - 4;
// rect.top = rect.bottom - 4;
// if ( rect.PtInRect( ptCur ) )
// {
// SetCursor(LoadCursor(NULL, MAKEINTRESOURCE(IDC_SIZENWSE)));
// return 0;
// }
if( CRect(rect.left, rect.top, rect.left+3, rect.top+3).PtInRect( ptCur ) || CRect(rect.right-3, rect.bottom-3, rect.right, rect.bottom).PtInRect( ptCur ) )
{
SetCursor(LoadCursor(NULL, MAKEINTRESOURCE(IDC_SIZENWSE)));
return 0;
}
else if( CRect(rect.left, rect.bottom-3, rect.left+3, rect.bottom).PtInRect( ptCur ) || CRect(rect.left, rect.bottom-3, rect.left+3, rect.bottom).PtInRect( ptCur ) )
{
SetCursor(LoadCursor(NULL, MAKEINTRESOURCE(IDC_SIZENESW)));
return 0;
}
else if( CRect(rect.left, rect.top, rect.right-128, rect.top+3).PtInRect( ptCur ) || CRect(rect.left, rect.bottom-3, rect.right, rect.bottom).PtInRect( ptCur ) )
{
SetCursor(LoadCursor(NULL, MAKEINTRESOURCE(IDC_SIZENS)));
return 0;
}
else if( CRect(rect.left, rect.top, rect.left+3, rect.bottom).PtInRect( ptCur ) || CRect(rect.right-3, rect.top, rect.right, rect.bottom).PtInRect( ptCur ) )
{
SetCursor(LoadCursor(NULL, MAKEINTRESOURCE(IDC_SIZEWE)));
return 0;
}
return CDialog::OnSetCursor(pWnd, nHitTest, message);
}
void CTestDlg::OnNcLButtonDown(UINT nHitTest, CPoint point)
{
switch( nHitTest )
{
case HTTOP:
SendMessage( WM_SYSCOMMAND, SC_SIZE | WMSZ_TOP, MAKELPARAM(point.x, point.y));
return;
case HTBOTTOM:
SendMessage( WM_SYSCOMMAND, SC_SIZE | WMSZ_BOTTOM, MAKELPARAM(point.x, point.y));
return;
case HTLEFT:
SendMessage( WM_SYSCOMMAND, SC_SIZE | WMSZ_LEFT, MAKELPARAM(point.x, point.y));
return;
case HTRIGHT:
SendMessage( WM_SYSCOMMAND, SC_SIZE | WMSZ_RIGHT, MAKELPARAM(point.x, point.y));
return;
case HTTOPLEFT:
SendMessage( WM_SYSCOMMAND, SC_SIZE | WMSZ_TOPLEFT, MAKELPARAM(point.x, point.y));
return;
case HTTOPRIGHT:
SendMessage( WM_SYSCOMMAND, SC_SIZE | WMSZ_TOPRIGHT, MAKELPARAM(point.x, point.y));
return;
case HTBOTTOMLEFT:
SendMessage( WM_SYSCOMMAND, SC_SIZE | WMSZ_BOTTOMLEFT, MAKELPARAM(point.x, point.y));
return;
case HTBOTTOMRIGHT:
SendMessage( WM_SYSCOMMAND, SC_SIZE | WMSZ_BOTTOMRIGHT, MAKELPARAM(point.x, point.y));
return;
default:
CDialog::OnNcLButtonDown( nHitTest, point );
}
CDialog::OnNcLButtonDown( nHitTest, point );
}