// InformationTip.cpp : implementation file
//
#include "stdafx.h"
#include "taskmng.h"
#include "InformationTip.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CInformationTip dialog
CInformationTip::CInformationTip(CWnd* pParent /*=NULL*/)
: CDialog(CInformationTip::IDD, pParent)
{
//{{AFX_DATA_INIT(CInformationTip)
//}}AFX_DATA_INIT
}
void CInformationTip::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CInformationTip)
DDX_Control(pDX, IDC_BUTTON_TIPINFO, m_ButtonCtrl_TipInfo);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CInformationTip, CDialog)
//{{AFX_MSG_MAP(CInformationTip)
ON_WM_SIZE()
ON_WM_TIMER()
ON_WM_KILLFOCUS()
ON_WM_MOUSEMOVE()
ON_WM_MOVE()
ON_WM_CTLCOLOR()
ON_WM_DESTROY()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CInformationTip message handlers
BOOL CInformationTip::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
/*获得屏幕高度和宽度*/
m_ScreenPos.m_ScreenX = ::GetSystemMetrics(SM_CXSCREEN);
m_ScreenPos.m_ScreenY = ::GetSystemMetrics(SM_CYSCREEN);
m_dwTime = 2000; /*初始停留时间:10秒*/
m_dwStep = 20; /*初始平滑度*/
m_iRate = 0; /*对话框充实度*/
m_IsAlreadyShow = TRUE;
m_DlkBkBrush.CreateSolidBrush(RGB(212,208,200));
m_TipInf_Font.CreateFont(16,0,0,0,FW_BOLD,FALSE,TRUE,0,DEFAULT_CHARSET,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,DEFAULT_PITCH|FF_SWISS,"宋体");
// m_TipInfoImage.Create(32,32,TRUE|ILC_COLOR8,4,0);
// m_TipInfoImage.Add(((CTaskMngApp*)AfxGetApp())->LoadIcon(IDI_ICON_USERS));
InitMemCtrl();
SetTimer(WM_TIMER,m_dwTime,NULL);
/****************************************************************/
/****************************************************************/
::SetWindowLong(GetSafeHwnd(),GWL_EXSTYLE,GetWindowLong(GetSafeHwnd(),GWL_EXSTYLE)^0x80000);
m_hUser32DLL = ::LoadLibrary("User32.DLL");
if(m_hUser32DLL)
{
m_fFill = NULL;
m_fFill = (SET_FILL_CLR)::GetProcAddress(m_hUser32DLL,"SetLayeredWindowAttributes");
if (m_fFill)
{
SetDlgLayoutColor(20);
}
}
ShowInformations(TRUE);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CInformationTip::SetDlgLayoutColor(int iRate)
{
if (iRate > 90)
iRate = 90;
else if (iRate < 10)
iRate = 20;
m_fFill(GetSafeHwnd(),0,(255*iRate)/100,2);
}
void CInformationTip::InitMemCtrl()
{
m_ButtonCtrl_TipInfo.SetFont(&m_TipInf_Font);
m_ButtonCtrl_TipInfo.SetWindowText("您有一条新消息!");
}
void CInformationTip::SetDlgBkColor(COLORREF Clr)
{
m_DlkBkBrush.CreateSolidBrush(Clr);
}
/*设置完毕后,下一次应用改变*/
void CInformationTip::SetShowTipAtWhere(TIPSHOWPOS TSP)
{
}
/*设置完毕后,下一次应用改变*/
void CInformationTip::SetShowTipTime(DWORD dwTime)
{
m_dwTime = dwTime;
}
/*设置完毕后,下一次应用改变*/
void CInformationTip::SetKeepMoveStep(DWORD dwStep)
{
m_dwStep = dwStep;
}
void CInformationTip::OnSize(UINT nType, int cx, int cy)
{
CDialog::OnSize(nType, cx, cy);
// TODO: Add your message handler code here
}
void CInformationTip::ShowInformations(BOOL IsShow)
{
if (!IsShow)
{
KeepMoveMoveMove(IsShow);
m_IsAlreadyShow = FALSE;
return ;
}
CRect rect;
rect.SetRect(0,0,0,0);
GetWindowRect(&rect);
SetWindowPos(&wndTopMost,
m_ScreenPos.m_ScreenX-rect.Width(),
m_ScreenPos.m_ScreenY-NEAR_SIDE,
rect.Width(),NEAR_SIDE,SWP_NOSIZE|SWP_SHOWWINDOW);
KeepMoveMoveMove(IsShow);
m_IsAlreadyShow = TRUE;
}
void CInformationTip::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
POINT pt;
CRect rc;
GetCursorPos(&pt);
GetWindowRect(&rc);
if (!PtInRect(&rc,pt))/*若鼠标不在窗体内,隐藏窗体*/
{
KillTimer(WM_TIMER);
ShowInformations(FALSE);
}
CDialog::OnTimer(nIDEvent);
}
void CInformationTip::KeepMoveMoveMove(BOOL IsShow)
{
CRect rc;
rc.SetRect(0,0,0,0);
GetWindowRect(&rc);
int i = 100;
if (!IsShow)
{
while (rc.top < (m_ScreenPos.m_ScreenY-NEAR_SIDE))
{
SetWindowPos(&wndTopMost,rc.left,rc.top,rc.right,rc.bottom,SWP_NOSIZE|SWP_HIDEWINDOW);
rc.top += m_dwStep;
if (rc.top > (m_ScreenPos.m_ScreenY-NEAR_SIDE))
{
rc.top = m_ScreenPos.m_ScreenY-NEAR_SIDE;
break;
}
SetWindowPos(&wndTopMost,rc.left,rc.top,rc.right,rc.bottom,SWP_NOSIZE|SWP_SHOWWINDOW);
if (m_fFill)
SetDlgLayoutColor((m_iRate-=5,m_iRate));
::Sleep(20);
}
SetWindowPos(&wndTopMost,rc.left,rc.top,rc.right,rc.bottom,SWP_NOSIZE|SWP_SHOWWINDOW);
}
else
{
/*
while (rc.top)
{
SetWindowPos(&wndTopMost,rc.left,rc.top,rc.right,rc.bottom,SWP_NOSIZE|SWP_HIDEWINDOW);
rc.top -= m_dwStep;
rc.bottom += m_dwStep;
if (rc.top <= 0)
{
rc.top = 0;
SetWindowPos(&wndTopMost,rc.left,rc.top,rc.right,rc.bottom,SWP_NOSIZE|SWP_SHOWWINDOW);
break;
}
SetWindowPos(&wndTopMost,rc.left,rc.top,rc.right,rc.bottom,SWP_NOSIZE|SWP_SHOWWINDOW);
}*/
for (int i=0;i<m_dwStep;++i)
{
SetWindowPos(&wndTopMost,rc.left,rc.top,rc.right,rc.bottom,SWP_NOSIZE|SWP_HIDEWINDOW);
rc.top -= m_dwStep;
SetWindowPos(&wndTopMost,rc.left,rc.top,rc.right,rc.bottom,SWP_NOSIZE|SWP_SHOWWINDOW);
if (m_fFill)
SetDlgLayoutColor((m_iRate+=5,m_iRate));
::Sleep(20);
}
}
}
void CInformationTip::OnKillFocus(CWnd* pNewWnd)
{
CDialog::OnKillFocus(pNewWnd);
// TODO: Add your message handler code here
}
void CInformationTip::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if (!m_IsAlreadyShow)
{
ShowInformations(TRUE);
SetTimer(WM_TIMER,m_dwTime,NULL);
}
CDialog::OnMouseMove(nFlags, point);
}
void CInformationTip::OnMove(int x, int y)
{
CDialog::OnMove(x, y);
// TODO: Add your message handler code here
}
void CInformationTip::OnOK()
{
/*
if (!m_IsAlreadyShow)
{
ShowInformations(TRUE);
SetTimer(WM_TIMER,m_dwTime,NULL);
}*/
return ;
}
void CInformationTip::Cancel()
{
/*
if (!m_IsAlreadyShow)
{
ShowInformations(TRUE);
SetTimer(WM_TIMER,m_dwTime,NULL);
}*/
return ;
}
void CInformationTip::OnClose()
{
/*
if (!m_IsAlreadyShow)
{
ShowInformations(TRUE);
SetTimer(WM_TIMER,m_dwTime,NULL);
}*/
return ;
}
HBRUSH CInformationTip::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
/*HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);*/
if (pWnd->GetDlgCtrlID() == IDC_BUTTON_TIPINFO)
{
pDC->SetTextColor(RGB(255,0,0));
pDC->SetBkColor(RGB(212,208,200));
pDC->SetBkMode(TRANSPARENT);
}
// TODO: Change any attributes of the DC here
// TODO: Return a different brush if the default is not desired
return m_DlkBkBrush;
}
BOOL CInformationTip::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class
return CDialog::PreTranslateMessage(pMsg);
}
void CInformationTip::OnDestroy()
{
CDialog::OnDestroy();
// TODO: Add your message handler code here
if (m_hUser32DLL)
::FreeLibrary(m_hUser32DLL);
}