/*********************************************************** *說明: 在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 }