// DisplayField.cpp : 实现文件
//

#include "stdafx.h"
#include "Verbpo.h"
#include "DisplayField.h"
#include "Data.h"

#define	COLOR_ALM_L		 RGB(0, 0, 0)
#define	COLOR_ALM_M		 RGB(255, 240, 0)
#define	COLOR_ALM_H		 RGB(250, 20, 2)

static UINT8 n_Flag[88] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x0E, 0x00, 0x30, 0x07, 0x00,
0x60, 0x03, 0x80, 0xC0, 0x01, 0xC1, 0x80, 0x00, 0xE3, 0x00,
0x00, 0x76, 0x00, 0x00, 0x3C, 0x00, 0x00, 0x1C, 0x00, 0x00,
0x3E, 0x00, 0x00, 0x67, 0x00, 0x00, 0xC3, 0x80, 0x01, 0x81,
0xC0, 0x03, 0x00, 0xE0, 0x06, 0x00, 0x70, 0x00, 0x00, 0x30,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00 };

// CDisplayField

IMPLEMENT_DYNAMIC(CDisplayField, CStatic)

CDisplayField::CDisplayField()
{
	m_i32ACFlag = -1, m_i32BatteryFlag = -1, m_i32BatteryLifePercent = -1;
	m_i32AlmTime = 0;
}

CDisplayField::~CDisplayField()
{
	font.DeleteObject();
	fontAlarm.DeleteObject();
	fontAlarmTime.DeleteObject();
	fontBattery.DeleteObject();
	dcMem.DeleteDC();
	bmp.DeleteObject();
	m_BitmapPower.DeleteObject();
	m_dcMemPower.DeleteDC();

	delete pen1;
	delete pen2, delete pen3, delete pen4;
}


BEGIN_MESSAGE_MAP(CDisplayField, CStatic)
	ON_WM_PAINT()
	ON_WM_ERASEBKGND()
	ON_WM_CREATE()
	ON_WM_LBUTTONDBLCLK()
END_MESSAGE_MAP()



// CDisplayField 消息处理程序

int CDisplayField::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
	//	this->MoveWindow(0, 0, m_i32Width, m_i32Height);
	// 获得控件区域
	GetClientRect(&m_rectCtrl);
	//客户区DC，可以绘画及显示
	CClientDC pDC(this);
	//依附窗口DC创建兼容内存DC
	dcMem.CreateCompatibleDC(&pDC);
	//创建兼容位图
	bmp.CreateCompatibleBitmap(&pDC, m_rectCtrl.Width(), m_rectCtrl.Height());
	dcMem.SelectObject(&bmp); //将位图选择进内存DC
	dcMem.FillSolidRect(IDC_DISPLAY_X, IDC_DISPLAY_Y, IDC_DISPLAY_WIDTH, IDC_DISPLAY_HEIGHT, RGB(0, 0, 0));

	dcMem.SetBkColor(RGB(0, 0, 0));



	m_BitmapPower.LoadBitmap(IDB_BITMAP_POWER);
	m_dcMemPower.CreateCompatibleDC(&pDC);
	m_dcMemPower.SelectObject(&m_BitmapPower);

	font.CreateFont(20,                                          //   nHeight     
		0,                                                   //   nWidth     
		0,                                                   //   nEscapement   
		0,                                                   //   nOrientation     
		FW_NORMAL,                                   //   nWeight     
		FALSE,                                           //   bItalic     
		FALSE,                                           //   bUnderline     
		0,                                                   //   cStrikeOut     
		ANSI_CHARSET,                             //   nCharSet     
		OUT_DEFAULT_PRECIS,                 //   nOutPrecision     
		CLIP_DEFAULT_PRECIS,               //   nClipPrecision     
		DEFAULT_QUALITY,                       //   nQuality     
		DEFAULT_PITCH | FF_SWISS,     //   nPitchAndFamily       
		_T("宋体"));


	fontAlarm.CreateFont(24,                                          //   nHeight     
		0,                                                   //   nWidth     
		0,                                                   //   nEscapement   
		0,                                                   //   nOrientation     
		FW_NORMAL,                                   //   nWeight     
		TRUE,                                           //   bItalic     
		FALSE,                                           //   bUnderline     
		0,                                                   //   cStrikeOut     
		ANSI_CHARSET,                             //   nCharSet     
		OUT_DEFAULT_PRECIS,                 //   nOutPrecision     
		CLIP_DEFAULT_PRECIS,               //   nClipPrecision     
		DEFAULT_QUALITY,                       //   nQuality     
		DEFAULT_PITCH | FF_SWISS,     //   nPitchAndFamily       
		_T("宋体"));


	fontAlarmTime.CreateFont(12,                                          //   nHeight     
		0,                                                   //   nWidth     
		0,                                                   //   nEscapement   
		0,                                                   //   nOrientation     
		FW_NORMAL,                                   //   nWeight     
		FALSE,                                           //   bItalic     
		FALSE,                                           //   bUnderline     
		0,                                                   //   cStrikeOut     
		ANSI_CHARSET,                             //   nCharSet     
		OUT_DEFAULT_PRECIS,                 //   nOutPrecision     
		CLIP_DEFAULT_PRECIS,               //   nClipPrecision     
		DEFAULT_QUALITY,                       //   nQuality     
		DEFAULT_PITCH | FF_SWISS,     //   nPitchAndFamily       
		_T("宋体"));

	fontBattery.CreateFont(20,                                          //   nHeight     
		0,                                                   //   nWidth     
		0,                                                   //   nEscapement   
		0,                                                   //   nOrientation     
		FW_NORMAL,                                   //   nWeight     
		FALSE,                                           //   bItalic     
		FALSE,                                           //   bUnderline     
		0,                                                   //   cStrikeOut     
		ANSI_CHARSET,                             //   nCharSet     
		OUT_DEFAULT_PRECIS,                 //   nOutPrecision     
		CLIP_DEFAULT_PRECIS,               //   nClipPrecision     
		DEFAULT_QUALITY,                       //   nQuality     
		DEFAULT_PITCH | FF_SWISS,     //   nPitchAndFamily       
		_T("宋体"));
	pen1 = new CPen(PS_SOLID, 1, RGB(210, 210, 210));

	pen2 = new CPen(PS_SOLID, 1, RGB(240, 20, 20));
	pen3 = new CPen(PS_SOLID, 1, RGB(240, 240, 20));
	pen4 = new CPen(PS_SOLID, 1, RGB(20, 240, 20));

	//	return CStatic::OnCreate(lpCreateStruct);
	return TRUE;
}
void  CDisplayField::OnLButtonDblClk(UINT nFlags, CPoint point)
{
	this->GetParent()->PostMessage(WM_STATIC_VALUE_RESP_NORMAL_DBLCLK, 0, 0);
}

