所谓QQ自动隐藏效果无非就是将对话框放到屏幕外面就行了。
大致步骤:
1、建立MFC对话框项目;
2、为对话框映射定时器消息;
3、开启定时器;
4、定义定时器操作函数;
5、关闭定时器;
具体步骤:
1、映射定时器WM_TIMER消息可以用多种方法,一种是下面的方法,还有一种就是使用类向导;
2、映射成功后会自动生成以下代码(已经在里面加上实现停靠效果的代码了):
//1、
afx_msg void OnTimer(UINT nIDEvent);
//2、
BEGIN_MESSAGE_MAP(CNoteManageDlg, CDialog)
//{{AFX_MSG_MAP(CNoteManageDlg)
ON_WM_TIMER()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
//3、
void CNoteManageDlg::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
CRect rc,rect;
CPoint m_Point;
//使用switch语句,是为多个定时器设计的,如果没有多个定时器的话,可以不用switch语句.
switch(nIDEvent)
{
case 1 :break;
case 2 :
//以下就是实现停靠效果的代码了
{
GetWindowRect(&rect);
rc.CopyRect(&rect);
GetCursorPos(&m_Point);
if (rect.top<0&&PtInRect(rect,m_Point))
{
rect.top = 0;
MoveWindow(rect.left,rect.top,rc.Width(),rc.Height());
}
else if(rect.top>-3&&rect.top<3&&!PtInRect(rect,m_Point))
{
rect.top = 3-rect.Height();
MoveWindow(rect.left,rect.top,rc.Width(),rc.Height());
}
}
break;
}
CDialog::OnTimer(nIDEvent);
}