This is also a problem encountered by the project. It is required that the dialog box without borders should be dragged with the mouse to change the size. The implementation of the borderless dialog box is definitely different from that of the borderless dialog box.
One method I found on the Internet is:
You need to process the following three messages:
WM_NCHITTEST WM_SETCURSOR WM_NCLBUTTONDOWN
Message Processing functions:
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));}
The above practice is a bit problematic, as in the judgment, the left and right sides, the top left, the bottom left, the top right, and the bottom right won't be able to do it.
There are all improvement methods:
UINT CTestDlg::OnNcHitTest( CPoint point ){CPoint ptCur;CRect rect;GetCursorPos( &ptCur );GetWindowRect( &rect );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,Closereturn 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);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 );}