首先,创建对话框工程,重写OnTimer;
void CQQDlg::OnTimer(UINT_PTR nIDEvent)
{
// TODO: Add your message handler code here and/or call default
CRect rect;
CRect re;
GetWindowRect(&rect);
re.CopyRect(&rect);
CPoint point;
GetCursorPos(&point);
if (rect.top < 0 && PtInRect(rect,point))
{
rect.top = 0;
MoveWindow( rect.left, rect.top ,re.Width(), re.Height() );
}
else if (rect.top > -3 && rect.top < 3 && !PtInRect(rect, point))
{
rect.top = 3 - rect.Height();
MoveWindow(rect.left, rect.top ,re.Width(), re.Height());
}
CDialog::OnTimer(nIDEvent);
}
通过判断窗口位置,利用MoveWindow函数实现窗口的隐藏功能。