⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mdfui.cpp

📁 电信机房MDF、电源柜监控源码,主要用在通信机房配线设备监控、电源柜监控
💻 CPP
字号:
// MDFUI.cpp: implementation of the CMDFUI class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "MDF.h"
#include "MDFUI.h"
#include ".\mdfui.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

extern CMDFApp	theApp ;
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
//##ModelId=44B6F884036F
CMDFUI::CMDFUI()
{
	//加载背景图片
	m_bmpBG.bmpImage.Attach((HBITMAP)::LoadImage(AfxGetInstanceHandle(),"pic/bg.bmp",IMAGE_BITMAP,0,0,LR_CREATEDIBSECTION|LR_DEFAULTSIZE|LR_LOADFROMFILE) );
	m_bmpBG.bmpImage.GetBitmap(&m_bmpBG.bmpInfo) ;
	//设置服务器初始状态 
	m_iRun = 0 ;
	m_uiBNMsg = NULL ;

}

//##ModelId=44B6F8840370
CMDFUI::~CMDFUI()
{

}
//设置异型窗口
//##ModelId=44B6F884036C
void CMDFUI::SetUIRgn(CDC* pDC ,CWnd* pWnd)
{
	int			x,y ;
	CDC			memDC ;
	COLORREF	PixColor,BGColor ;
	CRgn		rgnTemp ;
	CBitmap*	pOld ;

	m_pWnd = pWnd ;

	memDC.CreateCompatibleDC(pDC) ;
	pOld = memDC.SelectObject(&(m_bmpBG.bmpImage)) ;
	BGColor = RGB(102,153,0) ;
	m_bmpBG.bmpRGN.CreateRectRgn(0,0,m_bmpBG.bmpInfo.bmWidth,m_bmpBG.bmpInfo.bmHeight); 

	for(x=0 ; x<=m_bmpBG.bmpInfo.bmWidth ; x++)
	{
		for(y=0 ; y<=m_bmpBG.bmpInfo.bmHeight ; y++ )
		{
			PixColor = memDC.GetPixel(x,y) ;
			if(PixColor == BGColor )
			{
				rgnTemp.CreateRectRgn(x,y,x+1,y+1) ;
				m_bmpBG.bmpRGN.CombineRgn(&m_bmpBG.bmpRGN,&rgnTemp,RGN_XOR) ;
				rgnTemp.DeleteObject() ;
			}
		}
	}
	pWnd->SetWindowRgn(m_bmpBG.bmpRGN,TRUE) ;
	memDC.SelectObject(pOld) ;
	memDC.DeleteDC() ;
}
//显示界面
//##ModelId=44B6F8840361
void CMDFUI::ShowUI(CDC *pDC)
{
	CDC		memDC ;
	CBitmap*	pOld ;

	memDC.CreateCompatibleDC(pDC) ;
	pOld = memDC.SelectObject( &(m_bmpBG.bmpImage) ) ;

	pDC->BitBlt(0,0,m_bmpBG.bmpInfo.bmWidth,m_bmpBG.bmpInfo.bmHeight,&memDC,0,0,SRCCOPY) ;

	pDC->SetTextColor(RGB(255,255,255)) ;
	pDC->SetBkMode(TRANSPARENT) ;
	
	memDC.SelectObject( pOld ) ;
	memDC.DeleteDC() ;



}

//##ModelId=44B6F8840360
void CMDFUI::LoseFocus()
{
	//界面各元素失去焦点处理。
	if(m_BNStart.m_bFocus && m_BNStart.m_bEnable) m_BNStart.LoseFocus() ;
	if(m_BNStop.m_bFocus && m_BNStop.m_bEnable) m_BNStop.LoseFocus() ;
	if(m_BNSet.m_bFocus && m_BNSet.m_bEnable) m_BNSet.LoseFocus() ;
	if(m_BNMin.m_bFocus && m_BNMin.m_bEnable) m_BNMin.LoseFocus() ;
	if(m_BNClose.m_bFocus && m_BNMin.m_bEnable) m_BNClose.LoseFocus() ;

}

//##ModelId=44B6F884035F
void CMDFUI::InitMDF()
{
	CString pic,strTip ;

	int BnX = 23 ;
	int BnY = 154 ;
	int BnWith = 38 ;
	int BnHeight = 38 ;

	//初始化启动按钮
	pic="pic/start.bmp" ;
	m_BNStart.Create( IDC_STARTBN, TYPE_CONCAVE , m_pWnd , BnX , BnY , BnWith , BnHeight , pic , m_uiBNMsg ) ;
	m_BNStart.m_bEnable = FALSE ;

	//初始化停止按钮
	pic="pic/stop.bmp " ;
	BnX=BnX+BnWith+3 ;
	m_BNStop.Create( IDC_STOPBN , TYPE_CONCAVE , m_pWnd , BnX , BnY , BnWith , BnHeight , pic , m_uiBNMsg ) ;
	m_BNStop.m_bEnable = FALSE ;

	//初始化设置按钮
	pic="pic/set.bmp " ;
	BnX += 80 ;
	BnY += 3 ;
	BnWith = 102 ;
	BnHeight = 32 ;
	m_BNSet.Create( IDC_SET, TYPE_NORMAL , m_pWnd , BnX , BnY , BnWith , BnHeight , pic , m_uiBNMsg ) ;
	m_BNSet.m_bEnable = TRUE ;

	//初始化最小化按钮
	//pic="pic/min.bmp " ;
	BnX = 210 ;
	BnY = 8 ;
	BnWith = 18 ;
	BnHeight = 18 ;
	//m_BNMin.Create( IDC_MIN, TYPE_NORMAL , m_pWnd , BnX , BnY , BnWith , BnHeight , pic , m_uiBNMsg ) ;
	//m_BNMin.m_bEnable = TRUE ;

	//初始化关闭按钮
	pic="pic/close.bmp " ;
	BnX += 20  ;
	m_BNClose.Create( IDC_CLOSE, TYPE_NORMAL , m_pWnd , BnX , BnY , BnWith , BnHeight , pic , m_uiBNMsg ) ;
	m_BNClose.m_bEnable = TRUE ;

	//显示窗口
	CRect rs;
	rs.top = 34;
	rs.bottom = 108+rs.top;
	rs.left = 24;
	rs.right = 220+rs.left;


	m_pWnd->GetDlgItem(IDC_SHOW)->MoveWindow(rs) ;
	
	strTip =  "系统:界面初始化成功" ;
	TRACE0(strTip) ; 
	strTip = "系统:服务器未启动" ;
	TRACE0(strTip) ; 

	//m_pWnd->GetDlgItem(IDC_SHOW)->SetFont(&NewFont) ;
	//m_ShowUI.Create(m_pWnd) ;

}

//##ModelId=44B6F884034D
void CMDFUI::Run(BOOL on)
{
	if(on)
	{
		m_BNStart.m_bEnable = FALSE ;
		m_BNStop.m_bEnable = TRUE ;
		m_BNStop.m_bFocus = FALSE ;
		m_BNStop.ShowBN(0,m_BNStop.GetDC()) ;
		m_BNStart.ShowBN(3,m_BNStart.GetDC()) ;
	}
	else
	{
		m_BNStart.m_bEnable = TRUE ;
		m_BNStart.m_bFocus = FALSE ;
		m_BNStop.m_bEnable = FALSE ;		
		m_BNStart.ShowBN(0,m_BNStart.GetDC()) ;
		m_BNStop.ShowBN(3,m_BNStop.GetDC()) ;
	}

}
//界面消息处理
//##ModelId=44B6F884033F
void CMDFUI::OnMsg(UINT id , UINT event)
{
	CString strTip,strTime ;

	switch(id)
	{
	case IDC_STARTBN : //启动服务器
		if(event == BN_MOUSEDOWN)
		{
			if (!theApp.m_Baseinfo.MonitorStatus)
			{
				DisableButton();
				if(theApp.StartMonitoring())
					Run(TRUE);
				else
				{
					Run(FALSE) ;
				}
			}
		}
		break ;

	case IDC_STOPBN ://停止服务器
		if(event == BN_MOUSEDOWN)
		{
			DisableButton();
			if(theApp.StopMonitoring())
				Run(FALSE);
		}
		break ;
	case IDC_CLOSE ://关闭应用服务器
		if(event == BN_MOUSEDOWN)
		{
			//((CMDFDlg *)m_pWnd)->DestroyWindow();
			::SendMessage(((CMDFDlg *)m_pWnd)->m_hWnd,WM_CLOSE,NULL,NULL);
		}
		break ;
	case IDC_SET ://启动设置界面	
		if(event == BN_MOUSEDOWN)
		{
			OnSet() ;
		}
		break ;
	case IDC_MIN ://最小化窗口
		if(event == BN_MOUSEDOWN)
		{
			//HideMainWin() ; //最小化窗口
			::SendMessage(((CMDFDlg *)m_pWnd)->m_hWnd,WM_SIZE,SIZE_MINIMIZED,NULL);
		}
		break ;
	default :
		break ;
	}

}




