/*********************************************************** *说明: 在VC++6.0中让窗体像QQ同样自动隐藏 *备注:测试代码的对话框程序的工程名为:HideFrmLikeQQ *原理:运用窗体的OnTimer事件 *做者:袁培荣 yuanpeirong@vip.qq.com *修改时间:2011年09月26日 ***********************************************************/ //第一步:给窗体添加OnTimer事件并加入以下代码 void CHideFrmLikeQQDlg::OnTimer(UINT nIDEvent) { // TODO: Add your message handler code here and/or call default 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()); //隐藏窗体 } CDialog::OnTimer(nIDEvent); } //第二步启动计时器: //在窗体的OnInitDialog()函数中加入这句代码:SetTimer(1,100,NULL); //具体位置以下 BOOL CHideFrmLikeQQDlg::OnInitDialog() { …………………………………………//这里省略了向导自动添加的代码 // TODO: Add extra initialization here SetTimer(1,100,NULL);//启动计时器 return TRUE; // return TRUE unless you set the focus to a control }