📄 desdec.cpp
字号:
// DesDialog.cpp : 实现文件
//
#include "stdafx.h"
#include "LmCrypt.h"
#include "Desdec.h"
#include ".\desdialog.h"
// CDesDialog 对话框
IMPLEMENT_DYNAMIC(CDesDialog, CDialog)
CDesDialog::CDesDialog(CWnd* pParent /*=NULL*/)
: CDialog(CDesDialog::IDD, pParent)
, str_input(_T(""))
{
}
CDesDialog::~CDesDialog()
{
}
void CDesDialog::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Text(pDX, IDC_EDIT, str_input);
DDV_MaxChars(pDX, str_input, 8);
}
BEGIN_MESSAGE_MAP(CDesDialog, CDialog)
ON_BN_CLICKED(IDOK, OnBnClickedOk)
ON_EN_CHANGE(IDC_EDIT, OnEnChangeEdit)
END_MESSAGE_MAP()
// CDesDialog 消息处理程序
BOOL CDesDialog::OnInitDialog()
{
CDialog::OnInitDialog();
CDocManager * p_docm=::AfxGetApp()->m_pDocManager;
//p_docm->
//::AfxGetMainWnd()->get
POSITION pos= ::AfxGetApp()->GetFirstDocTemplatePosition();
CDocTemplate *pTemplate = ::AfxGetApp()->GetNextDocTemplate(pos);
POSITION pos_doc;
CDocument* m_doc;
int i_doccount=p_docm->GetOpenDocumentCount();
pos_doc=pTemplate->GetFirstDocPosition();
for(int j=0;j<i_doccount;j++){
m_doc=pTemplate->GetNextDoc(pos_doc);
m_docdecls[j]=m_doc;
CListBox * p_listdoc=(CListBox *)GetDlgItem(IDC_LIST_DOC);
p_listdoc->AddString(m_doc->GetTitle());
//s_doc=pTemplate->GetNextDoc();
}
CEdit * p_edit=(CEdit *)this->GetDlgItem(IDC_EDIT);
p_edit->SetWindowText("abcdefgk");
return TRUE; // return TRUE unless you set the focus to a control
// 异常: OCX 属性页应返回 FALSE
}
void CDesDialog::OnBnClickedOk()
{
Encyp();
OnOK();
}
int CDesDialog::Encyp(void)
{
//str_input="abcdefgh";
str_key.MakeLower();
for(int i=0;i<9;i++)
{
key[i]=str_key.GetAt(i);
}
CDocument* m_subdoc=m_docdecls[0];
CString str_path=m_subdoc->GetPathName();
// CString str_dir;
// int nBytes = ::GetCurrentDirectory (0, NULL);
//char *szDir = new char [nBytes + 1];
//::GetCurrentDirectory (nBytes + 1, szDir);
//str_dir = szDir;
//CString str_filename=m_subdoc->GetTitle();
//str_filename=str_filename+"enc.txt";
//str_dir=str_dir+"/enc/"+str_filename;
int ii=str_path.ReverseFind('.');
CString str_newfile=str_path.Left(ii);
str_newfile=str_newfile+"enc.txt";
CFile f_cur,f_enc;
CFileException ex;
// open the source file for reading
if (!f_cur.Open(str_path,
CFile::modeRead | CFile::shareDenyWrite, &ex))
{
// complain if an error happened
// no need to delete the ex object
TCHAR szError[1024];
ex.GetErrorMessage(szError, 1024);
// cout << "Couldn't open source file: ";
//cout << szError;
}
if (!f_enc.Open(str_newfile,
CFile::modeCreate|CFile::modeWrite , &ex))
{
// complain if an error happened
// no need to delete the ex object
TCHAR szError[1024];
ex.GetErrorMessage(szError, 1024);
// cout << "Couldn't open source file: ";
//cout << szError;
}
ULONGLONG l_leng=f_cur.GetLength();
unsigned char buf[1024];
unsigned char* pbuf;
CString str_in;
CLmDes des;
UINT n;
//for(ULONGLONG i=0;i<l_leng/8+1;i++)
//{
n=f_cur.Read(buf,l_leng);
pbuf=buf;
pbuf=des.yencrypt(key,pbuf,n);
//buf[0]=GetSub(buf[0]);
for(int i=0;i<n;i++)
{
buf[i]=*(pbuf+i);
}
f_enc.Write(buf,n);
//}
return 1;
}
void CDesDialog::OnEnChangeEdit()
{
// TODO: 如果该控件是 RICHEDIT 控件,则它将不会
// 发送该通知,除非重写 CDialog::OnInitDialog()
// 函数并调用 CRichEditCtrl().SetEventMask(),
// 同时将 ENM_CHANGE 标志“或”运算到掩码中。
UpdateData();
str_key=str_input;
UpdateData();
// TODO: 在此添加控件通知处理程序代码
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -