📄 mymd5dlg.cpp
字号:
// MyMD5Dlg.cpp : implementation file
//
#include "stdafx.h"
#include "MyMD5.h"
#include "MyMD5Dlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMyMD5Dlg dialog
CMyMD5Dlg::CMyMD5Dlg(CWnd* pParent /*=NULL*/)
: CDialog(CMyMD5Dlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CMyMD5Dlg)
m_Efile = _T("");
m_Re1 = _T("");
m_Re2 = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CMyMD5Dlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CMyMD5Dlg)
DDX_Text(pDX, IDC_EFile, m_Efile);
DDX_Text(pDX, IDC_ERe1, m_Re1);
DDX_Text(pDX, IDC_ERe2, m_Re2);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CMyMD5Dlg, CDialog)
//{{AFX_MSG_MAP(CMyMD5Dlg)
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_SelectFile, OnSelectFile)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMyMD5Dlg message handlers
BOOL CMyMD5Dlg::OnInitDialog()
{
CDialog::OnInitDialog();
Num=0;
// 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
}
// 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 CMyMD5Dlg::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 CMyMD5Dlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CMyMD5Dlg::OnSelectFile()
{
char szFilter[] = "选择文件(*.*)|*.*||";
CFileDialog file(TRUE,NULL,NULL,NULL,szFilter,this);
file.DoModal();
CString fileName;
fileName=file.GetPathName();
m_Efile=fileName;
if(Num==0){
m_Re1="";
m_Re2="";
}
UpdateData(FALSE);
CFile fp;
if(!fp.Open(fileName,CFile::modeRead)){
AfxMessageBox("不可对其读");
return;}
DWORD len=fp.GetLength();
BYTE *ptr=new BYTE[len];
if(!ptr){
AfxMessageBox("内存不够!");
fp.Close();
return;
}
DWORD l1=fp.ReadHuge(ptr,len);
fp.Close();
unsigned char digest[16];
char out[80];
DWORD state[4];
myMd5.MessageDigest(ptr,len,digest);
memcpy(state,digest,16);
sprintf(out,"a=0x%x,b=0x%x,c=0x%x,d=0x%x",state[0],state[1],state[2],state[3]);
if(Num==0){
m_Re1=out;
Num++; }
else
{ m_Re2=out;
Num=0; }
UpdateData(FALSE);
delete []ptr;
}
void CMyMD5Dlg::HexToChar(char *in, int len, char *out)
{
char x=0;
for(int i=0;i<len;i++){
x=(char)(in[i]&0x0f);
if(x>9)x=(char)('A'+x-10);
else x='0'+x;
out[2*i]=x;
x=in[i]&0xf0;
x=x>>4;
if(x>9)x='A'+x-10;
else x='0'+x;
out[2*i+1]=x;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -