1.新建基本对话框应用程序Hide,并添加OnTimer事件
void CHideDlg::OnTimer(UNIT nIDEvent)
{
switch(nIDEvent)
{
case 1:
{
CRect rc;
CRect rect;
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()); //隐藏窗体
}
}
break;
case 2:
{
}
break;
}
}
2.启动计时器,在OnInitDialog()函数中添加SetTimer(1,200,NULL)
BOOL CHideDlg::OnInitDialog()
{
SetTimer(1,100,NULL);
SetTimer(2,2000,NULL);//可以设置多个,但应与OnTimer中的分别对应
return TRUE;
// return TRUE unless you set the focus to a control }