duilib : 滑动显示的窗口实现
来源:互联网 发布:免费配货软件下载 编辑:程序博客网 时间:2024/05/19 16:02
前几天jhgwqp@csdn留言, 问有没有Demo工程. 做了一个给他.
原来记录这个技术点时, 也想做个Demo留念. 随着时间的推移, 已经忘了这事.
经jhgwqp@csdn提醒, 将这事做了.
工程下载点: srcbk_2015_0722_1819_src-sliding-window-display.rar
编译环境: vs2010 vc++ duilib
效果图:
代码预览:
建立弹出的滑动对话框时, 要以子窗口风格创建, 这样, 主窗口移动时, 我们就不用负责子窗口的位置移动了.
- void CMainDlg::CreateDlgSlidingShow()
- {
- do
- {
- if (NULL != m_pDlgSlidingShow)
- break;
-
- m_pDlgSlidingShow = new CDlgSlidingShow(
- XML_FILE_NAME_dlgSlidingShow_MainDlg,
- WND_CLASS_NAME_dlgSlidingShow_MainDlg);
-
- if (NULL == m_pDlgSlidingShow)
- break;
-
- m_pDlgSlidingShow->SetOwner(this);
- m_pDlgSlidingShow->Create(
- this->GetHWND(),
- WND_DISP_NAME_dlgSlidingShow_MainDlg,
- UI_WNDSTYLE_CHILD,
- WS_EX_WINDOWEDGE);
-
-
-
- m_pDlgSlidingShow->ShowWindow(false, false);
- } while (0);
- }
在消息中处理子窗口的滑动显示, 对DuiLib的显示操作, 最好放在消息中处理, 防止崩溃.- LRESULT CDlgSlidingShow::WndMessageProc_SlidingShow(UINT uMsg, WPARAM wParam, LPARAM lParam)
- {
-
-
-
-
-
-
- RECT rtMain;
- RECT rtLayout;
- RECT rtLayoutRate;
- const UINT uDispTimeMax = 1000 * 6;
-
-
-
- const float fDispStep = 0.03f;
- const UINT uMinHeight = 10;
-
-
- const float fRateMin = 0.05f;
- static UINT uDispTimeTotal = 0;
-
- do
- {
- if (!m_bPlay)
- break;
-
- if (eDispStatus_inc == m_Status)
- {
- m_fRate += fDispStep;
- if (m_fRate > 1.0f)
- {
- m_fRate = 1.0f;
- uDispTimeTotal = 0;
- m_Status = eDispStatus_disp;
- }
- else if (m_fRate < fRateMin)
- m_fRate = fRateMin;
- }
- else if (eDispStatus_disp == m_Status)
- {
- uDispTimeTotal += TIMER_DELAY_PLAY;
- if (uDispTimeTotal >= uDispTimeMax)
- m_Status = eDispStatus_dec;
- }
- else if (eDispStatus_dec == m_Status)
- {
- m_fRate -= fDispStep;
- if (m_fRate <= fRateMin)
- {
- m_fRate = fRateMin;
- uDispTimeTotal = 0;
- m_Status = eDispStatus_inc;
- m_bPlay = FALSE;
- }
- }
-
-
- ::GetClientRect(m_pOwner->GetHWND(), &rtMain);
-
- rtLayout.right = rtMain.right;
- rtLayout.bottom = rtMain.bottom;
- rtLayout.left = rtLayout.right - (m_rtMeOrg.right - m_rtMeOrg.left);
- rtLayout.top = rtLayout.bottom - (m_rtMeOrg.bottom - m_rtMeOrg.top);
-
- rtLayoutRate.left = rtLayout.left;
- rtLayoutRate.right = rtLayout.right;
- rtLayoutRate.bottom = rtLayout.bottom;
- rtLayoutRate.top = rtLayout.bottom - 1.0f * (rtLayout.bottom - rtLayout.top) * m_fRate;
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- ::MoveWindow(
- this->GetHWND(),
- rtLayoutRate.left,
- rtLayoutRate.top,
- rtLayoutRate.right,
- rtLayoutRate.bottom,
- TRUE);
-
- ::ShowWindow(this->GetHWND(), m_bPlay ? SW_SHOW : SW_HIDE);
- if (!m_bPlay)
- {
- ::PostMessageW(this->GetHWND(), WM_CLOSE, 0, 0);
- }
- } while (0);
-
- return S_OK;
- }
2014-03-28 03:23 的备份
- void CFloatTextMsgDlg::Play()
- {
-
-
-
-
-
-
- RECT rtTabView;
- RECT rtMain;
- RECT rtLayout;
- RECT rtLayoutRate;
- const UINT uDispTimeMax = 1000 * 6;
-
-
-
- const float fDispStep = 0.03f;
- const UINT uMinHeight = 10;
-
-
- const float fRateMin = 0.05f;
- static UINT uDispTimeTotal = 0;
-
- if (!m_bPlay)
- return;
-
- if (eDispStatus_inc == m_Status)
- {
- m_fRate += fDispStep;
- if (m_fRate > 1.0f)
- {
- m_fRate = 1.0f;
- uDispTimeTotal = 0;
- m_Status = eDispStatus_disp;
- }
- else if (m_fRate < fRateMin)
- m_fRate = fRateMin;
- }
- else if (eDispStatus_disp == m_Status)
- {
- uDispTimeTotal += TIMER_DELAY_PLAY;
- if (uDispTimeTotal >= uDispTimeMax)
- m_Status = eDispStatus_dec;
- }
- else if (eDispStatus_dec == m_Status)
- {
- m_fRate -= fDispStep;
- if (m_fRate <= fRateMin)
- {
- m_fRate = fRateMin;
- uDispTimeTotal = 0;
- m_Status = eDispStatus_inc;
- m_bPlay = FALSE;
- }
- }
-
- m_pOwner->GetTabViewFramePosition(rtTabView);
- ::GetWindowRect(m_pOwner->GetHWND(), &rtMain);
-
- rtLayout.left = rtMain.left + rtTabView.left;
- rtLayout.right = rtLayout.left + (m_rtMeOrg.right - m_rtMeOrg.left);
- rtLayout.top = rtMain.top + rtTabView.bottom - (m_rtMeOrg.bottom - m_rtMeOrg.top);
- rtLayout.bottom = rtMain.top + rtTabView.bottom;
-
- rtLayoutRate.left = rtLayout.left;
- rtLayoutRate.right = rtLayout.right;
- rtLayoutRate.bottom = rtLayout.bottom;
- rtLayoutRate.top = rtLayout.bottom - 1.0f * (rtLayout.bottom - rtLayout.top) * m_fRate;
-
-
-
-
-
- ::SetWindowPos(
- this->GetHWND(),
- m_pOwner->GetHWND(),
- rtLayoutRate.left,
- rtLayoutRate.top,
- rtLayoutRate.right - rtLayoutRate.left,
- rtLayoutRate.bottom - rtLayoutRate.top,
- SWP_SHOWWINDOW);
-
- ::ShowWindow(this->GetHWND(), m_bPlay ? SW_SHOW : SW_HIDE);
- }
0 0