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

📄 des encryptdlg.cpp

📁 DES加密程序 速度将就。。娃嘎嘎。。。 完整可运行的程序 有兴趣的加我qq 4964898
💻 CPP
字号:
// DES encryptDlg.cpp : 实现文件
//

#include "stdafx.h"
#include "DES encrypt.h"
#include "DES encryptDlg.h"
#include ".\des encryptdlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif

DWORD WINAPI CDESencryptDlg::EncryptThreadProc(
  LPVOID lpParameter
)
{
	       CDESencryptDlg* lpthis=(CDESencryptDlg*)lpParameter;
	
	 lpthis->GetDlgItem(IDC_DECRYPT)->EnableWindow(false);
	  lpthis->GetDlgItem(IDC_ENCRYPT)->EnableWindow(false);
  lpthis->m_strKey="";
  lpthis->UpdateData(false);

  lpthis->m_Edit.SetWindowText("加密进行中....");
switch(lpthis->m_Des.EncryptFile())
	{		
	case -3:
			lpthis->m_Edit.SetWindowText("打开文件错误");
	
			break;
		case 0:
	 lpthis->m_Edit.SetWindowText("加密文件完成");
	 break;
}
lpthis->m_hThread=NULL;
  lpthis->GetDlgItem(IDC_DECRYPT)->EnableWindow(true);
    lpthis->GetDlgItem(IDC_ENCRYPT)->EnableWindow(true);

 return 0;
}
DWORD WINAPI CDESencryptDlg::DecryptThreadProc(
  LPVOID lpParameter
  )
{
	CDESencryptDlg* lpthis=(CDESencryptDlg*)lpParameter;

	lpthis->m_strKey="";
lpthis->UpdateData(false);
	
	lpthis->m_Edit.SetWindowText("解密进行中....");
	
	lpthis->GetDlgItem(IDC_ENCRYPT)->EnableWindow(false);
lpthis->GetDlgItem(IDC_DECRYPT)->EnableWindow(false);

switch(lpthis->m_Des.DecryptFile())
{     
	case -1:
          
	lpthis->m_Edit.SetWindowText("文件类型错误 或扩展名不正确");

	      break;
     case   -2:
		 
		 
			lpthis->m_Edit.SetWindowText("解压密码错误请重新输入密码");

	     break;
   
         
   case -3:
          lpthis->m_Edit.SetWindowText("打开文件错误");
	     break;
   case 0:
          lpthis->m_Edit.SetWindowText("解密完成");
	   break;
}
lpthis->m_hThread=NULL;
 lpthis->GetDlgItem(IDC_ENCRYPT)->EnableWindow(true);
 lpthis->GetDlgItem(IDC_DECRYPT)->EnableWindow(true);
  return 0;
}
  
  
  
// 用于应用程序“关于”菜单项的 CAboutDlg 对话框

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// 对话框数据
	enum { IDD = IDD_ABOUTBOX };

	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV 支持

// 实现
protected:
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
END_MESSAGE_MAP()


// CDESencryptDlg 对话框



CDESencryptDlg::CDESencryptDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CDESencryptDlg::IDD, pParent)
	,m_fileType(_T(""))
	,m_Des()
	, m_strKey(_T(""))
	, m_strFileName(_T(""))
	,m_Progress() 
	,m_Edit()
{    m_hThread=NULL;
	INT m_StartTime=0;
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CDESencryptDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);

	DDX_Text(pDX, IDC_EDIT1, m_strKey);
	DDX_Text(pDX, IDC_EDIT2, m_strFileName);
	DDX_Control(pDX, IDC_PROGRESS1, m_Progress);
	DDX_Control(pDX, IDC_INFO, m_Edit);
	
}

BEGIN_MESSAGE_MAP(CDESencryptDlg, CDialog)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	//}}AFX_MSG_MAP
	ON_BN_CLICKED(IDC_OPEN, OnBnClickedOpen)
	ON_BN_CLICKED(IDC_ENCRYPT, OnBnClickedEncrypt)
	ON_EN_CHANGE(IDC_EDIT1, OnEnChangeEdit1)
	ON_BN_CLICKED(IDC_DECRYPT, OnBnClickedDecrypt)
	ON_MESSAGE(WM_DEFINE_POS, OnSetPos)
	
	ON_EN_CHANGE(IDC_INFO, OnEnChangeInfo)
	ON_BN_CLICKED(IDC_BUTTON1, OnBnClickedButton1)
END_MESSAGE_MAP()


// CDESencryptDlg 消息处理程序