BOOL CDisplayField::OnEraseBkgnd(CDC* pDC)
{

	return TRUE;
}

void CDisplayField::OnPaint()
{
	CPaintDC pDC(this);

	pDC.BitBlt(m_rectCtrl.left, m_rectCtrl.top, m_rectCtrl.Width(), m_rectCtrl.Height(), &dcMem, 0, 0, SRCCOPY);
	//	CStatic::OnPaint();
}


//显示报警
void CDisplayField::Show_Alm()
{
	//获得心电报警项
	struct SHOW_ALM a_stAlm;
	TCHAR a_cTime[64], a_cDate[64], a_cAlm[32];
	int i = 0;

	//显示心电报警
	if (theApp.m_Data->Get_ECG_Alm_Show_Next(&a_stAlm) == 0)
	{
		if (((theApp.m_Data->m_i32ParaECGALM_SW) && (a_stAlm.u8Type == ALM_TYPE_ECG))
			|| (theApp.m_Data->m_i32ParaECGST_ALM_SW) && (a_stAlm.u8Type == ALM_TYPE_ST)
			|| ((theApp.m_Data->m_i32ParaECGARRA_ALM_SW) && (a_stAlm.u8Type == ALM_TYPE_ARRA)))
		{
			if (a_stAlm.u8Level == CData::m_i32AlmLevelH)
			{
				dcMem.FillSolidRect(IDC_DISPLAY_ECG_ALM_X, IDC_DISPLAY_ECG_ALM_Y, IDC_DISPLAY_ECG_ALM_WIDTH, IDC_DISPLAY_ECG_ALM_HEIGHT - 1, COLOR_ALM_H);
				dcMem.SetTextColor(RGB(10, 10, 10));
			}
			else if (a_stAlm.u8Level == CData::m_i32AlmLevelM)
			{

				dcMem.FillSolidRect(IDC_DISPLAY_ECG_ALM_X, IDC_DISPLAY_ECG_ALM_Y, IDC_DISPLAY_ECG_ALM_WIDTH, IDC_DISPLAY_ECG_ALM_HEIGHT - 1, COLOR_ALM_M);
				dcMem.SetTextColor(RGB(10, 10, 10));
			}

			else
			{
				dcMem.FillSolidRect(IDC_DISPLAY_ECG_ALM_X, IDC_DISPLAY_ECG_ALM_Y, IDC_DISPLAY_ECG_ALM_WIDTH, IDC_DISPLAY_ECG_ALM_HEIGHT - 1, COLOR_ALM_L);
				dcMem.SetTextColor(RGB(250, 250, 250));
			}


			dcMem.SelectObject(&fontAlarm);

			//dcMem.SetTextColor(RGB(250, 250, 250));
			dcMem.TextOut(IDC_DISPLAY_ECG_ALM_X + 1, IDC_DISPLAY_ECG_ALM_Y, a_stAlm.cAlm);

			if (a_stAlm.u8ShowTime)
			{
				//显示报警时间
				for (i = 0; i < 10; i++)
					a_cDate[i] = a_stAlm.cTime[i];
				a_cDate[i] = 0;
				for (i = 11; i < 11 + 8; i++)
					a_cTime[i - 11] = a_stAlm.cTime[i];
				a_cTime[i - 11] = 0;
				dcMem.SelectObject(&fontAlarmTime);
				dcMem.TextOut(IDC_DISPLAY_ECG_ALM_X + 218, IDC_DISPLAY_ECG_ALM_Y, a_cDate);
				dcMem.TextOut(IDC_DISPLAY_ECG_ALM_X + 218, IDC_DISPLAY_ECG_ALM_Y + 15, a_cTime);
			}
		}
	}
	else
	{
		dcMem.FillSolidRect(IDC_DISPLAY_ECG_ALM_X, IDC_DISPLAY_ECG_ALM_Y, IDC_DISPLAY_ECG_ALM_WIDTH, IDC_DISPLAY_ECG_ALM_HEIGHT - 1, RGB(0, 0, 0));
	}

	//显示呼吸、体温报警
	if (theApp.m_Data->Get_Resp_Temp_Alm_Show_Next(&a_stAlm) == 0)
	{
		if (((theApp.m_Data->m_i32ParaRespALM_SW) && (a_stAlm.u8Type == ALM_TYPE_RESP))
			|| ((theApp.m_Data->m_i32ParaTempALM_SW) && (a_stAlm.u8Type == ALM_TYPE_TEMP)))
		{
			if (a_stAlm.u8Level == CData::m_i32AlmLevelH)
			{
				dcMem.FillSolidRect(IDC_DISPLAY_RESP_TEMP_ALM_X, IDC_DISPLAY_RESP_TEMP_ALM_Y, IDC_DISPLAY_RESP_TEMP_ALM_WIDTH, IDC_DISPLAY_RESP_TEMP_ALM_HEIGHT - 1, COLOR_ALM_H);
				dcMem.SetTextColor(RGB(10, 10, 10));
			}
			else if (a_stAlm.u8Level == CData::m_i32AlmLevelM)
			{
				dcMem.FillSolidRect(IDC_DISPLAY_RESP_TEMP_ALM_X, IDC_DISPLAY_RESP_TEMP_ALM_Y, IDC_DISPLAY_RESP_TEMP_ALM_WIDTH, IDC_DISPLAY_RESP_TEMP_ALM_HEIGHT - 1, COLOR_ALM_M);
				dcMem.SetTextColor(RGB(10, 10, 10));
			}
			else
			{
				dcMem.FillSolidRect(IDC_DISPLAY_RESP_TEMP_ALM_X, IDC_DISPLAY_RESP_TEMP_ALM_Y, IDC_DISPLAY_RESP_TEMP_ALM_WIDTH, IDC_DISPLAY_RESP_TEMP_ALM_HEIGHT - 1, COLOR_ALM_L);
				dcMem.SetTextColor(RGB(250, 250, 250));
			}
			dcMem.SelectObject(&fontAlarm);

			//dcMem.SetTextColor(RGB(250, 250, 250));
			dcMem.TextOut(IDC_DISPLAY_RESP_TEMP_ALM_X + 1, IDC_DISPLAY_RESP_TEMP_ALM_Y, a_stAlm.cAlm);

			if (a_stAlm.u8ShowTime)
			{
				//显示报警时间
				for (i = 0; i < 10; i++)
					a_cDate[i] = a_stAlm.cTime[i];
				a_cDate[i] = 0;
				for (i = 11; i < 11 + 8; i++)
					a_cTime[i - 11] = a_stAlm.cTime[i];
				a_cTime[i - 11] = 0;
				dcMem.SelectObject(&fontAlarmTime);
				dcMem.TextOut(IDC_DISPLAY_RESP_TEMP_ALM_X + 218, IDC_DISPLAY_RESP_TEMP_ALM_Y, a_cDate);
				dcMem.TextOut(IDC_DISPLAY_RESP_TEMP_ALM_X + 218, IDC_DISPLAY_RESP_TEMP_ALM_Y + 15, a_cTime);
			}
		}
	}
	else
	{
		dcMem.FillSolidRect(IDC_DISPLAY_RESP_TEMP_ALM_X, IDC_DISPLAY_RESP_TEMP_ALM_Y, IDC_DISPLAY_RESP_TEMP_ALM_WIDTH, IDC_DISPLAY_RESP_TEMP_ALM_HEIGHT - 1, RGB(0, 0, 0));
	}

	//显示血压、血氧报警
	if (theApp.m_Data->Get_Oxy_NIBP_Alm_Show_Next(&a_stAlm) == 0)
	{
		if (((theApp.m_Data->m_i32ParaOxyALM_SW) && (a_stAlm.u8Type == ALM_TYPE_OXY))
			|| ((theApp.m_Data->m_i32ParaBPALM_SW) && (a_stAlm.u8Type == ALM_TYPE_NIBP)))
		{
			if (a_stAlm.u8Level == CData::m_i32AlmLevelH)
			{
				dcMem.FillSolidRect(IDC_DISPLAY_OXY_NIBP_ALM_X, IDC_DISPLAY_OXY_NIBP_ALM_Y, IDC_DISPLAY_OXY_NIBP_ALM_WIDTH, IDC_DISPLAY_OXY_NIBP_ALM_HEIGHT - 1, COLOR_ALM_H);
				dcMem.SetTextColor(RGB(10, 10, 10));
			}
			else if (a_stAlm.u8Level == CData::m_i32AlmLevelM)
			{
				dcMem.FillSolidRect(IDC_DISPLAY_OXY_NIBP_ALM_X, IDC_DISPLAY_OXY_NIBP_ALM_Y, IDC_DISPLAY_OXY_NIBP_ALM_WIDTH, IDC_DISPLAY_OXY_NIBP_ALM_HEIGHT - 1, COLOR_ALM_M);
				dcMem.SetTextColor(RGB(10, 10, 10));
			}
			else
			{
				dcMem.FillSolidRect(IDC_DISPLAY_OXY_NIBP_ALM_X, IDC_DISPLAY_OXY_NIBP_ALM_Y, IDC_DISPLAY_OXY_NIBP_ALM_WIDTH, IDC_DISPLAY_OXY_NIBP_ALM_HEIGHT - 1, COLOR_ALM_L);
				dcMem.SetTextColor(RGB(250, 250, 250));
			}
			dcMem.SelectObject(&fontAlarm);

			//dcMem.SetTextColor(RGB(250, 250, 250));
			dcMem.TextOut(IDC_DISPLAY_OXY_NIBP_ALM_X + 1, IDC_DISPLAY_OXY_NIBP_ALM_Y, a_stAlm.cAlm);

			if (a_stAlm.u8ShowTime)
			{
				//显示报警时间
				for (i = 0; i < 10; i++)
					a_cDate[i] = a_stAlm.cTime[i];
				a_cDate[i] = 0;
				for (i = 11; i < 11 + 8; i++)
					a_cTime[i - 11] = a_stAlm.cTime[i];
				a_cTime[i - 11] = 0;
				dcMem.SelectObject(&fontAlarmTime);
				dcMem.TextOut(IDC_DISPLAY_OXY_NIBP_ALM_X + 218, IDC_DISPLAY_OXY_NIBP_ALM_Y, a_cDate);
				dcMem.TextOut(IDC_DISPLAY_OXY_NIBP_ALM_X + 218, IDC_DISPLAY_OXY_NIBP_ALM_Y + 15, a_cTime);
			}
		}
	}
	else
	{
		dcMem.FillSolidRect(IDC_DISPLAY_OXY_NIBP_ALM_X, IDC_DISPLAY_OXY_NIBP_ALM_Y, IDC_DISPLAY_OXY_NIBP_ALM_WIDTH, IDC_DISPLAY_OXY_NIBP_ALM_HEIGHT - 1, RGB(0, 0, 0));
	}

	//显示氧浓度报警
	if (theApp.m_Data->Get_AirOxy_Alm_Show_Next(&a_stAlm) == 0)
	{
		if (((theApp.m_Data->m_i32ParaAirOxyALM_SW) && (a_stAlm.u8Type == ALM_TYPE_AIROXY)))
		{
			if (a_stAlm.u8Level == CData::m_i32AlmLevelH)
			{
				dcMem.FillSolidRect(IDC_DISPLAY_AIROXY_ALM_X, IDC_DISPLAY_AIROXY_ALM_Y, IDC_DISPLAY_AIROXY_ALM_WIDTH, IDC_DISPLAY_AIROXY_ALM_HEIGHT - 1, COLOR_ALM_H);
				dcMem.SetTextColor(RGB(10, 10, 10));
			}
			else if (a_stAlm.u8Level == CData::m_i32AlmLevelM)
			{
				dcMem.FillSolidRect(IDC_DISPLAY_AIROXY_ALM_X, IDC_DISPLAY_AIROXY_ALM_Y, IDC_DISPLAY_AIROXY_ALM_WIDTH, IDC_DISPLAY_AIROXY_ALM_HEIGHT - 1, COLOR_ALM_M);
				dcMem.SetTextColor(RGB(10, 10, 10));
			}
			else
			{
				dcMem.FillSolidRect(IDC_DISPLAY_AIROXY_ALM_X + 1, IDC_DISPLAY_AIROXY_ALM_Y, IDC_DISPLAY_AIROXY_ALM_WIDTH, IDC_DISPLAY_AIROXY_ALM_HEIGHT - 1, COLOR_ALM_L);
				dcMem.SetTextColor(RGB(250, 250, 250));
			}
			dcMem.SelectObject(&fontAlarm);

			//dcMem.SetTextColor(RGB(250, 250, 250));
			dcMem.TextOut(IDC_DISPLAY_AIROXY_ALM_X, IDC_DISPLAY_AIROXY_ALM_Y, a_stAlm.cAlm);

			if (a_stAlm.u8ShowTime)
			{
				//显示报警时间
				for (i = 0; i < 10; i++)
					a_cDate[i] = a_stAlm.cTime[i];
				a_cDate[i] = 0;
				for (i = 11; i < 11 + 8; i++)
					a_cTime[i - 11] = a_stAlm.cTime[i];
				a_cTime[i - 11] = 0;
				dcMem.SelectObject(&fontAlarmTime);
				dcMem.TextOut(IDC_DISPLAY_AIROXY_ALM_X + 218, IDC_DISPLAY_AIROXY_ALM_Y, a_cDate);
				dcMem.TextOut(IDC_DISPLAY_AIROXY_ALM_X + 218, IDC_DISPLAY_AIROXY_ALM_Y + 15, a_cTime);
			}
		}
	}
	else
	{
		dcMem.FillSolidRect(IDC_DISPLAY_AIROXY_ALM_X, IDC_DISPLAY_AIROXY_ALM_Y, IDC_DISPLAY_AIROXY_ALM_WIDTH, IDC_DISPLAY_AIROXY_ALM_HEIGHT - 1, RGB(0, 0, 0));
	}

	m_i32ReDraw = 1;
}

