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

📄 mdfdlg.cpp

📁 MDF监控源码2
💻 CPP
字号:
// MDFDlg.cpp : implementation file
//

#include "stdafx.h"
#include "MDF.h"
#include "MDFDlg.h"
#include ".\mdfdlg.h"
//#include "DebugDlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// CMDFDlg dialog
extern CMDFApp theApp ;

//##ModelId=465286A100C0
CMDFDlg::CMDFDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CMDFDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CMDFDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_bTOMsg = FALSE ;
	m_bTOVoice = FALSE ;
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
	
}

//##ModelId=465286A100CE
void CMDFDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CMDFDlg)
	// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
	DDX_Control(pDX, IDC_SHOW, m_logShow);
}

BEGIN_MESSAGE_MAP(CMDFDlg, CDialog)
	//{{AFX_MSG_MAP(CMDFDlg)
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_WM_MOUSEMOVE()
	ON_WM_LBUTTONUP()
	ON_MESSAGE(WM_UIMESSAGE,OnUIMsg)
	ON_MESSAGE(WM_COMMRESTART,OnReStart)
	ON_WM_TIMER()
	ON_COMMAND(ID_EXIT, OnExit)
	ON_COMMAND(ID_SHOWMAINWIN, OnShowmainwin)
	ON_COMMAND(ID_STARTCOMM, OnStartcomm)
	ON_COMMAND(ID_STOPCOMM, OnStopcomm)
	ON_MESSAGE(WM_SHELLNOTIFY,OnShellNotify)
	ON_WM_DESTROY()
	ON_MESSAGE(MM_WOM_OPEN,OnMM_WOM_OPEN)
	ON_MESSAGE(MM_WOM_DONE,OnMM_WOM_DONE)
	ON_MESSAGE(MM_WOM_CLOSE,OnMM_WOM_CLOSE)
	ON_MESSAGE(WM_VOICE, GsmVoice)
	ON_MESSAGE(WM_VOICE_CLOSE, GsmVoiceClose)
	ON_MESSAGE(WM_REFRESH,Refresh)
	ON_MESSAGE(WM_WRITELOG,onWriteLog)				//存储日志
	ON_MESSAGE(WM_SHOWLOG,onShowLog)				//显示日志
	ON_MESSAGE(WM_SHOWERROR,onShowError)			//显示错误
	ON_MESSAGE(WM_SERVICESTATUS,onServiceStatus)	//服务器运行状态变化标志


	//}}AFX_MSG_MAP
	ON_EN_CHANGE(IDC_SHOW, OnEnChangeShow)

	ON_WM_ACTIVATE()
	ON_WM_CTLCOLOR()
	ON_EN_VSCROLL(IDC_SHOW, OnEnVscrollShow)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMDFDlg message handlers

//##ModelId=465286A10109
BOOL CMDFDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	
	// TODO: Add extra initialization here
	m_bWinMove = FALSE ;

	/**********************************/
	//Roy 2006-6-30
	//theApp.ReadConfig() ;//读配置参数readconfig()

	//界面初始化
	m_UI.m_uiBNMsg = WM_UIMESSAGE ;						//界面自定义消息
	m_UI.SetUIRgn(this->GetDC() , this) ;				//设置窗口外形
	
	/**********************************/
	//Roy 2006-6-30
	m_UI.InitMDF() ;									//初始化界面各元素


	SetWindowText(" CM2005 远程监控系统 ") ;

	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	
	

	return TRUE;  // return TRUE  unless you set the focus to a control
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

