📄 bch_coding.cpp
字号:
// BCH_Coding.cpp : Defines the class behaviors for the application.
//
#include "stdafx.h"
#include "BCH_Coding.h"
#include "MainFrm.h"
#include "ChildFrm.h"
#include "BCH_CodingDoc.h"
#include "BCH_CodingView.h"
#include "BCH_CodedFrm.h"
#include "BCH_CodedView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CBCH_CodingApp
BEGIN_MESSAGE_MAP(CBCH_CodingApp, CWinApp)
//{{AFX_MSG_MAP(CBCH_CodingApp)
ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
ON_COMMAND(ID_FILE_OPEN, OnFileOpen)
ON_COMMAND(ID_BCH_encode_15_7, OnBCHencode15_7)
//}}AFX_MSG_MAP
// Standard file based document commands
ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CBCH_CodingApp construction
CBCH_CodingApp::CBCH_CodingApp()
{
// TODO: add construction code here,
// Place all significant initialization in InitInstance
}
/////////////////////////////////////////////////////////////////////////////
// The one and only CBCH_CodingApp object
CBCH_CodingApp theApp;
/////////////////////////////////////////////////////////////////////////////
// CBCH_CodingApp initialization
BOOL CBCH_CodingApp::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.
SetRegistryKey(_T("Local AppWizard-Generated Applications"));
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.
CMultiDocTemplate* pDocTemplate;
pDocTemplate = new CMultiDocTemplate(
IDR_BCH_COTYPE,
RUNTIME_CLASS(CBCH_CodingDoc),
RUNTIME_CLASS(CChildFrame), // custom MDI child frame
RUNTIME_CLASS(CBCH_CodingView));
AddDocTemplate(pDocTemplate);
CMultiDocTemplate* pDocTemplate_Coded;
pDocTemplate_Coded = new CMultiDocTemplate(
IDR_BCH_CODEDTYPE,
RUNTIME_CLASS(CBCH_CodingDoc),
RUNTIME_CLASS(BCH_CodedFrm),
RUNTIME_CLASS(BCH_CodedView));
AddDocTemplate(pDocTemplate_Coded);
// create main MDI Frame window
CMainFrame* pMainFrame = new CMainFrame;
if (!pMainFrame->LoadFrame(IDR_MAINFRAME))
return FALSE;
m_pMainWnd = pMainFrame;
// 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 main window has been initialized, so show and update it.
pMainFrame->ShowWindow(m_nCmdShow);
pMainFrame->UpdateWindow();
IsFileOpen = FALSE;
IsFileCoded = FALSE;
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 CBCH_CodingApp::OnAppAbout()
{
CAboutDlg aboutDlg;
aboutDlg.DoModal();
}
/////////////////////////////////////////////////////////////////////////////
// CBCH_CodingApp message handlers
void CBCH_CodingApp::OnFileOpen()
{
TCHAR szFilter[] = _T("预编码文件(*.txt)|*.txt|");
CFileDialog fileDlg(TRUE, NULL, NULL, OFN_PATHMUSTEXIST, szFilter,NULL);
if (fileDlg.DoModal() == IDOK ) //确定打开一个文件
{
//确定文件存在
CString fn = fileDlg.GetFileName();
CFileFind ff;
if (!ff.FindFile(fn))
{
AfxMessageBox("文件不存在!");
return;
}
//通过模板指针打开窗口,并使窗口计数器加1;
POSITION pos = GetFirstDocTemplatePosition();
CDocTemplate* curTemplate = GetNextDocTemplate(pos);
curTemplate->OpenDocumentFile(NULL);
m_WndNum++;
//得到当前活动窗口的窗口、文档、视图指针,并记录源图的文档m_OriDoc
CMDIChildWnd* active_wnd;
active_wnd = ((CMDIFrameWnd*)AfxGetMainWnd())->MDIGetActive();
CBCH_CodingView* active_view = (CBCH_CodingView*)active_wnd->GetActiveView();
CBCH_CodingDoc* doc = (CBCH_CodingDoc*)active_wnd->GetActiveDocument();
POSITION pos_doc = curTemplate->GetFirstDocPosition();
m_OriDoc = (CBCH_CodingDoc*) curTemplate->GetNextDoc(pos_doc);
m_OriDoc->file_name = fileDlg.GetFileName();
CFile f(m_OriDoc->file_name, CFile::modeRead);
m_OriDoc->file_size = f.GetLength();
//存储文件中的数据
uint8_t data_buffer[1];
while (f.Read(data_buffer, 1) != 0)
m_OriDoc->LFileData.AddTail(data_buffer[0]);
f.Close();
doc->SetTitle(_T("未编码的文件数据信息") + doc->file_name);
active_view->UpdateScrollSizes();
IsFileOpen = TRUE;
}
}
void CBCH_CodingApp::OnBCHencode15_7()
{
POSITION CurTemplatePos = GetFirstDocTemplatePosition();
while (CurTemplatePos != NULL)
{
CDocTemplate* CurTemplate = GetNextDocTemplate(CurTemplatePos);
CString str;
CurTemplate->GetDocString(str, CDocTemplate::docName);
if (str == _T("BCH_Coded"))
{
CurTemplate->OpenDocumentFile(NULL);
POSITION pos = CurTemplate->GetFirstDocPosition();
CBCH_CodingDoc* doc = (CBCH_CodingDoc*)CurTemplate->GetNextDoc(pos);
pos = doc->GetFirstViewPosition();
CView* view = doc->GetNextView(pos);
CFrameWnd* frame = view->GetParentFrame();
frame->ShowWindow(TRUE);
frame->ActivateFrame();
doc->encode_file();
IsFileCoded = TRUE;
return;
}
}
AfxMessageBox(IDS_NOBCHCodedTEMPLATE);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -