📄 mzdlg.cpp
字号:
// MZDlg.cpp : implementation file
//
#include "stdafx.h"
#include "MZ.h"
#include "MZDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// 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)
//}}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()
/////////////////////////////////////////////////////////////////////////////
// CMZDlg dialog
CMZDlg::CMZDlg(CWnd* pParent /*=NULL*/)
: CDialog(CMZDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CMZDlg)
m_Input = _T("");
m_Output = _T("");
m_Output2 = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CMZDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CMZDlg)
DDX_Text(pDX, IDC_EDIT_Sequence, m_Input);
DDX_Text(pDX, IDC_EDIT_MZ, m_Output);
DDX_Text(pDX, IDC_EDIT_Output, m_Output2);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CMZDlg, CDialog)
//{{AFX_MSG_MAP(CMZDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTON_Begin, OnBUTTONBegin)
ON_BN_CLICKED(IDC_BUTTON_Back, OnBUTTONBack)
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMZDlg message handlers
BOOL CMZDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
}
void CMZDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// 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.
void CMZDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
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);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CMZDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CMZDlg::OnBUTTONBegin()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
long m,n,dlg1,dlg2;
CString temp,Data,form,str,flag,tag,strOutput,strLength,str1,str2,dlg3,key1,key2,InputTemp;
Data.Format("MH--CCITT.mdb");
form.Format("MHinfo");
dlg1=m_Input.GetLength();
key1.Format("%ld",dlg1);
GetDlgItem(IDC_Input_Num)->SetWindowText(key1);
m_DataBase.InitAccess();
m_DataBase.openAccess((_bstr_t)Data,form);
m_Output.Format("%s","000000000001");
temp=m_Input.Left(1);
if(temp=="1")
m_Output.Insert(m_Output.GetLength(),"00110101");
if(m_Input.GetLength()%1728!=0)//每一行必须1728个像素
{
MessageBox("Error! Please check and input again!");
return;
}//0000110111
while(!m_Input.IsEmpty())
{
InputTemp=m_Input.Right(m_Input.GetLength()-1728);
m_Input=m_Input.Left(1728);
//CString a,b;
//a.Format("%d",m_Input.GetLength());
//b.Format("%d",InputTemp.GetLength());
//MessageBox(a);
//MessageBox(b);
if(temp=="1")
{
flag="0";
tag="1";
fan: while(!m_Input.IsEmpty())
{
if(m_Input.Find(flag)==-1)
str=m_Input;
else
str=m_Input.Left(m_Input.Find(flag));
if(str.GetLength()<64&&str.GetLength()>0)
{
strLength.Format("%d",str.GetLength());
strOutput=SearchMZ(strLength,tag);
m_Output.Insert(m_Output.GetLength(),strOutput);
}
else if(str.GetLength()>63&&str.GetLength()<=1728)
{
m=str.GetLength()/64;
n=str.GetLength()-64*m;
str1.Format("%d",n);
str2.Format("%d",64*m);
strOutput=SearchMZ(str2,tag);
m_Output.Insert(m_Output.GetLength(),strOutput);
strOutput=SearchMZ(str1,tag);
m_Output.Insert(m_Output.GetLength(),strOutput);
}
// else if(str.GetLength()==0)
// continue;
// else
// {
// MessageBox("Error! Please check and input again!");
// }
temp=flag;
flag=tag;
tag=temp;
m_Input=m_Input.Right(m_Input.GetLength()-str.GetLength());
}
}
else if(temp=="0")
{
flag="1";
tag="0";
goto fan;
}
m_Output.Insert(m_Output.GetLength(),"000000000001");
m_Input=InputTemp;
}
dlg2=m_Output.GetLength()-12;
key2.Format("%ld",dlg2);
GetDlgItem(IDC_MZ_Length)->SetWindowText(key2);
dlg3.Format("%.2f",(float)dlg1/(float)dlg2);
GetDlgItem(IDC_Small_Rate)->SetWindowText(dlg3);
m_Output.Insert(m_Output.GetLength(),"000000000001000000000001000000000001000000000001000000000001000000000001");
UpdateData(FALSE);
}
CString CMZDlg::SearchMZ(CString seq, CString tag)//tag==1表示为黑色像素,tag==0代表白色像素;
{
CString strSQL,temp;
while(!m_DataBase.m_pRecordset->fsEOF)
{
strSQL=(char *)(_bstr_t)m_DataBase.m_pRecordset->GetCollect("RL长度");
if(seq==strSQL)
{
if(tag=="1")
{
temp=(char*)(_bstr_t)m_DataBase.m_pRecordset->GetCollect("黑游程码字");
}
else if(tag=="0")
{
temp=(char*)(_bstr_t)m_DataBase.m_pRecordset->GetCollect("白游程码字");
}
m_DataBase.m_pRecordset->MoveFirst();//将游标重置为数据库第一条记录
return temp;
}
else
m_DataBase.m_pRecordset->MoveNext();
}
m_DataBase.m_pRecordset->MoveFirst();
return "0";
}
void CMZDlg::OnBUTTONBack()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
CString Temp,tag="0",flag="1",strTemp,num,fill,dlg;
int back,i;
if(m_Output.Left(12)!="000000000001"||m_Output.Right(72)!="000000000001000000000001000000000001000000000001000000000001000000000001")
{
MessageBox("Receive Code Error! Please retransmmit again!");
return;
}
m_Output=m_Output.Right(m_Output.GetLength()-12);
m_Output=m_Output.Left(m_Output.GetLength()-72);
while(!m_Output.IsEmpty())
{
for(i=1;i<=m_Output.GetLength();i++)
{
Temp=m_Output.Left(i);
num=CopyMZ(Temp,tag);
if(num=="EOL")
break;
back=atoi(num);
if(back==-1)//说明没有匹配的码元
continue;
else if(back==0)//说明有匹配的码元,且本行初始像素为黑色像素
{
break;
}
else if(back>0)
{
for(int j=0;j<back;j++)
fill.Insert(fill.GetLength(),tag);
m_Output2.Insert(m_Output2.GetLength(),fill);
fill.Empty();
break;
}
}
if(back<64)
{
dlg=tag;//像素交换
tag=flag;
flag=dlg;
}
m_Output=m_Output.Right(m_Output.GetLength()-i);//去除已经解码完毕的MH码元
}
m_DataBase.exitAccess();//关闭数据库
UpdateData(FALSE);
}
CString CMZDlg::CopyMZ(CString str,CString tag)//tag==1表示为黑色像素,tag==0代表白色像素;
{
CString strSQL,temp;
if(tag=="1")
{
while(!m_DataBase.m_pRecordset->fsEOF)
{
strSQL=(char *)(_bstr_t)m_DataBase.m_pRecordset->GetCollect("黑游程码字");
if(str==strSQL)
{
temp=(char*)(_bstr_t)m_DataBase.m_pRecordset->GetCollect("RL长度");
m_DataBase.m_pRecordset->MoveFirst();//将游标重置为数据库第一条记录
return temp;
}
else
m_DataBase.m_pRecordset->MoveNext();
}
}
else if(tag=="0")
{
while(!m_DataBase.m_pRecordset->fsEOF)
{
strSQL=(char *)(_bstr_t)m_DataBase.m_pRecordset->GetCollect("白游程码字");
if(str==strSQL)
{
temp=(char*)(_bstr_t)m_DataBase.m_pRecordset->GetCollect("RL长度");
m_DataBase.m_pRecordset->MoveFirst();//将游标重置为数据库第一条记录
return temp;
}
else
m_DataBase.m_pRecordset->MoveNext();
}
}
m_DataBase.m_pRecordset->MoveFirst();
return "-1";
}
//00001101010000011100101011000000000000000000000000000000
//10111100011101000011101011001001110100001110100001111100000011
void CMZDlg::OnButton1()
{
// TODO: Add your control notification handler code here
m_Input.Empty();
m_Output.Empty();
m_Output2.Empty();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -