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

📄 deslxpdlg.cpp

📁 用AES 加解密文件,内容包括一个测试EXE,和加解密模块D
💻 CPP
字号:
// DESlxpDlg.cpp : implementation file
//

#include "stdafx.h"

#define CODECDLL_IMPORT
#include "DESlxp.h"
#include "DESlxpDlg.h"
#include "..\FileCodec\FileCodec.h"
#pragma comment(lib,"..\\FileCodec\\Debug\\FileCodec.lib");

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

/////////////////////////////////////////////////////////////////////////////
// CDESlxpDlg dialog

CDESlxpDlg::CDESlxpDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CDESlxpDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CDESlxpDlg)
	m_filekey = _T("12345678");
	m_filename = _T("");
	m_dirkey = _T("12345678");
	m_dirname = _T("");
	m_filesuffix = _T("groovy");
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CDESlxpDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CDESlxpDlg)
	DDX_Text(pDX, IDC_EDIT_FILEKEY,  m_filekey);
	DDX_Text(pDX, IDC_EDIT_FILENAME, m_filename);
	DDX_Text(pDX, IDC_EDIT_DIRKEY,   m_dirkey);
	DDX_Text(pDX, IDC_EDIT_DIRNAME,  m_dirname);
	DDX_Text(pDX, IDC_EDIT_FILESUFFIX, m_filesuffix);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CDESlxpDlg, CDialog)
	//{{AFX_MSG_MAP(CDESlxpDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_BUTTON_FILEENC, OnFileEnc)
	ON_BN_CLICKED(IDC_BUTTON_FILEDEC, OnFileDec)
	ON_BN_CLICKED(IDC_BUTTON_DIRENC, OnDirEnc)
	ON_BN_CLICKED(IDC_BUTTON_DIRDEC, OnDirDec)
	ON_BN_CLICKED(IDC_BUTTON_SELECTFILE, OnSelectFile)
	ON_BN_CLICKED(IDC_BUTTON_SELECTDIR, OnSelectDir)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDESlxpDlg message handlers

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

void CDESlxpDlg::OnFileEnc() 
{
	UpdateData(TRUE);

	if(m_filename=="")
	{
		AfxMessageBox("请选择一个文件!");
		return;
	}

	CString errMsg;
	CFileCodec fc;
	fc.EncFile(m_filekey,m_filename,errMsg);
	AfxMessageBox("加密成功!");
	UpdateData(FALSE);
}

void CDESlxpDlg::OnFileDec() 
{
	UpdateData(TRUE);

	if(m_filename=="")
	{
		AfxMessageBox("请选择一个文件!");
		return;
	}

	CString errMsg;
	CFileCodec fc;
	fc.DecFile(m_filekey,m_filename,errMsg);
	if(errMsg!="")
		AfxMessageBox(errMsg);
	else
		AfxMessageBox("解密成功!");

	UpdateData(FALSE);	
}

void CDESlxpDlg::OnDirEnc() 
{
	UpdateData(TRUE);

	if(m_dirname=="")
	{
		AfxMessageBox("请选择一个文件夹!");
		return;
	}
	if(m_filesuffix=="")
	{
		AfxMessageBox("请输入文件类型!");
		return;
	}

	CString errMsg;
	CFileCodec fc;
	if(fc.EncDir(m_dirkey,m_dirname,m_filesuffix, errMsg)!=0)
		AfxMessageBox(errMsg);
	else
	    AfxMessageBox("加密成功!");

	UpdateData(FALSE);
}

void CDESlxpDlg::OnDirDec() 
{
	UpdateData(TRUE);

	if(m_dirname=="")
	{
		AfxMessageBox("请选择一个文件夹!");
		return;
	}
	if(m_filesuffix=="")
	{
		AfxMessageBox("请输入文件类型!");
		return;
	}

	CString errMsg;
	CFileCodec fc;
	if(fc.DecDir(m_dirkey,m_dirname,m_filesuffix, errMsg)!=0)
		AfxMessageBox(errMsg);
	else
	    AfxMessageBox("解密成功!");

	UpdateData(FALSE);
}

void CDESlxpDlg::OnSelectFile() 
{
	UpdateData(TRUE);
	CFileDialog dlg(1,NULL,NULL,OFN_HIDEREADONLY ,"All Files(*.*)|*.*||");
	if(IDOK!=dlg.DoModal())return;
	m_filename=dlg.GetPathName();
	UpdateData(FALSE);
}

void CDESlxpDlg::OnSelectDir() 
{
    UpdateData(TRUE);
	m_dirname = GetDirPath();
	UpdateData(FALSE);
}



CString CDESlxpDlg::GetDirPath()
{
	char		szTitle[]		= "请选择一个本地目录:";
	char		szPath[MAX_PATH * 2];
	BROWSEINFO	m_bi;
	BOOL		bRet			= FALSE;
	BOOL		bLoop			= TRUE;
	

    m_bi.ulFlags		= BIF_RETURNONLYFSDIRS;
    m_bi.hwndOwner		= this->m_hWnd;
    m_bi.pidlRoot		= NULL;
    m_bi.lpszTitle		= szTitle;
    m_bi.lpfn			= NULL;
    m_bi.lParam			= NULL;
    m_bi.pszDisplayName = szPath;
	
	while (bLoop)
	{
		bRet = FALSE;
		
		LPITEMIDLIST pidl = ::SHBrowseForFolder( &m_bi );
		
		if ( pidl )
		{
			bRet = ::SHGetPathFromIDList ( pidl, szPath );
			
			IMalloc * pMalloc = NULL;
			if ( SUCCEEDED ( ::SHGetMalloc( &pMalloc ) ) )  // 取得IMalloc分配器接口
			{
				pMalloc->Free( pidl );    // 释放内存
				pMalloc->Release();       // 释放接口
			}
		}
		
		if (bRet)
		{
			if ( '\\' == szPath[0] && '\\' == szPath[1] )
			{
				MessageBox("不能设置网络路径作为保密文件夹,请重新选择", "错误", MB_OK|MB_ICONERROR);
			}
			else
			{
				bLoop = FALSE;
			}
		}
		else
		{
			bLoop = FALSE;
		}
	}

	if ( bRet )
	{
		return szPath;
	}
	else
	{
		return "";
	}



}

⌨️ 快捷键说明

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