void CDisplayField::Show_Time()
{
	COleDateTime tm = COleDateTime::GetCurrentTime();
	CString cs1, cs2;

	cs1.Format(_T("%04d-%02d-%02d"), tm.GetYear(), tm.GetMonth(), tm.GetDay());
	cs2.Format(_T("%02d:%02d:%02d"), tm.GetHour(), tm.GetMinute(), tm.GetSecond());

	dcMem.FillSolidRect(IDC_DISPLAY_TIME_X, IDC_DISPLAY_TIME_Y, IDC_DISPLAY_TIME_WIDTH, IDC_DISPLAY_TIME_HEIGHT, RGB(0, 0, 0));

	dcMem.SelectObject(&font);
	dcMem.SetTextColor(RGB(245, 245, 245));
	dcMem.TextOut(IDC_DISPLAY_TIME_X, IDC_DISPLAY_TIME_Y, cs1);
	dcMem.TextOut(IDC_DISPLAY_TIME_X, IDC_DISPLAY_TIME_Y + 30, cs2);

	m_i32ReDraw = 1;
}


// 设置病人ID
int CDisplayField::set_ID(CString& cs)
{
	m_csID = cs;

	dcMem.FillSolidRect(IDC_DISPLAY_ID_X, IDC_DISPLAY_ID_Y, IDC_DISPLAY_ID_WIDTH, IDC_DISPLAY_ID_HEIGHT, RGB(0, 0, 0));
	dcMem.SelectObject(&font);
	dcMem.SetTextColor(RGB(245, 245, 245));
	dcMem.TextOut(IDC_DISPLAY_ID_X, IDC_DISPLAY_ID_Y, m_csID);

	m_i32ReDraw = 1;

	return 0;
}


// 设置病人名称
int CDisplayField::set_Name(CString& cs)
{
	m_csName = cs;

	dcMem.FillSolidRect(IDC_DISPLAY_NAME_X, IDC_DISPLAY_NAME_Y, IDC_DISPLAY_NAME_WIDTH, IDC_DISPLAY_NAME_HEIGHT, RGB(0, 0, 0));
	dcMem.SelectObject(&font);
	dcMem.SetTextColor(RGB(245, 245, 245));
	dcMem.TextOut(IDC_DISPLAY_NAME_X, IDC_DISPLAY_NAME_Y, m_csName);

	m_i32ReDraw = 1;

	return 0;
}


// 设置病人类型
int CDisplayField::set_PatType(CString& cs)
{
	m_csType = cs;

	dcMem.FillSolidRect(IDC_DISPLAY_TYPE_X, IDC_DISPLAY_TYPE_Y, IDC_DISPLAY_TYPE_WIDTH, IDC_DISPLAY_TYPE_HEIGHT, RGB(0, 0, 0));
	dcMem.SelectObject(&font);
	dcMem.SetTextColor(RGB(245, 245, 245));
	dcMem.TextOut(IDC_DISPLAY_TYPE_X, IDC_DISPLAY_TYPE_Y, m_csType);

	m_i32ReDraw = 1;

	return 0;
}


int CDisplayField::set_PatSex(CString& cs)
{
	m_csSex = cs;

	dcMem.FillSolidRect(IDC_DISPLAY_SEX_X, IDC_DISPLAY_SEX_Y, IDC_DISPLAY_SEX_WIDTH, IDC_DISPLAY_SEX_HEIGHT, RGB(0, 0, 0));
	dcMem.SelectObject(&font);
	dcMem.SetTextColor(RGB(245, 245, 245));
	dcMem.TextOut(IDC_DISPLAY_SEX_X, IDC_DISPLAY_SEX_Y, m_csSex);

	m_i32ReDraw = 1;

	return 0;
}


//更新病人信息
void CDisplayField::Update_Pat_Info(CPatient & pat)
{
	// 设置病人ID
	set_ID(CString(pat.m_cID));
	// 设置病人名称
	set_Name(CString(pat.m_cName));
	// 设置病人类型
	if (pat.m_i32Type == 0)
	{
		set_PatType(CString(_T("新生儿")));
	}
	if (pat.m_i32Sex == 0)
	{
		set_PatSex(CString(_T("男")));
	}
	else
	{
		set_PatSex(CString(_T("女")));
	}

	Invalidate();
}

// 设置电池电量
int CDisplayField::set_Battery(INT ACFlag, INT BatteryFlag, INT BatteryLifePercent)
{
	int i, j, t = 0;
	CString a_cs;
	UINT8 chr = 0;

	//如果电池 电源 状态变化
	if ((m_i32ACFlag != ACFlag) || (m_i32BatteryFlag != BatteryFlag) || (m_i32BatteryLifePercent != BatteryLifePercent))
	{
		dcMem.FillSolidRect(IDC_DISPLAY_BATTERY_X, IDC_DISPLAY_BATTERY_Y, IDC_DISPLAY_BATTERY_WIDTH, IDC_DISPLAY_BATTERY_HEIGHT, RGB(0, 0, 0));

		m_i32ACFlag = ACFlag, m_i32BatteryFlag = BatteryFlag, m_i32BatteryLifePercent = BatteryLifePercent;
		//	128	没有电池
		//	255	未知，无法读取状态
		if ((m_i32BatteryFlag == 128) || (m_i32BatteryFlag == 256))
		{
			//电池图标显示 红叉

			//电池框
			dcMem.SelectObject(pen1);
			dcMem.MoveTo(IDC_DISPLAY_BATTERY_X + 0, IDC_DISPLAY_BATTERY_Y + 6);
			dcMem.LineTo(IDC_DISPLAY_BATTERY_X + 0, IDC_DISPLAY_BATTERY_Y + 24);
			dcMem.MoveTo(IDC_DISPLAY_BATTERY_X + 1, IDC_DISPLAY_BATTERY_Y + 6);
			dcMem.LineTo(IDC_DISPLAY_BATTERY_X + 1, IDC_DISPLAY_BATTERY_Y + 24);

			dcMem.MoveTo(IDC_DISPLAY_BATTERY_X + 2, IDC_DISPLAY_BATTERY_Y + 0);
			dcMem.LineTo(IDC_DISPLAY_BATTERY_X + 53, IDC_DISPLAY_BATTERY_Y + 0);

			dcMem.MoveTo(IDC_DISPLAY_BATTERY_X + 2, IDC_DISPLAY_BATTERY_Y + 28);
			dcMem.LineTo(IDC_DISPLAY_BATTERY_X + 53, IDC_DISPLAY_BATTERY_Y + 28);

			dcMem.MoveTo(IDC_DISPLAY_BATTERY_X + 2, IDC_DISPLAY_BATTERY_Y + 0);
			dcMem.LineTo(IDC_DISPLAY_BATTERY_X + 2, IDC_DISPLAY_BATTERY_Y + 28);

			dcMem.MoveTo(IDC_DISPLAY_BATTERY_X + 53, IDC_DISPLAY_BATTERY_Y + 0);
			dcMem.LineTo(IDC_DISPLAY_BATTERY_X + 53, IDC_DISPLAY_BATTERY_Y + 28);

			//显示红叉

			for (i = 0; i < 24; i++)
			{
				for (j = 0; j < 24; j++)
				{
					if (j % 8 == 0)
					{
						chr = n_Flag[t];
						t++;
					}
					if (chr & 0x80)
						dcMem.SetPixel(IDC_DISPLAY_BATTERY_X + 16 + j, IDC_DISPLAY_BATTERY_Y + 2 + i, RGB(255, 0, 0));

					chr <<= 1;
				}
			}
		}
		else if (m_i32BatteryFlag & 0x0f)
		{
			//电池图标显示 充电
			dcMem.SelectObject(pen1);

			dcMem.MoveTo(IDC_DISPLAY_BATTERY_X + 0, IDC_DISPLAY_BATTERY_Y + 6);
			dcMem.LineTo(IDC_DISPLAY_BATTERY_X + 0, IDC_DISPLAY_BATTERY_Y + 24);
			dcMem.MoveTo(IDC_DISPLAY_BATTERY_X + 1, IDC_DISPLAY_BATTERY_Y + 6);
			dcMem.LineTo(IDC_DISPLAY_BATTERY_X + 1, IDC_DISPLAY_BATTERY_Y + 24);

			dcMem.MoveTo(IDC_DISPLAY_BATTERY_X + 2, IDC_DISPLAY_BATTERY_Y + 0);
			dcMem.LineTo(IDC_DISPLAY_BATTERY_X + 53, IDC_DISPLAY_BATTERY_Y + 0);

			dcMem.MoveTo(IDC_DISPLAY_BATTERY_X + 2, IDC_DISPLAY_BATTERY_Y + 28);
			dcMem.LineTo(IDC_DISPLAY_BATTERY_X + 53, IDC_DISPLAY_BATTERY_Y + 28);

			dcMem.MoveTo(IDC_DISPLAY_BATTERY_X + 2, IDC_DISPLAY_BATTERY_Y + 0);
			dcMem.LineTo(IDC_DISPLAY_BATTERY_X + 2, IDC_DISPLAY_BATTERY_Y + 28);

			dcMem.MoveTo(IDC_DISPLAY_BATTERY_X + 53, IDC_DISPLAY_BATTERY_Y + 0);
			dcMem.LineTo(IDC_DISPLAY_BATTERY_X + 53, IDC_DISPLAY_BATTERY_Y + 28);


			j = m_i32BatteryLifePercent / 2;

			dcMem.SetTextColor(RGB(245, 245, 245));
			dcMem.SetBkMode(TRANSPARENT);
			if (m_i32BatteryLifePercent < 30)
			{

				for (i = 0; i < j; i++)
				{
					dcMem.SelectObject(pen2);
					dcMem.MoveTo(IDC_DISPLAY_BATTERY_X + 52 - i, IDC_DISPLAY_BATTERY_Y + 1);
					dcMem.LineTo(IDC_DISPLAY_BATTERY_X + 52 - i, IDC_DISPLAY_BATTERY_Y + 28);

				}
			}
			else if (m_i32BatteryLifePercent < 50)
			{
				for (i = 0; i < j; i++)
				{
					dcMem.SelectObject(pen3);
					dcMem.MoveTo(IDC_DISPLAY_BATTERY_X + 52 - i, IDC_DISPLAY_BATTERY_Y + 1);
					dcMem.LineTo(IDC_DISPLAY_BATTERY_X + 52 - i, IDC_DISPLAY_BATTERY_Y + 28);

				}
			}
			else
			{
				for (i = 0; i < j; i++)
				{
					dcMem.SelectObject(pen4);
					dcMem.MoveTo(IDC_DISPLAY_BATTERY_X + 52 - i, IDC_DISPLAY_BATTERY_Y + 1);
					dcMem.LineTo(IDC_DISPLAY_BATTERY_X + 52 - i, IDC_DISPLAY_BATTERY_Y + 28);

				}
			}
			dcMem.SelectObject(&fontBattery);
			a_cs.Format(_T("%d"), m_i32BatteryLifePercent);
			a_cs += _T("%");
			dcMem.TextOut(IDC_DISPLAY_BATTERY_X + 7, IDC_DISPLAY_BATTERY_Y + 4, a_cs);
		}
		else
		{
			dcMem.SelectObject(pen1);

			dcMem.MoveTo(IDC_DISPLAY_BATTERY_X + 0, IDC_DISPLAY_BATTERY_Y + 6);
			dcMem.LineTo(IDC_DISPLAY_BATTERY_X + 0, IDC_DISPLAY_BATTERY_Y + 24);
			dcMem.MoveTo(IDC_DISPLAY_BATTERY_X + 1, IDC_DISPLAY_BATTERY_Y + 6);
			dcMem.LineTo(IDC_DISPLAY_BATTERY_X + 1, IDC_DISPLAY_BATTERY_Y + 24);

			dcMem.MoveTo(IDC_DISPLAY_BATTERY_X + 2, IDC_DISPLAY_BATTERY_Y + 0);
			dcMem.LineTo(IDC_DISPLAY_BATTERY_X + 53, IDC_DISPLAY_BATTERY_Y + 0);

			dcMem.MoveTo(IDC_DISPLAY_BATTERY_X + 2, IDC_DISPLAY_BATTERY_Y + 28);
			dcMem.LineTo(IDC_DISPLAY_BATTERY_X + 53, IDC_DISPLAY_BATTERY_Y + 28);

			dcMem.MoveTo(IDC_DISPLAY_BATTERY_X + 2, IDC_DISPLAY_BATTERY_Y + 0);
			dcMem.LineTo(IDC_DISPLAY_BATTERY_X + 2, IDC_DISPLAY_BATTERY_Y + 28);

			dcMem.MoveTo(IDC_DISPLAY_BATTERY_X + 53, IDC_DISPLAY_BATTERY_Y + 0);
			dcMem.LineTo(IDC_DISPLAY_BATTERY_X + 53, IDC_DISPLAY_BATTERY_Y + 28);


			j = m_i32BatteryLifePercent / 2;

			dcMem.SetTextColor(RGB(245, 245, 245));
			dcMem.SetBkMode(TRANSPARENT);
			if (m_i32BatteryLifePercent < 30)
			{

				for (i = 0; i < j; i++)
				{
					dcMem.SelectObject(pen2);
					dcMem.MoveTo(IDC_DISPLAY_BATTERY_X + 52 - i, IDC_DISPLAY_BATTERY_Y + 1);
					dcMem.LineTo(IDC_DISPLAY_BATTERY_X + 52 - i, IDC_DISPLAY_BATTERY_Y + 28);

				}
			}
			else if (m_i32BatteryLifePercent < 50)
			{
				for (i = 0; i < j; i++)
				{
					dcMem.SelectObject(pen3);
					dcMem.MoveTo(IDC_DISPLAY_BATTERY_X + 52 - i, IDC_DISPLAY_BATTERY_Y + 1);
					dcMem.LineTo(IDC_DISPLAY_BATTERY_X + 52 - i, IDC_DISPLAY_BATTERY_Y + 28);

				}
			}
			else
			{
				for (i = 0; i < j; i++)
				{
					dcMem.SelectObject(pen4);
					dcMem.MoveTo(IDC_DISPLAY_BATTERY_X + 52 - i, IDC_DISPLAY_BATTERY_Y + 1);
					dcMem.LineTo(IDC_DISPLAY_BATTERY_X + 52 - i, IDC_DISPLAY_BATTERY_Y + 28);

				}
			}
			dcMem.SelectObject(&fontBattery);
			a_cs.Format(_T("%d"), m_i32BatteryLifePercent);
			a_cs += _T("%");
			dcMem.TextOut(IDC_DISPLAY_BATTERY_X + 7, IDC_DISPLAY_BATTERY_Y + 4, a_cs);
		}

		if (m_i32ACFlag == 1)
		{
			dcMem.BitBlt(IDC_DISPLAY_BATTERY_X, IDC_DISPLAY_BATTERY_Y + 31, 54, 28, &m_dcMemPower, 0, 0, SRCCOPY);
		}
		else
		{
			dcMem.FillSolidRect(IDC_DISPLAY_BATTERY_X, IDC_DISPLAY_BATTERY_Y + 31, IDC_DISPLAY_BATTERY_WIDTH, IDC_DISPLAY_BATTERY_HEIGHT - 1, RGB(0, 0, 0));
		}

		m_i32ReDraw = 1;
	}




	return 0;
}

//开始显示 报警静音 倒计时
void CDisplayField::start_alm_time(INT a)
{
	CString cs;

	dcMem.SelectObject(&fontAlarm);
	dcMem.SetTextColor(RGB(250, 250, 250));

	dcMem.TextOut(IDC_DISPLAY_ALM_TIME_X + 1, IDC_DISPLAY_ALM_TIME_Y, _T("静音倒计时"));
	cs.Format(_T("%d:%2d"), a / 60, a % 60);
	dcMem.TextOut(IDC_DISPLAY_ALM_TIME_X + 1, IDC_DISPLAY_ALM_TIME_Y + 30, cs);
	m_i32AlmTime = a;
}


//停止 显示 报警静音 倒计时
void CDisplayField::stop_alm_time()
{
	dcMem.FillSolidRect(IDC_DISPLAY_ALM_TIME_X, IDC_DISPLAY_ALM_TIME_Y, IDC_DISPLAY_ALM_TIME_WIDTH, IDC_DISPLAY_ALM_TIME_HEIGHT - 1, RGB(0, 0, 0));
}


//更新报警静音 倒计时 调用一次，减少1秒
void CDisplayField::update_alm_time()
{
	CString cs;

	m_i32AlmTime -= 1;
	if (m_i32AlmTime < 0)
	{
		m_i32AlmTime = 0;
	}
	cs.Format(_T("%d:%2d"), m_i32AlmTime / 60, m_i32AlmTime % 60);
	dcMem.SelectObject(&fontAlarm);
	dcMem.SetTextColor(RGB(250, 250, 250));
	dcMem.FillSolidRect(IDC_DISPLAY_ALM_TIME_X, IDC_DISPLAY_ALM_TIME_Y + 30, IDC_DISPLAY_ALM_TIME_WIDTH, 30, RGB(0, 0, 0));
	dcMem.TextOut(IDC_DISPLAY_ALM_TIME_X + 1, IDC_DISPLAY_ALM_TIME_Y + 30, cs);
}


// 重画
void CDisplayField::Redraw()
{
	if (m_i32ReDraw == 1)
	{
		m_i32ReDraw = 0;
		Invalidate(1);
	}
}