portdataview.cpp

来自「串口通讯演示程序」· C++ 代码 · 共 369 行

CPP
369
字号
// RevDataView.cpp : implementation of the CPortDataView class
//



#include "stdafx.h"
#include "CeTools.h"

//#include "RevDataDoc.h"
#include "CntrItem.h"
#include "PortDataView.h"
#include "SetFlagCharDlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// CPortDataView

IMPLEMENT_DYNCREATE(CPortDataView, CRichEditView)

BEGIN_MESSAGE_MAP(CPortDataView, CRichEditView)
	//{{AFX_MSG_MAP(CPortDataView)
	ON_COMMAND(ID_FLAGCHAR, OnFlagchar)
	ON_COMMAND(ID_FLAGCOLOR, OnFlagcolor)
	ON_COMMAND(ID_BACKCOLOR, OnBackcolor)
	ON_COMMAND(ID_FONT_SET, OnFontSet)
	ON_COMMAND(ID_CHARCOLOR_REV, OnCharcolorRev)
	ON_COMMAND(ID_CLEAR_CHAR, OnClearChar)
	ON_COMMAND(ID_FLAGCHAR_VIEW, OnFlagcharView)
	ON_COMMAND(ID_C_VIEW, OnCView)
	ON_COMMAND(ID_P_VIEW, OnPView)
	ON_WM_TIMER()
	ON_COMMAND(ID_SHOW_A, OnShowA)
	ON_COMMAND(ID_SHOW_B, OnShowB)
	ON_COMMAND(ID_SHOW_ALL, OnShowAll)
	ON_WM_MOUSEMOVE()
	//}}AFX_MSG_MAP
	// Standard printing commands
	ON_COMMAND(ID_FILE_PRINT, CRichEditView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_DIRECT, CRichEditView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, CRichEditView::OnFilePrintPreview)

	ON_MESSAGE(ID_VIEWDATA, OnViewData)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CPortDataView construction/destruction

CPortDataView::CPortDataView()
{
	// TODO: add construction code here

}

CPortDataView::~CPortDataView()
{
}

BOOL CPortDataView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CRichEditView::PreCreateWindow(cs);
}

void CPortDataView::OnInitialUpdate()
{
	CRichEditView::OnInitialUpdate();


	// Set the printing margins (720 twips = 1/2 inch).
	SetMargins(CRect(720, 720, 720, 720));

	app = (CCeToolsApp *)AfxGetApp();
	GetRichEditCtrl().GetDefaultCharFormat(cf);
	cf.dwMask=CFM_COLOR|CFM_SIZE|CFM_FACE;
	cf.dwEffects=CFE_BOLD|CFE_ITALIC;

	CString str;
	str=AfxGetApp()->GetProfileString(_T("SetParam2"),_T("FaceName"),"System");
	logfont.lfHeight=AfxGetApp()->GetProfileInt(_T("SetParam2"),_T("lfHeight"),-21);
	cf.yHeight=AfxGetApp()->GetProfileInt(_T("SetParam2"),_T("yHeight"),200);
	lstrcpy(logfont.lfFaceName,str);

	str=AfxGetApp()->GetProfileString(_T("SetParam2"),_T("RevCharColor"),"16744448");
	sscanf(str,"%u",&colorref_rev);
	str=AfxGetApp()->GetProfileString(_T("SetParam2"),_T("BackColor"),"14811135");//RGB(255,255,225)
	sscanf(str,"%u",&colorref_back);

	GetRichEditCtrl().SetBackgroundColor(FALSE,colorref_back);//RGB(255,255,225)

	str=AfxGetApp()->GetProfileString(_T("SetParam2"),_T("FlagCharColor"),"255");
	sscanf(str,"%u",&FlagCharColor);
	FlagCharNum=0;
	str=AfxGetApp()->GetProfileString(_T("SetParam2"),_T("FlagChar"),"");

	if(!str.IsEmpty())
	{
		FlagCharNum=1;
		FlagChar[0]=str;
	}
//	FlagCharNum=app->FlagCharToBuf(str,FlagChar);

	ViewPause=0;
	ListViewCount=2000;
	SetTimer(1,50,NULL);
}

/////////////////////////////////////////////////////////////////////////////
// CPortDataView printing

BOOL CPortDataView::OnPreparePrinting(CPrintInfo* pInfo)
{
	// default preparation
	return DoPreparePrinting(pInfo);
}

void CPortDataView::OnTimer(UINT nIDEvent) 
{
	// TODO: Add your message handler code here and/or call default
	ViewData();
	CRichEditView::OnTimer(nIDEvent);
}
void CPortDataView::OnViewData(WPARAM wParam,LPARAM lParam)
{
}
void CPortDataView::OnFontSet() 
{
	CFontDialog dlg(&logfont,CF_SCREENFONTS);
	if(dlg.DoModal()==IDOK)
	{
		logfont.lfHeight=dlg.m_lf.lfHeight;
		lstrcpy(logfont.lfFaceName,dlg.GetFaceName());

		cf.yHeight=dlg.GetSize();
		lstrcpy(cf.szFaceName,dlg.GetFaceName());

		AfxGetApp()->WriteProfileInt(_T("SetParam2"),_T("lfHeight"),logfont.lfHeight);
		AfxGetApp()->WriteProfileInt(_T("SetParam2"),_T("yHeight"),cf.yHeight);
		AfxGetApp()->WriteProfileString(_T("SetParam2"),_T("FaceName"),logfont.lfFaceName);
	}
	
}
void CPortDataView::OnBackcolor() 
{
	CString str;
	CColorDialog dlg(colorref_back);
	if(dlg.DoModal()==IDOK)
	{
		colorref_back=dlg.GetColor();
		str.Format("%u",colorref_back);
//		AfxGetApp()->WriteProfileInt(_T("SetParam2"),_T("BackColor"),colorref_back);
		AfxGetApp()->WriteProfileString(_T("SetParam2"),_T("BackColor"),str);
		GetRichEditCtrl().SetBackgroundColor(FALSE,colorref_back);
	}
	
}
void CPortDataView::OnCharcolorRev() 
{
	CString str;
	CColorDialog dlg(colorref_rev);
	if(dlg.DoModal()==IDOK)
	{
		colorref_rev=dlg.GetColor();
		str.Format("%u",colorref_rev);
		AfxGetApp()->WriteProfileString(_T("SetParam2"),_T("RevCharColor"),str);
	}
	
}

void CPortDataView::OnClearChar() 
{
	GetRichEditCtrl().SetSel(0,GetRichEditCtrl().GetTextLength());
	GetRichEditCtrl().Clear();
	
}
void CPortDataView::OnFlagcolor() 
{
	CString str;
	CColorDialog dlg(FlagCharColor);
	if(dlg.DoModal()==IDOK)
	{
		FlagCharColor=dlg.GetColor();
		str.Format("%u",FlagCharColor);
		AfxGetApp()->WriteProfileString(_T("SetParam2"),_T("FlagCharColor"),str);
	}
	
}
void CPortDataView::OnFlagchar() 
{
	CSetFlagCharDlg dlg;
	CString str,str1,str2,ss;
	int i=0;
	dlg.para="SetParam2";
	if(dlg.DoModal()==IDOK)
	{
		FlagCharNum=0;
		str=AfxGetApp()->GetProfileString(_T("SetParam2"),_T("FlagChar"),"");
		FlagCharNum=1;
		FlagChar[0]=str;
//		FlagCharNum=app->FlagCharToBuf(str,FlagChar);
		AfxGetApp()->WriteProfileInt(_T("SetParam2"),_T("FlagCharNum"),FlagCharNum);
  }
}
BOOL CPortDataView::PreTranslateMessage(MSG* pMsg) 
{
	if (pMsg->message == WM_RBUTTONDOWN)
	{
		CMenu Menu;
		CPoint pt;

		pt.x = LOWORD(pMsg->lParam);
		pt.y = HIWORD(pMsg->lParam);
		ClientToScreen(&pt);

		if (Menu.LoadMenu(IDR_MENU2))
		{
			CMenu* pSubMenu = Menu.GetSubMenu(0);

			if (pSubMenu!=NULL)
			{
				CHARRANGE cr;
				GetRichEditCtrl().GetSel(cr);
				if(cr.cpMin==cr.cpMax)
					pSubMenu->EnableMenuItem(ID_EDIT_COPY,MF_GRAYED);
				if(ViewPause)
					pSubMenu->EnableMenuItem(ID_P_VIEW,MF_GRAYED);
				else
					pSubMenu->EnableMenuItem(ID_C_VIEW,MF_GRAYED);

				if(app->ShowSel==1)
					pSubMenu->CheckMenuItem(ID_SHOW_A,MF_CHECKED);
				else if(app->ShowSel==2)
					pSubMenu->CheckMenuItem(ID_SHOW_B,MF_CHECKED);
				else
					pSubMenu->CheckMenuItem(ID_SHOW_ALL,MF_CHECKED);

				CWnd* pWndPop=this;
				pWndPop=pWndPop->GetParent();
				pSubMenu->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON,pt.x,pt.y,pWndPop);
			}
		}
	}
	
	return CRichEditView::PreTranslateMessage(pMsg);
}
void CPortDataView::OnFlagcharView() 
{
	for(int i=0;i<FlagCharNum;i++)
	{
		GetRichEditCtrl().SetSel(0,0);
		while(FindText(FlagChar[i]))
		{
			cf.crTextColor=FlagCharColor;
			SetCharFormat(cf);
			GetRichEditCtrl().ReplaceSel(FlagChar[i]);
		}
	}
}
void CPortDataView::OnCView() 
{
	ViewPause=0;	
}

void CPortDataView::OnPView() 
{
	ViewPause=1;	
}
int CPortDataView::ViewData() 
{
	long eChart;
	CString str;
	str.Empty();
	if(app->ShowSel==1)
		str=GetViewStr(1);
	else if(app->ShowSel==2)
		str=GetViewStr(2);
	else
	{
		str=GetViewStr(1);
		str+=GetViewStr(2);
	}
	if(ViewPause==1)
		return 0;
	if(!str.IsEmpty())
	{
		eChart=GetRichEditCtrl().GetTextLength();
		GetRichEditCtrl().SetSel(eChart,eChart);
		cf.crTextColor=colorref_rev;
		GetRichEditCtrl().SetSelectionCharFormat(cf);
		GetRichEditCtrl().ReplaceSel(str);

		if(GetRichEditCtrl().GetLineCount()>ListViewCount)
			OnClearChar();
	}
	return 1;
}
void CPortDataView::OnShowA() 
{
	app->ShowSel=1;	
	::SendMessage(app->m_hWnd,ID_APPINFO,0,0);
}

void CPortDataView::OnShowB() 
{
	app->ShowSel=2;	
	::SendMessage(app->m_hWnd,ID_APPINFO,0,0);
}

void CPortDataView::OnShowAll() 
{
	app->ShowSel=0;	
	::SendMessage(app->m_hWnd,ID_APPINFO,0,0);
}

CString CPortDataView::GetViewStr(int ch)
{
	int i;
	CString str;
	str.Empty();
	if(ch==1)	
	{
		for(i=0;i<2;i++)
		{
			if(app->ViewDataStr[i].Enable==1 && app->ViewDataStr[i].DataFlag==1)
			{
				app->ViewDataStr[i].Enable=0;
				str=app->ViewDataStr[i].ViewData;
				app->ViewDataStr[i].ViewData.Empty();
				app->ViewDataStr[i].DataFlag=0;
				app->ViewDataStr[i].Enable=1;
				break;
			}
		}
	}
	else if(ch==2)
	{
		for(i=0;i<2;i++)
		{
			if(app->ViewDataStr2[i].Enable==1 && app->ViewDataStr2[i].DataFlag==1)
			{
				app->ViewDataStr2[i].Enable=0;
				str=app->ViewDataStr2[i].ViewData;
				app->ViewDataStr2[i].ViewData.Empty();
				app->ViewDataStr2[i].DataFlag=0;
				app->ViewDataStr2[i].Enable=1;
				break;
			}
		}
	}
	return str;
}
void CPortDataView::OnMouseMove(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	if(app->ShowMouseFlag==0)
	{
		ShowCursor(TRUE);
		app->ShowMouseFlag=1;
	}
	
	CRichEditView::OnMouseMove(nFlags, point);
}

⌨️ 快捷键说明

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