📄 laihui1dlg.cpp
字号:
// laihui1Dlg.cpp : implementation file
#include "stdafx.h"
#include "laihui1.h"
#include "laihui1Dlg.h"
#include "Laihui1BM.h"
#include "LILI_II.H"
#include "Stream.h"
#include "string.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
LILI_II LILI ;
Key_Stream Test;
LFSR *C_D=&LILI.LFSRc;//指针用于指向LFSRc或LFSRd,此时初始让其指向LFSRc
/////////////////////////////////////////////////////////////////////////////
// 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()
/////////////////////////////////////////////////////////////////////////////
// CLaihui1Dlg dialog
CLaihui1Dlg::CLaihui1Dlg(CWnd* pParent /*=NULL*/)
: CDialog(CLaihui1Dlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CLaihui1Dlg)
m_edit1 = _T("");
m_edit2 = _T("");
m_edit3 = 0;
m_edit4 = 0;
m_radio1 = -1;
m_radio3 = -1;
m_edit5 = _T("");
m_edit6 = 0;
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CLaihui1Dlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CLaihui1Dlg)
DDX_Control(pDX, IDC_EDIT8, c_edit8);
DDX_Control(pDX, IDC_EDIT7, c_edit7);
DDX_Control(pDX, IDC_EDIT6, c_edit6);
DDX_Control(pDX, IDC_EDIT5, c_edit5);
DDX_Control(pDX, IDC_EDIT2, c_edit2);
DDX_Control(pDX, IDC_EDIT1, c_edit1);
DDX_Text(pDX, IDC_EDIT1, m_edit1);
DDV_MaxChars(pDX, m_edit1, 128);
DDX_Text(pDX, IDC_EDIT2, m_edit2);
DDV_MaxChars(pDX, m_edit2, 128);
DDX_Text(pDX, IDC_EDIT3, m_edit3);
DDX_Text(pDX, IDC_EDIT4, m_edit4);
DDX_Radio(pDX, IDC_RADIO1, m_radio1);
DDX_Radio(pDX, IDC_RADIO3, m_radio3);
DDX_Text(pDX, IDC_EDIT5, m_edit5);
DDX_Text(pDX, IDC_EDIT6, m_edit6);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CLaihui1Dlg, CDialog)
//{{AFX_MSG_MAP(CLaihui1Dlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
ON_EN_CHANGE(IDC_EDIT1, OnChangeEdit1)
ON_EN_CHANGE(IDC_EDIT2, OnChangeEdit2)
ON_BN_CLICKED(IDC_BUTTON3, OnButton3)
ON_BN_CLICKED(IDC_BUTTON4, OnButton4)
ON_BN_CLICKED(IDC_RADIO1, OnRadio1)
ON_BN_CLICKED(IDC_RADIO2, OnRadio2)
ON_BN_CLICKED(IDC_BUTTON5, OnButton5)
ON_BN_CLICKED(IDC_BUTTON6, OnButton6)
ON_BN_CLICKED(IDC_BUTTON7, OnButton7)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CLaihui1Dlg message handlers
BOOL CLaihui1Dlg::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
// UpdateData(TRUE);
m_radio1=0; //初始化radio1,使黑点指向LFSRc
m_radio3=0; //初始化radio3,使黑点指向Fibonacci配置
m_edit6=100;
UpdateData(FALSE);
LILI.LFSRc.length=7; //初始配置LFSRc的长度
LILI.LFSRc.length_a=7;
LILI.LFSRd.length=8; //初始配置LFSRd的长度
LILI.LFSRd.length_a=8;
char temp[8];
int i;
strcpy(temp,"1011011");
for(i=0;i<LILI.LFSRc.length;i++) LILI.LFSRc.a[i]=temp[i]-'0';
strcpy(temp,"1110001");
for(i=0;i<LILI.LFSRc.length;i++) LILI.LFSRc.q[i]=temp[i]-'0';
strcpy(temp,"10001011");
for(i=0;i<LILI.LFSRd.length;i++) LILI.LFSRd.a[i]=temp[i]-'0';
strcpy(temp,"11001101");
for(i=0;i<LILI.LFSRd.length;i++) LILI.LFSRd.q[i]=temp[i]-'0';
OnRadio1();
c_edit8.SetWindowText("初始化配置LFSRc(状态q的长度即为寄存器长度)");
return TRUE; // return TRUE unless you set the focus to a control
}
void CLaihui1Dlg::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 CLaihui1Dlg::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 CLaihui1Dlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CLaihui1Dlg::OnButton1()
{
int i=0;
char t,sum=0;
UpdateData(TRUE);
c_edit1.GetWindowText(m_edit1);
if (!m_radio1)
C_D=&LILI.LFSRc;
else
C_D=&LILI.LFSRd;
while (i<m_edit1.GetLength())
{
t=m_edit1.GetAt(i)-'0';
if ((t!=0)&&(t!=1))
{
MessageBox("输入有错,每位必须是'0' 或 '1'!","错误!",MB_ICONEXCLAMATION);
c_edit1.SetFocus();
UpdateData(FALSE);
return;
}
else {sum+=t;i++;}
}
if (sum==0)
{
MessageBox("输入全零,请重输!","错误!",MB_ICONEXCLAMATION);
c_edit1.SetFocus();
UpdateData(FALSE);
return;
}
if((C_D->length_a>C_D->length))
{
MessageBox("初始状态a的长度大于寄存器长度!","提示!",MB_ICONINFORMATION);
c_edit1.SetFocus();
UpdateData(FALSE);
return;
}
i=0;
while (i<m_edit1.GetLength())
{
t=m_edit1.GetAt(i)-'0';
C_D->q[i]=t;
i++;
}
C_D->length=m_edit1.GetLength();
}
void CLaihui1Dlg::OnButton2()
{
int i=0;
char t,sum=0;
UpdateData(TRUE);
c_edit2.GetWindowText(m_edit2);
if (!m_radio1)
C_D=&LILI.LFSRc;
else
C_D=&LILI.LFSRd;
if (!C_D->length)
{
MessageBox("寄存器q未配置!","提示!",MB_ICONINFORMATION);
c_edit1.SetFocus();
UpdateData(FALSE);
return;
}
while (i<m_edit2.GetLength())
{
t=m_edit2.GetAt(i)-'0';
if ((t!=0)&&(t!=1))
{
MessageBox("输入有错,每位必须是'0' 或 '1'!","错误!",MB_ICONEXCLAMATION);
c_edit2.SetFocus();
UpdateData(FALSE);
return;
}
else { sum+=t;i++;}
}
if (sum==0)
{
MessageBox("输入全零,请重输","错误!",MB_ICONEXCLAMATION);
c_edit2.SetFocus();
UpdateData(FALSE);
return;
}
if(m_edit2.GetLength()>C_D->length)
{
MessageBox("初始状态a的长度大于寄存器长度!","提示!",MB_ICONINFORMATION);
c_edit2.SetFocus();
UpdateData(FALSE);
return;
}
C_D->length_a=m_edit2.GetLength();
i=0;
while (i<m_edit2.GetLength())
{
t=m_edit2.GetAt(i)-'0';
C_D->a[i]=t;
i++;
}
while(i<C_D->length)
{
C_D->a[i]=0;
m_edit2+="0";
i++;
}
m_edit4=i;
UpdateData(FALSE);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -