获得CTextView的窗口区大小,设你获得后保存在CRect parentRect对象里面,将这个参数作为你浮动窗口的成员变量保存,然后重载你的浮动对话框的OnMove函数,在里面限制窗口的移动区域,m_Widht,和m_height为你的浮动窗口的宽度和高度,自己在OnInitDialog里面初始化void CRestrictDlg::OnMove(int x, int y) { CDialog::OnMove(x, y);
// TODO: Add your message handler code here CRect rect; GetClientRect(&rect);
if (x<parentRect.left || y <parentRect.top) { MoveWindow(parentRect.left,parentRect.top,m_Width,m_height,TRUE); } if (x>parentRect.right-m_Width || y>parentRect.bottom-m_height) { MoveWindow(parentRect.right-m_Width,parentRect.bottom-m_height,m_Width,m_height,TRUE); }
if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
!m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
{
TRACE0("Failed to create toolbar\n");
return -1; // fail to create
}
{
CDialog::OnMove(x, y);
// TODO: Add your message handler code here
CRect rect;
GetClientRect(&rect);
if (x<parentRect.left || y <parentRect.top)
{
MoveWindow(parentRect.left,parentRect.top,m_Width,m_height,TRUE);
} if (x>parentRect.right-m_Width || y>parentRect.bottom-m_height)
{
MoveWindow(parentRect.right-m_Width,parentRect.bottom-m_height,m_Width,m_height,TRUE);
}
}