标签:
//1、添加用到的成员变量及 函数 class CxxxDialog : public CDialog { //... private: //窗口的尺寸(大小) CSize m_szWindow; //开始滑动挪动窗口位置 bool m_bHide; //滑动次数 int m_nSildeCount; //父窗口的位置 CRect m_rcParentPos; protected: //初始化参数 afx_msg void OnTimer(UINT nIDEvent) ; void InitSlideParam(); public: void StartSliding(bool bHide = false); }; //2、添加启动挪动窗口的函数 StartSliding void CChild::StartSliding(bool bHide) { InitSlideParam(); SetTimer(1,500,NULL); m_bHide = bHide; } //3、添加初始化函数InitSlideParam() void CxxxDialog::InitSlideParam() { //初始化滑动次数 m_nSildeCount = 1; //获取父窗口的先对的位置 if(GetParent() !=NULL) { GetParent()->GetWindowRect(&m_rcParentPos); } else { int nScreenWidth=GetSystemMetrics(SM_CXSCREEN); int nScreenHeight=GetSystemMetrics(SM_CYSCREEN); m_rcParentPos.left = 0; m_rcParentPos.top = 0; m_rcParentPos.right = (nScreenWidth - m_szWindow.cx)/2; m_rcParentPos.bottom = (nScreenHeight - m_szWindow.cy)/2; } } //4、用定时器挪动窗口 void CChild::OnTimer(UINT nIDEvent) { KillTimer(1); int nWidth=m_szWindow.cx/25; if(m_szWindow.cx>=m_nSildeCount*nWidth) { if(!m_bHide) { SetWindowPos(GetParent() ,m_rcParentPos.right -m_szWindow.cx +m_nSildeCount*nWidth, m_rcParentPos.top, m_szWindow.cx, m_szWindow.cy, SWP_SHOWWINDOW|SWP_NOOWNERZORDER|SWP_NOACTIVATE ); } else { SetWindowPos(GetParent(),m_rcParentPos.right+m_szWindow.cx-m_nSildeCount*nWidth, m_rcParentPos.top, m_szWindow.cx, m_szWindow.cy, SWP_NOOWNERZORDER|SWP_NOACTIVATE); } m_nSildeCount++; SetTimer(1,10,NULL); } if(m_bHide && m_nSildeCount*nWidth>=m_szWindow.cx) ShowWindow(SW_HIDE); CDialog::OnTimer(nIDEvent); }
标签:
原文地址:http://blog.csdn.net/chenlu5201314/article/details/51332162