📄 stateswnd.cpp
字号:
// StatesWnd.cpp : implementation file
//
#include "stdafx.h"
#include "gtmpeg.h"
#include "StatesWnd.h"
#include "ZoneOperator.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////////////////////
CStatesWnd::CStatesWnd()
{
WNDCLASS wndcls;
HINSTANCE hInst = AfxGetResourceHandle();
if (!(::GetClassInfo(hInst, "StatesWnd", &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;
CBrush Brush(RGB(192,192,192));
wndcls.hbrBackground = NULL;//(HBRUSH) (Brush.operator HBRUSH());//COLOR_3DFACE + 1
wndcls.lpszMenuName = NULL;
wndcls.lpszClassName = "StatesWnd";
if (!AfxRegisterClass(&wndcls))
AfxThrowResourceException();
}
m_bType=FALSE;
m_nTimers=0;
m_nExitTimer=0;
m_pZone=NULL;
m_pSecondary=NULL;
}
CStatesWnd::~CStatesWnd()
{
m_pZone=NULL;
m_pSecondary=NULL;
}
/////////////////////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////////////////////
BEGIN_MESSAGE_MAP(CStatesWnd, CWnd)
//{{AFX_MSG_MAP(CStatesWnd)
ON_WM_LBUTTONDOWN()
ON_WM_PAINT()
ON_WM_CREATE()
ON_WM_TIMER()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////////////////////
void CStatesWnd::SetZone(CZone* pZone)
{
if(!m_bType)
{
m_pZone=pZone;
m_nExitTimer=m_pZone->m_nExitTimer;
Invalidate();
}
}
/////////////////////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////////////////////
void CStatesWnd::SetSecondary(CSecondary* pSecondary)
{
if(m_bType)
{
m_pSecondary=pSecondary;
m_sCaption1="停止";
m_sCaption2="开启";
Invalidate();
}
}
/////////////////////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////////////////////
BOOL CStatesWnd::Create(BOOL bType,CRect rect, CWnd* pParentWnd, UINT nID)
{
m_bType=bType;
return CWnd::Create("StatesWnd","", WS_CHILD|WS_VISIBLE, rect, pParentWnd, nID, NULL);
}
/////////////////////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////////////////////
void CStatesWnd::OnLButtonDown(UINT nFlags, CPoint point)
{
NMHDR Msg;
Msg.hwndFrom=m_hWnd;
UINT uInfoID;
Msg.idFrom=GetDlgCtrlID();
if(Msg.idFrom>=IDC_ZONE_STATES_1&&Msg.idFrom<=IDC_ZONE_STATES_16)
uInfoID=_ALARM_ZONE_INFO;
else
uInfoID=_ALARM_SECONDARY_INFO;
CZoneOperator *pParentWnd=(CZoneOperator *)GetParent();
Msg.code=pParentWnd->m_nCurChunnel;
Msg.code<<=16;
if(m_nTimers!=0)
return;
if(m_bType)//输出设备
{
if(m_pSecondary->GetStates())
{
m_pSecondary->SetStates(!m_pSecondary->GetStates());
Msg.code+=m_pSecondary->GetStates();
theApp.m_pMainWnd->SendMessage(WM_NOTIFY,uInfoID,(LPARAM)&Msg);
Invalidate();
}
}
else if(!m_bType)//防区
{
if(m_pZone->m_nCtrlWay==1||m_pZone->m_nType==7)//前端控制
return;
if((m_pZone->m_nCtrlWay==2&&(!m_pZone->m_bStates3))||(m_pZone->m_nCtrlWay==0&&(!m_pZone->GetStates())))//进行设防操作
{
SetTimer(0,1000,NULL);
return;
}
if(m_pZone->m_nCtrlWay==0||((m_pZone->m_nCtrlWay==2&&m_pZone->m_bStates3)))//中心控制或二级控制,进行撤防操作
{
if(m_pZone->m_nCtrlWay==0&&m_pZone->GetStates())
{
m_pZone->SetStates(!m_pZone->GetStates());
Msg.code+=m_pZone->GetStates();
theApp.m_pMainWnd->SendMessage(WM_NOTIFY,uInfoID,(LPARAM)&Msg);
Invalidate();
}
else
{
if(!m_pZone->m_bStates2)//前端已经撤防
{
m_pZone->m_bStates3=FALSE;
Msg.code+=m_pZone->m_bStates3;
theApp.m_pMainWnd->SendMessage(WM_NOTIFY,uInfoID,(LPARAM)&Msg);
Invalidate();
}
if(m_pZone->m_bStates2)//前端已经布防
{
m_pZone->m_bStates3=FALSE;//表示中心撤防
Invalidate();
}
}
}
}
CWnd::OnLButtonDown(nFlags, point);
}
/////////////////////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////////////////////
void CStatesWnd::OnPaint()
{
CPaintDC dc(this);
if(m_bType)
{
if(m_pSecondary==NULL)
return;
}
else
{
if(m_pZone==NULL)
return;
}
CRect rect,rect1;
GetClientRect(rect);
rect1=rect;
CBitmap Bitmap;
CString sCaption="";
BOOL bStates=FALSE;
if(m_bType)
{
bStates=m_pSecondary->GetStates();
if(bStates)
{
Bitmap.LoadBitmap(IDB_ALARMLAMP_2);
sCaption=m_sCaption2;
}
else
{
Bitmap.LoadBitmap(IDB_ALARMLAMP_1);
sCaption=m_sCaption1;
}
}
else
{
if(m_pZone->m_nType!=7)
{
switch(m_pZone->m_nCtrlWay)
{
default:
case 0://中心控制
bStates=m_pZone->GetStates();
if(bStates)
{
Bitmap.LoadBitmap(IDB_ALARMLAMP_2);
sCaption="布防";
}
else
{
Bitmap.LoadBitmap(IDB_ALARMLAMP_1);
sCaption="撤防";
}
break;
case 1://一级控制
bStates=m_pZone->m_bStates2;
if(bStates)
{
Bitmap.LoadBitmap(IDB_ALARMLAMP_2);
sCaption="前端布防";
}
else
{
Bitmap.LoadBitmap(IDB_ALARMLAMP_1);
sCaption="前端撤防";
}
break;
case 2://二级控制
bStates=m_pZone->m_bStates3;
if(bStates)
{
Bitmap.LoadBitmap(IDB_ALARMLAMP_2);
sCaption="中心布防";
if(m_pZone->m_bStates2)
sCaption+=",前端布防";
else
sCaption+=",前端撤防";
}
else
{
Bitmap.LoadBitmap(IDB_ALARMLAMP_1);
sCaption="中心撤防";
if(m_pZone->m_bStates2)
sCaption+=",前端布防";
else
sCaption+=",前端撤防";
}
}
}
else
{
bStates=m_pZone->m_bStates2;
if(bStates)
{
Bitmap.LoadBitmap(IDB_ALARMLAMP_2);
sCaption="所属防区布防";
}
else
{
Bitmap.LoadBitmap(IDB_ALARMLAMP_1);
sCaption="所属防区撤防";
}
}
}
if(Bitmap.m_hObject!=NULL)
APutImage(&dc,rect.left,rect.top,&Bitmap,RGB(255,255,255));
rect.left+=20;
if(!m_bType)
{
if(m_pZone->m_nCtrlWay!=1&&m_pZone->m_nType!=7)
{
rect.right=rect.right-66;
rect1.left=rect1.right-64;
Draw3DRectangle(&dc,rect1,1);
rect1.DeflateRect(2,2);
DrawRectangle(&dc,rect1,1,COLOR_BLUE,COLOR_BLUE);
}
}
Draw3DRectangle(&dc,rect,bStates);
dc.SetBkMode(TRANSPARENT);
CFont font,*pOldFont;
font.CreatePointFont(90,"宋体");
pOldFont=dc.SelectObject(&font);
dc.DrawText(sCaption, rect,DT_CENTER|DT_SINGLELINE|DT_VCENTER);
dc.SelectObject(pOldFont);
}
/////////////////////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////////////////////
int CStatesWnd::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CWnd::OnCreate(lpCreateStruct) == -1)
return -1;
return 0;
}
/////////////////////////////////////////////////////////////////////////////
//二级布防操作:有一个布防即为布防
//二级撤防操作:同时撤防即为撤防
/////////////////////////////////////////////////////////////////////////////
void CStatesWnd::OnTimer(UINT nIDEvent)
{
m_nTimers++;
CRect rect;
GetClientRect(rect);
CBitmap Bitmap;
CClientDC dc(this);
CString sCaption="";
int nTmpStates=m_nTimers%2;
switch(m_pZone->m_nCtrlWay)
{
case 0://中心控制
if(nTmpStates)
{
Bitmap.LoadBitmap(IDB_ALARMLAMP_2);
sCaption="布防";
}
else
{
Bitmap.LoadBitmap(IDB_ALARMLAMP_1);
sCaption="撤防";
}
break;
case 2://二级控制
if(nTmpStates)
{
Bitmap.LoadBitmap(IDB_ALARMLAMP_2);
sCaption="中心布防";
if(m_pZone->m_bStates2)
sCaption+=",前端布防";
else
sCaption+=",前端撤防";
}
else
{
Bitmap.LoadBitmap(IDB_ALARMLAMP_1);
sCaption="中心撤防";
if(m_pZone->m_bStates2)
sCaption+=",前端布防";
else
sCaption+=",前端撤防";
}
}
APutImage(&dc,rect.left,rect.top,&Bitmap,RGB(255,255,255));
CRect rect1;
rect1=rect;
rect1.left+=20;
rect1.right=rect1.right-66;
Draw3DRectangle(&dc,rect1,nTmpStates);
dc.SetBkMode(TRANSPARENT);
CFont font,*pOldFont;
font.CreatePointFont(90,"宋体");
pOldFont=dc.SelectObject(&font);
dc.DrawText(sCaption, rect1,DT_CENTER|DT_SINGLELINE|DT_VCENTER);
dc.SelectObject(pOldFont);
rect.left=rect.right-64;
int nStep=(rect.Width()-2)/theApp.m_nExitDelay;
Draw3DRectangle(&dc,rect,1);
rect.right=rect.left+m_nTimers*nStep;
rect.DeflateRect(2,2);
DrawRectangle(&dc,rect,1,COLOR_GREEN,COLOR_GREEN);
if(m_nTimers>=m_nExitTimer)
{
if(m_pZone->m_nCtrlWay==0)
m_pZone->SetStates(TRUE);
else
m_pZone->m_bStates3=TRUE;
NMHDR Msg;
Msg.hwndFrom=m_hWnd;
UINT uInfoID;
Msg.idFrom=GetDlgCtrlID();
uInfoID=_ALARM_ZONE_INFO;
CZoneOperator *pParentWnd=(CZoneOperator *)GetParent();
Msg.code=pParentWnd->m_nCurChunnel;
Msg.code<<=16;
Msg.code+=1;
theApp.m_pMainWnd->SendMessage(WM_NOTIFY,uInfoID,(LPARAM)&Msg);
KillTimer(0);
m_nTimers=0;
Invalidate();
}
CWnd::OnTimer(nIDEvent);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -