思路:在定时器中判断鼠标的位置和窗体的位置,然后使用MoveWindow方法移动窗体,从而实现窗体的显示和隐藏
void CDlgDlg::OnTimer(UINT_PTR nIDEvent)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
// 隐藏窗体
if (nIDEvent == ID_SHOWDIDE){
CRect rect, rc;
GetWindowRect(&rect);
rc.CopyRect(&rect);
CPoint point;
GetCursorPos(&point);
if (rect.top < 0 && PtInRect(rect, point)) // 显示窗体
{
rect.top = 0;
MoveWindow(rect.left, rect.top, rc.Width(), rc.Height());
}
else if (rect.top >-3 && rect.top < 3 && !PtInRect(rect, point)) // 隐藏窗体
{
rect.top = 3 - rect.Height();
MoveWindow(rect.left, rect.top, rc.Width(), rc.Height());
}
}
CDialogEx::OnTimer(nIDEvent);
}