//##ModelId=465286A10119
void CMDFDlg::OnPaint() 
{
	CRect lpRect;
	//CBrush *pBrush;
	CPaintDC dc(this); 

	if (IsIconic())
	{
		// device context for painting
		dc.SetBkColor(RGB(255,255,255));

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;
		// Draw the icon

		//dc.DrawIcon(x, y, m_hIcon);
		//dc.SetBkMode(TRANSPARENT); 
		////dc->SetBkColor(RGB(255, 255, 255));

		//pBrush  = new CBrush(RGB(255, 255, 255));
		//this->GetWindowRect(lpRect);
		//ScreenToClient(lpRect);
		//dc.FillRect(lpRect,pBrush);
		
	}
	else
	{
		
		CDC *pDC = GetDlgItem(IDC_SHOW)->GetDC();

		m_UI.ShowUI(&dc) ; //显示界面

		//pDC->SetBkMode(TRANSPARENT); 
		//pDC->SetBkColor(RGB(255, 255, 255));

		//pBrush  = new CBrush(RGB(255, 255, 255));
		//GetDlgItem(IDC_SHOW)->GetWindowRect(lpRect);
		//ClientToScreen(lpRect);
		//pDC->FillRect(lpRect,pBrush);
		
		CDialog::OnPaint();
	}



}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
//##ModelId=465286A10128
HCURSOR CMDFDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}


//##ModelId=465286A1012A
void CMDFDlg::OnMouseMove(UINT nFlags, CPoint point) 
{

	int x , y ;
	//窗口拖动处理。
	m_UI.LoseFocus() ;

	if( nFlags && MK_MBUTTON )
	{
		if(! m_bWinMove )
		{
			m_pt = point ; //保存初始移动位置。
			m_bWinMove = TRUE ;
		}

		ClientToScreen (&point) ;
		//计算窗口拖动的定位
		x = point.x - m_pt.x ;
		y = point.y - m_pt.y ;
		SetCapture() ;
		this->MoveWindow( x , y ,m_UI.m_bmpBG.bmpInfo.bmWidth,m_UI.m_bmpBG.bmpInfo.bmHeight) ;
	}

}

//##ModelId=465286A1013A
void CMDFDlg::OnLButtonUp(UINT nFlags, CPoint point) 
{
	//用于窗口的拖动释放。
	ReleaseCapture() ;
	m_bWinMove = FALSE ;
	CDialog::OnLButtonUp(nFlags, point);
}

//##ModelId=465286A10149
LRESULT CMDFDlg::OnUIMsg(WPARAM BNId , LPARAM BNEvent)
{
	m_UI.OnMsg(BNId , BNEvent) ;
	return(-1);
}

//##ModelId=465286A1016A
void CMDFDlg::OnTimer(UINT nIDEvent) 
{
	//int nCount ;

	CDialog::OnTimer(nIDEvent);
}

//##ModelId=465286A10179
void CMDFDlg::OnExit() 
{
	// TODO: Add your command handler code here
	NOTIFYICONDATA tnd ;
	//int i = AfxMessageBox("是否关闭服务器?",MB_YESNO|MB_ICONQUESTION) ;
	//if( i == 7 )
		//return ;
	//theApp.m_pComm->StopComm() ;
	tnd.cbSize = sizeof(NOTIFYICONDATA) ;
	tnd.hWnd =  theApp.m_pMainWnd->m_hWnd ;
	tnd.uID = IDD_MDFMAIN ;
	Shell_NotifyIcon(NIM_DELETE,&tnd) ;
	exit(0) ;
}

//##ModelId=465286A101C7
void CMDFDlg::OnShowmainwin() 
{
	// TODO: Add your command handler code here
	ShowWindow(SW_SHOW) ;
}

//##ModelId=465286A101D4
void CMDFDlg::OnStartcomm() 
{
	// TODO: Add your command handler code here
	m_UI.Run(TRUE) ;
}

//##ModelId=465286A101E4
void CMDFDlg::OnStopcomm() 
{
	// TODO: Add your command handler code here
	m_UI.Run(FALSE) ;

}

