int nx = rect.right - rectInit.Width();
int ny = cy - rectInit.Height();
rectInit.MoveToXY(nx, ny);
MoveWindow(rectInit);
}
void CMsgTipDlg::OnTimer(UINT_PTR nIDEvent)
{
RECT rect;
SystemParametersInfo(SPI_GETWORKAREA,0,&rect,0);
int cy = rect.bottom-rect.top;
int cx = rect.right-rect.left;
CRect rectTip;
GetWindowRect(&rectTip);
switch (nIDEvent)
{
case BLAND_IN:
{
if (m_bAlpha > (BLAND_MAX - BLAND_SPAN))
{
m_bAlpha = BLAND_MAX;
}
else
{
m_bAlpha += BLAND_SPAN;
}
SetLayeredWindowAttributes(BLAND_COLOR, m_bAlpha, LWA_ALPHA);
if (BLAND_MAX == m_bAlpha)
{
KillTimer(BLAND_IN);
SetTimer(DLG_DELAY, DELAY_ELAPSE, NULL);
}
break;
}
case DLG_DELAY:
{
KillTimer(DLG_DELAY);
SetTimer(BLAND_OUT, OUT_ELAPSE, NULL);
break;
}
case BLAND_OUT:
{
if (m_bAlpha < BLAND_SPAN)
{
m_bAlpha = BLAND_MIN;
}
else
{
m_bAlpha -= BLAND_SPAN;
}
SetLayeredWindowAttributes(BLAND_COLOR, m_bAlpha, LWA_ALPHA);
if (BLAND_MIN == m_bAlpha)
{
KillTimer(BLAND_OUT);
PostMessage(WM_CLOSE);
}
break;
}
}
CDialog::OnTimer(nIDEvent);
}
void CMsgTipDlg::OnCancel()
{
DestroyWindow();
}
void CMsgTipDlg::PostNcDestroy()
{
CDialog::PostNcDestroy();
//窗口销毁时,删除该对象
m_pTipMng->RemoveTipWindow(m_nTipID);
}
void CMsgTipDlg::OnBnClickedOk()
{
OnCancel();
//::MessageBox(AfxGetMainWnd()->GetSafeHwnd(), _T("提示框的反馈-是"), _T("提示"), MB_OK);
}
void CMsgTipDlg::OnBnClickedCancel()
{
OnCancel();
}
BOOL CMsgTipDlg::PreTranslateMessage(MSG* pMsg)
{
//对话框屏蔽Enter和ESC键
if (WM_KEYDOWN == pMsg->message)
{
if ( (VK_RETURN == pMsg->wParam)
|| (VK_ESCAPE == pMsg->wParam))
{
return TRUE;
}
}
return CDialog::PreTranslateMessage(pMsg);
}
void CMsgTipDlg::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CRect rect;
GetClientRect(&rect);
//显示对话框
if (m_bAlpha < BLAND_MAX)
{
KillTimer(BLAND_IN);
KillTimer(DLG_DELAY);
KillTimer(BLAND_OUT);
m_bAlpha = BLAND_MAX;
SetLayeredWindowAttributes(BLAND_COLOR, m_bAlpha, LWA_ALPHA);
//继续等待
SetTimer(DLG_DELAY, DELAY_ELAPSE, NULL);
}
CDialog::OnMouseMove(nFlags, point);
}
2、消息框管理器
消息框管理器功能:控制每次只弹出一个消息框。
MsgTipMng.h。
[cpp]
/*
@brief 消息提示管理器
@date 2012-08-10
*/
#pragma once
#include "MsgTipDlg.h"
#include
#include
using namespace std;
class CMsgTipMng
{
public:
CMsgTipMng(void);
~CMsgTipMng(void);
void AddTipWindow(const CString& strTipInfo);
void RemoveTipWindow(int nTipID);
private:
void ShowTipWindow();
private:
vector
bool m_bInShow;//是否有消息框弹出
};
MsgTipMng.cp