⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 worddlg.cpp

📁 基于MFC的加密解密程序,能自己设置密文,并进行相关操作
💻 CPP
字号:
// wordDlg.cpp : implementation file
//

#include "stdafx.h"
#include "word.h"
#include "wordDlg.h"
#include<math.h>
#include<stdio.h>
#include<iostream.h>
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
char *p1,*p2,*p3;//定义char指针,用来读取文本框中的字符

CString as1,as2,as3,as,as4,as5;  //定义CString类
char a[100];//存放字符
	




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()

/////////////////////////////////////////////////////////////////////////////
// CWordDlg dialog

CWordDlg::CWordDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CWordDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CWordDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CWordDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CWordDlg)
	DDX_Control(pDX, IDC_EDIT6, m_a6);
	DDX_Control(pDX, IDC_EDIT5, m_a5);
	DDX_Control(pDX, IDC_EDIT4, m_a4);
	DDX_Control(pDX, IDC_EDIT3, m_a3);
	DDX_Control(pDX, IDC_EDIT2, m_a2);
	DDX_Control(pDX, IDC_EDIT1, m_a1);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CWordDlg, CDialog)
	//{{AFX_MSG_MAP(CWordDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
	ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
	ON_BN_CLICKED(IDC_BUTTON3, OnButton3)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CWordDlg message handlers

BOOL CWordDlg::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 CWordDlg::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 CWordDlg::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 CWordDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}









void CWordDlg::OnButton1() //加密按钮
{
	int len1=m_a1.GetWindowTextLength();//取明文框中输入的字符串长度
	int len2=m_a2.GetWindowTextLength();//取密钥框中输入的字符串长度
	int m1,m2;
	
	if(len1<=6&&len2<=6)   //不能输入长度大于6的字符串
	{
	m_a1.GetWindowText(as1);
	p1=as1.GetBuffer(as1.GetLength());   //字符串的录入
						
	m_a2.GetWindowText(as2);
	p2=as2.GetBuffer(as2.GetLength());   //字符串的录入


	
    m1=strtoul(p1,NULL,36);  //将输入的字符串转换成整型数
	m2=strtoul(p2,NULL,36);  //将输入的字符串转换成整型数
	as=itoa(m1+m2,a,36);    //将两个整型数相加,再转换成字符---------------------------------------------
		
	as3.Format("%s",as);
	m_a3.SetWindowText(as3);   //在文本框中输出字符
	}
	else
		AfxMessageBox("错误,数据不能超过6位");//长度超过6位报错

	
}

void CWordDlg::OnButton2()   //解密按钮
{
	int len1=m_a4.GetWindowTextLength();//取密文框中输入的字符串长度
	int len2=m_a5.GetWindowTextLength();//取密钥框中输入的字符串长度
	int m1,m2;

	if(len1<=7&&len2<=6)  //不能输入长度大于6的字符串
	{
	m_a4.GetWindowText(as1);
	p1=as1.GetBuffer(as1.GetLength());   //字符串的录入
						
	m_a5.GetWindowText(as2);
	p2=as2.GetBuffer(as2.GetLength());	 //字符串的录入	
	
	m1=strtoul(p1,NULL,36);//将输入的字符串转换成整型数
	m2=strtoul(p2,NULL,36);//将输入的字符串转换成整型数

	as5=itoa(m1-m2,a,36);//将两个整型数相加,再转换成字符-----------------------------------------



	as4.Format("%s",as5);
	m_a6.SetWindowText(as4);//在文本框中输出字符
	}
	else
		AfxMessageBox("错误,数据不能超过6位");//长度超过6位报错
	
}

void CWordDlg::OnButton3() 
{
	AfxMessageBox("明文和密钥不能超过6位且不能为空");
	
}

⌨️ 快捷键说明

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