BOOL CDESencryptDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// 将\“关于...\”菜单项添加到系统菜单中。

	// IDM_ABOUTBOX 必须在系统命令范围内。
	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);
		}
	}

	// 设置此对话框的图标。当应用程序主窗口不是对话框时,框架将自动
	//  执行此操作
	SetIcon(m_hIcon, TRUE);			// 设置大图标
	SetIcon(m_hIcon, FALSE);		// 设置小图标

	// TODO: 在此添加额外的初始化代码
	m_Des.SetHWD(this->GetSafeHwnd());
	
	
	::EnableWindow(this->GetDlgItem(IDC_ENCRYPT)->GetSafeHwnd(),false);
	::EnableWindow(this->GetDlgItem(IDC_DECRYPT)->GetSafeHwnd(),false);
	
	return TRUE;  // 除非设置了控件的焦点,否则返回 TRUE
}

void CDESencryptDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}

// 如果向对话框添加最小化按钮,则需要下面的代码
//  来绘制该图标。对于使用文档/视图模型的 MFC 应用程序,
//  这将由框架自动完成。

void CDESencryptDlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // 用于绘制的设备上下文

		SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);

		// 使图标在工作矩形中居中
		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;

		// 绘制图标
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
	    
		CDialog::OnPaint();
	}
}

//当用户拖动最小化窗口时系统调用此函数取得光标显示。
HCURSOR CDESencryptDlg::OnQueryDragIcon()
{
	return static_cast<HCURSOR>(m_hIcon);
}

void CDESencryptDlg::OnBnClickedOpen()
{
	// TODO: Add your control notification handler code here
CFileDialog dlg(true,NULL
,NULL,OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT
   ," Des File(*.DES)|*.des|All Files(*.*)|*.*||",NULL,0);
CString tmp1(""),tmp2("");
if(dlg.DoModal()==IDOK)
{   
	m_strFileName=dlg.GetPathName();
     
	tmp1=dlg.GetFileName();
     
	tmp2=dlg.GetFileTitle();
	
	m_fileType=tmp1.Mid(tmp2.GetLength());
    
	m_Des.SetFileType(m_fileType);
m_Des.SetFilePath(m_strFileName);
	
	this->UpdateData(false);
	
    ::EnableWindow(this->GetDlgItem(IDC_ENCRYPT)->GetSafeHwnd(),true);
	this->GetDlgItem(IDC_DECRYPT)->EnableWindow(true);


}

}

void CDESencryptDlg::OnBnClickedEncrypt()
{
	DWORD id=0;
	DWORD exit=0;
	
 m_hThread=::CreateThread(NULL,0,EncryptThreadProc,this,0,&id);
 
	//::GetExitCodeThread(m_hThread,&exit);

	
}

void CDESencryptDlg::OnEnChangeEdit1()
{
	
	
m_Edit.SetWindowText("正在输入密码...");
	
this->UpdateData(true);
ULONGLONG key=0;
ULONGLONG len=m_strKey.GetLength();


for(int i=0;i<len;i++)
{
	
key=key<<8;
	key=key|(BYTE)m_strKey.GetAt(i);

}

if(len<8)
key=key<<(8-len)*8;

m_Des.SetKey(key);

TRACEHEX("key",key);

	
}

void CDESencryptDlg::OnBnClickedDecrypt()

{  
	DWORD id=0;
	DWORD exit=0;
	
m_hThread=::CreateThread(NULL,0,DecryptThreadProc,this,0,&id);
 
	::GetExitCodeThread(m_hThread,&exit);
	
}

LRESULT CDESencryptDlg::OnSetPos(WPARAM wParam,LPARAM lParam)
{     
	
	ULONGLONG tmp=::GetCurrentTime();
	INT dif=tmp-m_StartTime;
	      m_StartTime=tmp;
	if(dif!=0)
	{
		
			SetDlgItemInt(IDC_SPEED,(UINT)(m_Des.m_progress-m_Des.m_difPro)*8000/1024/dif,0);
		//else SetDlgItemInt(IDC_SPEED,(UINT)(m_Des.m_progress-m_Des.m_difPro)*8000/1024/dif,0);
	}
 register tmp1=(INT)100*m_Des.GetProgress();
SetDlgItemInt(IDC_STATIC_PRO,tmp1,0);
m_Progress.SetPos(tmp1);
	


	
	
	return -1;


}

void CDESencryptDlg::OnEnChangeInfo()
{
	// TODO:  If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.

	// TODO:  Add your control notification handler code here
}

void CDESencryptDlg::OnBnClickedButton1()
{
  if(m_hThread) 
	SetThreadPriority(m_hThread,THREAD_PRIORITY_LOWEST);
    
  ::SendMessage(this->m_hWnd,WM_SYSCOMMAND,SC_MINIMIZE,0);
	
}

BOOL CDESencryptDlg::OnCommand(WPARAM wParam, LPARAM lParam)
{
	// TODO: Add your specialized code here and/or call the base class
        if(wParam==SC_MAXIMIZE)
		{if(m_hThread) 
				::SetThreadPriority(m_hThread,THREAD_PRIORITY_NORMAL);
		
		}return CDialog::OnCommand(wParam, lParam);
}

⌨️ 快捷键说明

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