//##ModelId=465286A100FA
LRESULT CMDFDlg::OnShellNotify(WPARAM wParam, LPARAM lParam)
{
	if(lParam==WM_LBUTTONDBLCLK ) 
	{
		OnShowmainwin();
		return(0) ;
	}
	//如果收到的中单击右键信息,根据对剪贴板的监视与否修改不同的菜单项
	if(lParam==WM_RBUTTONDOWN) 
	{
		CMenu menu; 

		menu.LoadMenu(IDR_POPMENU); 

		//if( !(theApp.m_pComm->m_bRun) )
		//{
			//启用“开始记录”菜单项
			menu.EnableMenuItem(ID_STARTCOMM,0);//0  使启动菜单有效 
			menu.EnableMenuItem(ID_STOPCOMM,1); //1  使停止菜单无效
		//}
		//else
		//{
		//	//启用“停止始记录”菜单项
		//	menu.EnableMenuItem(ID_STARTCOMM,1);
		//	menu.EnableMenuItem(ID_STOPCOMM,0);
		//}
		// 鼠标单击位置 
		CPoint point; 
		GetCursorPos(&point); 
		// 将背景窗口激活 
		SetForegroundWindow(); 
		// 显示图标菜单 
		menu.GetSubMenu(0)->TrackPopupMenu( 
			TPM_LEFTBUTTON|TPM_RIGHTBUTTON,  
			point.x, point.y, this, NULL);

		return(0) ;
	}
	return(0);
}

//##ModelId=465286A101E6
void CMDFDlg::OnDestroy() 
{
	CDialog::OnDestroy();
	// TODO: Add your message handler code here	
}

//打开音频播放器
//##ModelId=465286A1017B
LRESULT CMDFDlg::OnMM_WOM_OPEN(UINT wParam, LONG lParam)
{
	theApp.OutPut("程序:调用 CMDFDlg::OnMM_WOM_OPEN()") ;//%%%

	return 0;//theApp.m_pMedia->OnOpen() ;	
}

//结束音频播放器
//##ModelId=465286A10189
LRESULT CMDFDlg::OnMM_WOM_DONE(UINT wParam, LONG lParam)
{
	theApp.OutPut("程序:调用 CMDFDlg::OnMM_WOM_DONE()") ;//%%%
	return 0; //theApp.m_pMedia->OnClose() ;
}

//关闭音频播放器
//##ModelId=465286A101A5
LRESULT CMDFDlg::OnMM_WOM_CLOSE(UINT wParam, LONG lParam)
{
	theApp.OutPut("程序:调用 CMDFDlg::OnMM_WOM_CLOSE()") ;//%%%
	return 0; //theApp.m_pMedia->Free() ;
}

//##ModelId=465286A101B5
LRESULT CMDFDlg::GsmVoice(WPARAM wParam,LPARAM lParam)
{
	theApp.OutPut("程序:调用 CMDFDlg::GsmVoice()") ;//%%%
	return 0;//theApp.m_pMedia->AlarmVoice() ;	
}

//##ModelId=465286A101B9
LRESULT CMDFDlg::GsmVoiceClose(WPARAM wParam,LPARAM lParam)
{
	theApp.OutPut("程序:调用 CMDFDlg::GsmVoiceClose()") ;//%%%
	return 0;//theApp.m_pMedia->CloseVoice() ;	
}

//##ModelId=465286A100CB
BOOL CMDFDlg::PreTranslateMessage(MSG* pMsg) 
{
	// TODO: Add your specialized code here and/or call the base class
	CString strPath ;
	if( pMsg->message == WM_KEYDOWN && (pMsg->wParam == VK_RETURN || pMsg->wParam == VK_ESCAPE) )
	{
		//AfxMessageBox("hello") ;
		return TRUE ;
	}
	if( pMsg->message == WM_KEYDOWN && pMsg->wParam == VK_F1 )
	{
		strPath = theApp.m_strPath + "help.chm" ;
		ShellExecute(this->m_hWnd,"open",strPath,"","",SW_SHOW );
		return TRUE ;
	}
	return CDialog::PreTranslateMessage(pMsg);
}

//##ModelId=465286A10158
LRESULT CMDFDlg::OnReStart(UINT wParam,LONG lParam)
{
	//return theApp.ReStart() ;
	BOOL bResult = theApp.RestartMonitoring();
	if(bResult)
	{
		this->m_UI.Run(TRUE); 
	}
	return bResult;
}

