📄 alarmlamp.cpp
字号:
// AlarmLamp.cpp : implementation file
//
#include "stdafx.h"
#include "gtmpeg.h"
#include "AlarmLamp.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////////////////////
CAlarmLamp::CAlarmLamp()
{
WNDCLASS wndcls;
HINSTANCE hInst = AfxGetResourceHandle();
if (!(::GetClassInfo(hInst, "AlarmLampCtrl", &wndcls)))
{
wndcls.style = CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW;
wndcls.lpfnWndProc = ::DefWindowProc;
wndcls.cbClsExtra = wndcls.cbWndExtra = 0;
wndcls.hInstance = hInst;
wndcls.hIcon = NULL;
wndcls.hCursor = NULL;
wndcls.hbrBackground = NULL;//(HBRUSH) (Brush.operator HBRUSH());//COLOR_3DFACE + 1
wndcls.lpszMenuName = NULL;
wndcls.lpszClassName = "AlarmLampCtrl";
if (!AfxRegisterClass(&wndcls))
AfxThrowResourceException();
}
m_bSway=FALSE;
m_pToolTip = NULL;
m_bDBClk=FALSE;
}
CAlarmLamp::~CAlarmLamp()
{
if (m_pToolTip)
{
delete (m_pToolTip);
m_pToolTip = NULL;
}
KillTimer(0);
}
/////////////////////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////////////////////
BEGIN_MESSAGE_MAP(CAlarmLamp, CWnd)
//{{AFX_MSG_MAP(CAlarmLamp)
ON_WM_CREATE()
ON_WM_LBUTTONDOWN()
ON_WM_PAINT()
ON_WM_TIMER()
ON_WM_LBUTTONDBLCLK()
//}}AFX_MSG_MAP
ON_NOTIFY_EX_RANGE(TTN_NEEDTEXT,0,0xFFFF,OnToolTipNotify)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////////////////////
BOOL CAlarmLamp::Create(CString sCaption,CRect rect, CWnd* pParentWnd, UINT nID)
{
m_sCaption=sCaption;
return CWnd::Create("AlarmLampCtrl",NULL,WS_VISIBLE|WS_CHILD, rect, pParentWnd, nID);
}
/////////////////////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////////////////////
BOOL CAlarmLamp::CreatePoint(CString sCaption,CPoint point, CWnd* pParentWnd, UINT nID)
{
CRect rect;
rect.left=point.x-8;
rect.right=point.x+8;
rect.top=point.y-8;
rect.bottom=point.y+8;
m_bDBClk=TRUE;
return Create(sCaption,rect,pParentWnd, nID);
}
/////////////////////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////////////////////
BOOL CAlarmLamp::PreTranslateMessage(MSG* pMsg)
{
switch(pMsg->message)
{
case WM_LBUTTONDOWN:
case WM_MOUSEMOVE:
case WM_LBUTTONUP:
case WM_MBUTTONDOWN:
case WM_MBUTTONUP:
case WM_RBUTTONDOWN:
case WM_RBUTTONUP:
if (m_pToolTip)
{
CPoint ptCurrentPos;
ptCurrentPos.x = LOWORD(pMsg->lParam);
ptCurrentPos.y = HIWORD(pMsg->lParam);
if (m_rectSearch.PtInRect(ptCurrentPos) == FALSE)
{
m_pToolTip->Activate(FALSE);
}
m_pToolTip->Activate(TRUE);
m_pToolTip->RelayEvent(pMsg);
}
}
return CWnd::PreTranslateMessage(pMsg);
}
/////////////////////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////////////////////
void CAlarmLamp::OnLButtonDown(UINT nFlags, CPoint point)
{
CWnd::OnLButtonDown(nFlags, point);
}
/////////////////////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////////////////////
void CAlarmLamp::OnPaint()
{
CPaintDC dc(this);
CRect rect;
GetClientRect(rect);
CBitmap Bitmap;
Bitmap.LoadBitmap(IDB_ALARMLAMP_1);
//rect.DeflateRect(1,1);
APutImage(&dc,rect.left,rect.top,&Bitmap,RGB(255,255,255));
}
/////////////////////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////////////////////
int CAlarmLamp::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CWnd::OnCreate(lpCreateStruct) == -1)
return -1;
ModifyStyleEx(0,WS_EX_TRANSPARENT);
CreateTooltips();
return 0;
}
//////////////////////////////////////
//
/////////////////////////////////////
void CAlarmLamp::CreateTooltips()
{
if (m_pToolTip == NULL)
{
CRect rect;
GetClientRect(rect);
m_pToolTip = new CToolTipCtrl;
if(!m_pToolTip)
{
MessageBox(_T("Unable to allocate memory for ToolTips!"));
}
else
{
if( !m_pToolTip->Create(this, TTS_ALWAYSTIP) )
{
MessageBox(_T("Unable to Create ToolTips for Grid!"));
}
else
{
m_pToolTip->AddTool(this, LPSTR_TEXTCALLBACK, rect, 1);
m_pToolTip->Activate(TRUE);
m_pToolTip->SendMessage(TTM_SETDELAYTIME,TTDT_AUTOPOP,30000);
EnableToolTips(TRUE);
}
}
}
}
////////////////////////////////////////
//
///////////////////////////////////////
void CAlarmLamp::SetCaption(CString sCaption)
{
m_sCaption=sCaption;
}
////////////////////////////////////////
//
///////////////////////////////////////
BOOL CAlarmLamp::OnToolTipNotify(UINT id,NMHDR *pNMH, LRESULT *pResult)
{
LPTOOLTIPTEXT lpttt;
lpttt = (LPTOOLTIPTEXT)pNMH;
lpttt->szText[0] = '\0';
POINT ptCurrentPos;
GetCursorPos(&ptCurrentPos);
ScreenToClient(&ptCurrentPos);
m_rectSearch.SetRect(ptCurrentPos.x - 3,ptCurrentPos.y - 3,ptCurrentPos.x + 3,ptCurrentPos.y + 3);
strcpy(lpttt->szText,m_sCaption);
return FALSE;
}
/////////////////////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////////////////////
void CAlarmLamp::OnTimer(UINT nIDEvent)
{
CRect rect;
GetClientRect(rect);
CClientDC dc(this);
CBitmap Bitmap;
if(m_bSway)
Bitmap.LoadBitmap(IDB_ALARMLAMP_1);
else
Bitmap.LoadBitmap(IDB_ALARMLAMP_2);
APutImage(&dc,rect.left,rect.top,&Bitmap,RGB(255,255,255));
m_bSway=!m_bSway;
CWnd::OnTimer(nIDEvent);
}
/////////////////////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////////////////////
void CAlarmLamp::SetSway(BOOL bStart)
{
if(bStart)
{
m_bSway=FALSE;
CClientDC dc(this);
CRect rect;
GetClientRect(rect);
CBitmap Bitmap;
Bitmap.LoadBitmap(IDB_ALARMLAMP_2);
APutImage(&dc,rect.left,rect.top,&Bitmap,RGB(255,255,255));
SetTimer(0,500,NULL);
}
else
{
m_bSway=FALSE;
KillTimer(0);
Invalidate();
}
}
/////////////////////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////////////////////
void CAlarmLamp::OnLButtonDblClk(UINT nFlags, CPoint point)
{
if(m_bDBClk)
{
NMHDR Msg;
Msg.hwndFrom=m_hWnd;
Msg.code=GetDlgCtrlID();
GetParent()->SendMessage(WM_NOTIFY,2000,(LPARAM)&Msg);
}
CWnd::OnLButtonDblClk(nFlags, point);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -