cetools.cpp
来自「串口通讯演示程序」· C++ 代码 · 共 278 行
CPP
278 行
// CeTools.cpp : Defines the class behaviors for the application.
//
#include "stdafx.h"
#include "CeTools.h"
#include "MainFrm.h"
#include "CeToolsDoc.h"
#include "CeToolsView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CCeToolsApp
BEGIN_MESSAGE_MAP(CCeToolsApp, CWinApp)
//{{AFX_MSG_MAP(CCeToolsApp)
ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG_MAP
// Standard file based document commands
ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
// Standard print setup command
ON_COMMAND(ID_FILE_PRINT_SETUP, CWinApp::OnFilePrintSetup)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCeToolsApp construction
CCeToolsApp::CCeToolsApp()
{
// TODO: add construction code here,
// Place all significant initialization in InitInstance
}
/////////////////////////////////////////////////////////////////////////////
// The one and only CCeToolsApp object
CCeToolsApp theApp;
/////////////////////////////////////////////////////////////////////////////
// CCeToolsApp initialization
BOOL CCeToolsApp::InitInstance()
{
AfxEnableControlContainer();
// Standard initialization
// If you are not using these features and wish to reduce the size
// of your final executable, you should remove from the following
// the specific initialization routines you do not need.
#ifdef _AFXDLL
Enable3dControls(); // Call this when using MFC in a shared DLL
#else
Enable3dControlsStatic(); // Call this when linking to MFC statically
#endif
// Change the registry key under which our settings are stored.
// TODO: You should modify this string to be something appropriate
// such as the name of your company or organization.
GetModuleFileName(NULL,AppPathName,MAX_PATH);
GetAppName(AppPathName);
// SetRegistryKey(_T("Local AppWizard-Generated Applications"));
SetRegistryKey(_T(AppPathName));
LoadStdProfileSettings(); // Load standard INI file options (including MRU)
// Register the application's document templates. Document templates
// serve as the connection between documents, frame windows and views.
CSingleDocTemplate* pDocTemplate;
pDocTemplate = new CSingleDocTemplate(
IDR_MAINFRAME,
RUNTIME_CLASS(CCeToolsDoc),
RUNTIME_CLASS(CMainFrame), // main SDI frame window
RUNTIME_CLASS(CCeToolsView));
AddDocTemplate(pDocTemplate);
// Parse command line for standard shell commands, DDE, file open
CCommandLineInfo cmdInfo;
ParseCommandLine(cmdInfo);
// Dispatch commands specified on the command line
if (!ProcessShellCommand(cmdInfo))
return FALSE;
// The one and only window has been initialized, so show and update it.
m_pMainWnd->ShowWindow(SW_SHOWMAXIMIZED);
m_pMainWnd->SetWindowText("华易金融平台—接收测试");
m_pMainWnd->UpdateWindow();
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
// No message handlers
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
// App command to run the dialog
void CCeToolsApp::OnAppAbout()
{
CAboutDlg aboutDlg;
aboutDlg.DoModal();
}
/////////////////////////////////////////////////////////////////////////////
// CCeToolsApp message handlers
int CCeToolsApp::FlagCharToBuf(CString sStr, CString *dStr)
{
int len,i,FlagCharNum=0;
CString str1,str2,*ss;
ss=dStr;
str1.Empty();
if(sStr.IsEmpty())
return 0;
len=sStr.GetLength();
for(i=0;i<len;i++)
{
str2=sStr.Mid(i,1);
if(str2!=" ")
str1+=str2;
if(str2==" " && str1.GetLength()>0)
{
*ss=str1;
ss++;
str1.Empty();
FlagCharNum++;
if(FlagCharNum>20)
return FlagCharNum;
}
}
if(str1.GetLength()>0)
{
*ss=str1;
ss++;
str1.Empty();
FlagCharNum++;
if(FlagCharNum>20)
return FlagCharNum;
}
return FlagCharNum;
}
int CCeToolsApp::Run()
{
int i;
m_hWnd=AfxGetApp()->m_pMainWnd->m_hWnd;
PortState=1;
ShowMouseFlag=0;
for(i=0;i<2;i++)
{
ViewDataStr[i].Enable=1;
ViewDataStr[i].DataFlag=0;
ViewDataStr[i].ViewData.Empty();
ViewDataStr2[i].Enable=1;
ViewDataStr2[i].DataFlag=0;
ViewDataStr2[i].ViewData.Empty();
}
ErrCodeRate.CommTotalLen=1;
ErrCodeRate.TotalLen=1;
ErrCodeRate.ErrLen=0;
ErrCodeRate.ErrCodeRate=0;
ErrCodeRate2.CommTotalLen=1;
ErrCodeRate2.TotalLen=1;
ErrCodeRate2.ErrLen=0;
ErrCodeRate2.ErrCodeRate=0;
ErrCodeRate_m.CommTotalLen=1;
ErrCodeRate_m.ErrLen=0;
ErrCodeRate_m.TotalLen=0;
ErrCodeRate2_m.CommTotalLen=1;
ErrCodeRate2_m.ErrLen=0;
ErrCodeRate2_m.TotalLen=0;
ErrCodeRate_t.CommTotalLen=1;
ErrCodeRate_t.ErrLen=0;
ErrCodeRate_t.TotalLen=0;
ErrCodeRate2_t.CommTotalLen=1;
ErrCodeRate2_t.ErrLen=0;
ErrCodeRate2_t.TotalLen=0;
return CWinApp::Run();
}
BOOL CCeToolsApp::InitApplication()
{
BmState=1;
BufferDataLen=0;
ShowSel=1;
CurRevType=1;//有编码
TotalRunTime=0;
return CWinApp::InitApplication();
}
float CCeToolsApp::ExpErrRate(int Err, int All)
{
if(Err==0)
return 0;
if(Err>All)
Err=All;
return (float)(((float)Err/(float)All)*100);
}
void CCeToolsApp::GetAppName(TCHAR *AppPath)
{
int ch = '\\';
char *pdest,*pdest2;
int result,result2;
int i=0;
pdest=strrchr(AppPath,ch);
if(pdest!=NULL)
{
result= pdest - AppPath + 1;
ch='.';
pdest2=strrchr(AppPath,ch);
if(pdest2!=NULL)
{
result2= pdest2 - AppPath + 1;
for(int j=result;j<result2-1;j++,i++)
AppPath[i]=AppPath[j];
AppPath[i]='\0';
}
}
else
strcpy(AppPath,"CeTools");
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?