//##ModelId=465286A101F4
LRESULT CMDFDlg::Refresh(WPARAM wParam,LPARAM lParam) 
{
	//用于窗口的拖动释放。
	return theApp.Refresh() ;
}


// 存储日志
//##ModelId=465286A10213
LRESULT CMDFDlg::onWriteLog(WPARAM wParam, LPARAM lParam)
{
	CString strLog = (CString&)wParam;
	//m_pAdoDB->WriteLog(strLog);

	return LRESULT();
}

// 显示错误信息
//##ModelId=465286A10222
LRESULT CMDFDlg::onShowError(WPARAM wParam, LPARAM lParam)
{
	return LRESULT();
}

// 显示日志信息
//##ModelId=465286A10232
LRESULT CMDFDlg::onShowLog(WPARAM wParam, LPARAM lParam)
{
	
	CString strTime,strTemp,strShow,strTip ;
	strTime = CTime::GetCurrentTime().Format ( "[%Y-%m-%d %H:%M:%S]" ) ;	//获取当前时间
	CString strOld;
	char *cBuf = (char *)wParam;
	strTip =  strTime + cBuf;
	m_logShow.GetWindowText(strOld);
		if (strOld.GetLength() > 5000)
		strOld.Empty();
	strOld += strTip;
	if (strOld.GetLength() >0 )
		strOld += "\r\n";

	this->GetDlgItem(IDC_SHOW)->SetWindowText(strOld);
	int linenum=((CEdit *)(this->GetDlgItem(IDC_SHOW)))->GetLineCount();
	((CEdit *)(this->GetDlgItem(IDC_SHOW)))->LineScroll(linenum);
	this->GetDlgItem(IDC_SHOW)->UpdateData();
	return LRESULT();
}

//##ModelId=465286A10203
LRESULT CMDFDlg::onServiceStatus(WPARAM wParam, LPARAM lParam)
{
	
	int iStatus = 0;
	iStatus  = (int)wParam;
	if (iStatus == 0)
		this->m_UI.Run(FALSE); 
	else
		this->m_UI.Run(TRUE); 

	return LRESULT();
}


//##ModelId=465286A10236
void CMDFDlg::OnEnChangeShow()
{
	// TODO:  如果该控件是 RICHEDIT 控件,则它将不会
	// 发送该通知,除非重写 CDialog::OnInitDialog()
	// 函数并调用 CRichEditCtrl().SetEventMask(),
	// 同时将 ENM_CHANGE 标志“或”运算到掩码中。
	// TODO:  在此添加控件通知处理程序代码


}



//##ModelId=465286A10243
void CMDFDlg::OnActivate(UINT nState, CWnd* pWndOther, BOOL bMinimized)
{
	CDialog::OnActivate(nState, pWndOther, bMinimized);

	m_UI.Run(theApp.m_Baseinfo.MonitorStatus); 

	// TODO: 在此处添加消息处理程序代码
}

//##ModelId=465286A10252
BOOL CMDFDlg::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult)
{
	// TODO: 在此添加专用代码和/或调用基类

	return CDialog::OnNotify(wParam, lParam, pResult);
}

//##ModelId=465286A10271
HBRUSH CMDFDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
	HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);

	// TODO:  在此更改 DC 的任何属性
	CRect lpRect;
	if(pWnd->GetDlgCtrlID() == IDC_SHOW)
	{

		pDC->SetBkMode(TRANSPARENT); 
		pDC->SetBkColor(RGB(255, 255, 255));
		CBrush *pBrush  = new CBrush(RGB(255, 255, 255));
		this->GetWindowRect(lpRect);
		ClientToScreen(lpRect);
		pDC->FillRect(lpRect,pBrush);

	}
	// TODO:  如果默认的不是所需画笔,则返回另一个画笔
	return hbr;
}

//##ModelId=465286A10276
void CMDFDlg::OnEnVscrollShow()
{
	//::SendMessage(m_logShow.m_hWnd,WM_PAINT,NULL,NULL);

	// TODO: 在此添加控件通知处理程序代码
}

⌨️ 快捷键说明

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