//##ModelId=44B6F884033D
int CMDFUI::OnSet()
{
	CString strSet ;

	int nResponse = m_SetDlg.DoModal();

	//if (nResponse == IDOK)
	//{
	//	//设置用户ID
	//	if( !m_SetDlg.m_DBDlg.m_strUserId.IsEmpty() )
	//	{
	//		//theApp.m_pAdoDB->m_strUserId.Empty() ;
	//		theApp.m_strUserId.Empty() ;
	//		//theApp.m_pAdoDB->m_strUserId = m_SetDlg.m_DBDlg.m_strUserId ;
	//		theApp.m_strUserId = m_SetDlg.m_DBDlg.m_strUserId ;
	//	}

	//	//设置用户密码
	//	//theApp.m_pAdoDB->m_strPassWord.Empty() ;
	//	//theApp.m_pAdoDB->m_strPassWord = m_SetDlg.m_DBDlg.m_strPassWord ;
	//	theApp.m_strPassWord.Empty() ;
	//	theApp.m_strPassWord = m_SetDlg.m_DBDlg.m_strPassWord ;

	//	//设置通讯IP地址
	//	if( !m_SetDlg.m_ConDlg.m_strWebIp.IsEmpty() )
	//	{
	//		theApp.m_pComm->m_pCommPool->m_strWebIp.Empty() ;
	//		theApp.m_pComm->m_pCommPool->m_strWebIp = m_SetDlg.m_ConDlg.m_strWebIp ;
	//	}
	//	if( !m_SetDlg.m_ConDlg.m_strDBIp.IsEmpty() )
	//	{
	//		//theApp.m_pAdoDB->m_strIp.Empty() ;
	//		//theApp.m_pAdoDB->m_strIp = m_SetDlg.m_ConDlg.m_strDBIp ;
	//		theApp.m_strIp.Empty() ;
	//		theApp.m_strIp = m_SetDlg.m_ConDlg.m_strDBIp ;
	//	}

	//	//设置通讯端口
	//	//theApp.m_pComm->m_pCommPool->m_unSCPort = m_SetDlg.m_PortDlg.m_unSCPort ;
	//	theApp.m_pComm->m_pCommPool->m_unGSMPort = m_SetDlg.m_PortDlg.m_unGSMPort ;
	//	if( m_SetDlg.m_PortDlg.m_unTCPPort > 0 )
	//		theApp.m_pComm->m_pCommPool->m_unTCPPort = m_SetDlg.m_PortDlg.m_unTCPPort ;
	//	if( m_SetDlg.m_PortDlg.m_unWebPort > 0 )
	//		theApp.m_pComm->m_pCommPool->m_unWebPort = m_SetDlg.m_PortDlg.m_unWebPort ;

	//	//设置短信中心号码
	//	theApp.m_pComm->m_pCommPool->m_GSM.m_strMsgCenter.Empty() ;
	//	theApp.m_pComm->m_pCommPool->m_GSM.m_strMsgCenter = m_SetDlg.m_MsgDlg.m_strMsgCenter ;
	//	//设置系统功能
	//	theApp.m_pComm->m_bIsMsgOpen = m_SetDlg.m_FuncDlg.m_bMsg ;
	//	theApp.m_pComm->m_bIsVoiceOpen = m_SetDlg.m_FuncDlg.m_bVoice ;
	//	theApp.m_pComm->m_bIsWebOpen =  m_SetDlg.m_FuncDlg.m_bWeb ;

	//	theApp.WriteConfig() ;
	//	theApp.Show("系统:参数设置保存") ;

	//	if( theApp.m_pComm->m_bComm )
	//	{
	//		AfxMessageBox("参数设置已改变,需重启MDF才能生效") ;
	//	}
	//}

	return 0 ;
}

// 禁止所有按钮
int CMDFUI::DisableButton(void)
{
	m_BNStart.ShowBN(3,m_BNStart.GetDC()) ;
	m_BNStop.ShowBN(3,m_BNStop.GetDC()) ;
	return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -