CRect类
数据成员有left,top,right,和bottom。
left左上角X坐标,top左上角Y坐标,right右下角X坐标,bottom右下角Y坐标。
rect.InflateRect(3,3);//修改CRect的宽和高,每次增加3,3
rect.OffsetRect(5,5);//修改CRect的x、y值,每次增加5,5
CWnd类中
GetWindowRect(rect);
MoveWindow(rect);
SetTimer
KillTimer
void CTestCWndDlg::OnBnClickedButton5()
{
DWORD dwExStyle = m_edit.GetExStyle();
m_edit.ModifyStyleEx(0,WS_EX_CLIENTEDGE | WS_EX_DLGMODALFRAME );
CRect rect;
m_edit.GetWindowRect(rect);//得到相对于当前屏幕的位置
ScreenToClient(rect);//将相对于屏幕的位置改变为相对于当前客户区的位置
rect.InflateRect(3,3);//修改CRect的宽和高,每次增加3,3
rect.OffsetRect(5,5);//修改CRect的x、y值,每次增加5,5
m_edit.MoveWindow(rect);//得到相对于当前客户区的位置
Invalidate();
}
void CTestCWndDlg::OnTimer(UINT_PTR nIDEvent)
{
CRect wRect,cRect;
m_edit.GetWindowRect(wRect);
ScreenToClient(wRect);
wRect.OffsetRect(5,5);
GetClientRect(cRect);//得到当前客户区的位置
if(wRect.right >= cRect.right || wRect.bottom >= cRect.bottom)
KillTimer(123);//关闭计时器
m_edit.MoveWindow(wRect);
CDialog::OnTimer(nIDEvent);
}
void CTestCWndDlg::OnBnClickedButton6()
{
SetTimer(123,500,NULL);//ID为123,每隔500ms触发一次OnTimer
}