MFC 简单的MD5计算器
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? MFC 簡單的MD5計算器
一、簡述
? ? ? ? 記--使用開源MD5計算代碼+MFC實現簡單的文件MD5計算器。
????????1、支持拖拽文件或目錄。
????????2、支持拖拽多個文件或目錄。
????????3、支持比較兩個MD5值,不一致時指出第幾個字符不一致。
????????4、支持輸出文件全路徑或僅文件名。
????????5、支持輸出文件大小。
????????6、支持指定文件后綴。
例子打包:外鏈:https://wwi.lanzouq.com/b0c9zap6d?密碼:d49u
C語言開源MD5代碼:https://github.com/chinaran/Compute-file-or-string-md5
二、效果
??
三、代碼工程
四、源文件
MD5CalculatorDlg.h文件
// MD5CalculatorDlg.h : 頭文件 //#pragma once #include "afxwin.h"# #define FILE_EXTENSION_MAX_LEN 6 //限制文件后綴長度typedef struct {int isFullPath;//標識是否是全路徑,1:全路徑;0:僅文件名int isOutPutFileSize;//標識是否需要輸出文件大小 1:輸出,0:不輸出CString fileExtension;//文件后綴 } OutputParam_t;// CMD5CalculatorDlg 對話框 class CMD5CalculatorDlg : public CDialogEx { // 構造 public:CMD5CalculatorDlg(CWnd* pParent = NULL); // 標準構造函數// 對話框數據 #ifdef AFX_DESIGN_TIMEenum { IDD = IDD_MD5CALCULATOR_DIALOG }; #endifprotected:virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持 private:int ProcessOneFile(OutputParam_t &outputParam, int &index, const char* filePath, int filePathLen, CString &resultStr);void ProcessDir(OutputParam_t &outputParam, int &index, CString path, CString &resultStr);void GetOutputParam(OutputParam_t &outputParam);// 實現 protected:HICON m_hIcon;void OnOK();// 生成的消息映射函數virtual BOOL OnInitDialog();afx_msg void OnSysCommand(UINT nID, LPARAM lParam);afx_msg void OnPaint();afx_msg HCURSOR OnQueryDragIcon();DECLARE_MESSAGE_MAP() public:CString mEditMD5Str;//MD5值CString mEditMD5ResultStr;//MD5計算結果CButton mCheckIsFullPath;//是否顯示文件全路徑CString mEditFileExtensionStr;//文件后綴,當為空時全部符合CButton mCheckOutPutFileSize;//結果中是否輸出文件大小CString mEditCompareMD5Str;//要對比的MD5值CButton mBtnCompareMD5;//比較按鈕afx_msg void OnBnClickedButtonCopymd5(); afx_msg void OnDropFiles(HDROP hDropInfo); afx_msg void OnBnClickedButtonComparemd5(); };MD5CalculatorDlg.cpp文件
#define _CRT_SECURE_NO_WARNINGS //去除安全警告 // MD5CalculatorDlg.cpp : 實現文件 //#include "stdafx.h" #include "MD5Calculator.h" #include "MD5CalculatorDlg.h" #include "afxdialogex.h" #include "common.h"#ifdef _DEBUG #define new DEBUG_NEW #endif//使用說明信息 #define USEAGE_INFO _T("1、拖拽文件或目錄到該窗口內,即可計算MD5值。\r\n" \"2、支持拖拽多個文件或目錄。\r\n"\"3、可比較兩個MD5值,區分大小寫。\r\n"\"4、勾選\"文件名全路徑\"則輸出文件全路徑。\r\n"\"5、勾選\"文件大小\"則輸出文件大小。\r\n"\"6、可指定要計算MD5的文件后綴,未指定則無限制。")// 用于應用程序“關于”菜單項的 CAboutDlg 對話框class CAboutDlg : public CDialogEx { public:CAboutDlg();// 對話框數據 #ifdef AFX_DESIGN_TIMEenum { IDD = IDD_ABOUTBOX }; #endifprotected:virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持// 實現 protected:DECLARE_MESSAGE_MAP() };CAboutDlg::CAboutDlg() : CDialogEx(IDD_ABOUTBOX) { }void CAboutDlg::DoDataExchange(CDataExchange* pDX) {CDialogEx::DoDataExchange(pDX); }BEGIN_MESSAGE_MAP(CAboutDlg, CDialogEx) END_MESSAGE_MAP()// CMD5CalculatorDlg 對話框CMD5CalculatorDlg::CMD5CalculatorDlg(CWnd* pParent /*=NULL*/): CDialogEx(IDD_MD5CALCULATOR_DIALOG, pParent), mEditMD5Str(_T("")), mEditMD5ResultStr(_T("")), mEditFileExtensionStr(_T("")), mEditCompareMD5Str(_T("")) {m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); }void CMD5CalculatorDlg::DoDataExchange(CDataExchange* pDX) {CDialogEx::DoDataExchange(pDX);DDX_Text(pDX, IDC_EDIT_MD5, mEditMD5Str);DDV_MaxChars(pDX, mEditMD5Str, MD5_MAX_LEN);DDX_Text(pDX, IDC_EDIT_Result, mEditMD5ResultStr);DDX_Control(pDX, IDC_CHECK_FullPath, mCheckIsFullPath);DDX_Text(pDX, IDC_EDIT_FileExtension, mEditFileExtensionStr);DDV_MaxChars(pDX, mEditFileExtensionStr, FILE_EXTENSION_MAX_LEN);DDX_Control(pDX, IDC_CHECK_OutPutFileSize, mCheckOutPutFileSize);DDX_Text(pDX, IDC_EDIT_CompareMD5, mEditCompareMD5Str);DDV_MaxChars(pDX, mEditCompareMD5Str, MD5_MAX_LEN);DDX_Control(pDX, IDC_BUTTON_CompareMD5, mBtnCompareMD5); }BEGIN_MESSAGE_MAP(CMD5CalculatorDlg, CDialogEx)ON_WM_SYSCOMMAND()ON_WM_PAINT()ON_WM_QUERYDRAGICON()ON_BN_CLICKED(IDC_BUTTON_CopyMD5, &CMD5CalculatorDlg::OnBnClickedButtonCopymd5)ON_WM_DROPFILES()ON_BN_CLICKED(IDC_BUTTON_CompareMD5, &CMD5CalculatorDlg::OnBnClickedButtonComparemd5) END_MESSAGE_MAP()// CMD5CalculatorDlg 消息處理程序//重載回車,不然會退出 void CMD5CalculatorDlg::OnOK() {// TODO: 在此添加專用代碼和/或調用基類//CDialogEx::OnOK(); }BOOL CMD5CalculatorDlg::OnInitDialog() {CDialogEx::OnInitDialog();// 將“關于...”菜單項添加到系統菜單中。// IDM_ABOUTBOX 必須在系統命令范圍內。ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);ASSERT(IDM_ABOUTBOX < 0xF000);CMenu* pSysMenu = GetSystemMenu(FALSE);if (pSysMenu != NULL){BOOL bNameValid;CString strAboutMenu;bNameValid = strAboutMenu.LoadString(IDS_ABOUTBOX);ASSERT(bNameValid);if (!strAboutMenu.IsEmpty()){pSysMenu->AppendMenu(MF_SEPARATOR);pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);}}// 設置此對話框的圖標。 當應用程序主窗口不是對話框時,框架將自動// 執行此操作SetIcon(m_hIcon, TRUE); // 設置大圖標SetIcon(m_hIcon, FALSE); // 設置小圖標// TODO: 在此添加額外的初始化代碼mEditMD5ResultStr = USEAGE_INFO;UpdateData(false);//SetWindowPos(NULL, 0, 0, 586, 380, SWP_NOMOVE);//設置窗口寬高但不移動位置return TRUE; // 除非將焦點設置到控件,否則返回 TRUE }void CMD5CalculatorDlg::OnSysCommand(UINT nID, LPARAM lParam) {if ((nID & 0xFFF0) == IDM_ABOUTBOX){CAboutDlg dlgAbout;dlgAbout.DoModal();}else{CDialogEx::OnSysCommand(nID, lParam);} }// 如果向對話框添加最小化按鈕,則需要下面的代碼 // 來繪制該圖標。 對于使用文檔/視圖模型的 MFC 應用程序, // 這將由框架自動完成。void CMD5CalculatorDlg::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{CDialogEx::OnPaint();} }//當用戶拖動最小化窗口時系統調用此函數取得光標 //顯示。 HCURSOR CMD5CalculatorDlg::OnQueryDragIcon() {return static_cast<HCURSOR>(m_hIcon); }//復制MD5值到粘貼板 void CMD5CalculatorDlg::OnBnClickedButtonCopymd5() {// TODO: 在此添加控件通知處理程序代碼if (OpenClipboard()){UpdateData(true);HGLOBAL clipbuffer;char* buffer = NULL;EmptyClipboard();clipbuffer = GlobalAlloc(GMEM_DDESHARE, mEditMD5Str.GetLength() + 1);buffer = (char*)GlobalLock(clipbuffer);strcpy_s(buffer, mEditMD5Str.GetLength() + 1, (LPSTR)(LPCTSTR)mEditMD5Str);GlobalUnlock(clipbuffer);SetClipboardData(CF_TEXT, clipbuffer);CloseClipboard();} }//處理拖拽文件 void CMD5CalculatorDlg::OnDropFiles(HDROP hDropInfo) {// TODO: 在此添加消息處理程序代碼和/或調用默認值UINT count;int pathLen;TCHAR filePath[MAX_PATH];CString resultStr = "";int fileIndex = 1;OutputParam_t outputParam = { 0 };GetOutputParam(outputParam);count = DragQueryFile(hDropInfo, 0xFFFFFFFF, NULL, 0);//從成功的拖放操作中檢索文件的名稱。并取代被拖拽文件的數目for (UINT i = 0; i < count; i++) {memset(filePath, 0x0, sizeof(filePath));pathLen = DragQueryFile(hDropInfo, i, filePath, sizeof(filePath));//TRACE(_T("i:%d, filePath:%s\n"), i, filePath); if (!IsDir(filePath)) {if (YES == ProcessOneFile(outputParam, fileIndex, filePath, pathLen, resultStr)) {fileIndex++;} } else {//遞歸目錄ProcessDir(outputParam, fileIndex, CString(filePath), resultStr);}}mEditMD5ResultStr = resultStr;UpdateData(false);//將關聯變量值更新到控件CDialogEx::OnDropFiles(hDropInfo); }//處理一個文件的MD5值 int CMD5CalculatorDlg::ProcessOneFile(OutputParam_t &outputParam, int &index, const char *filePath, int filePathLen, CString & resultStr) {char md5[MD5_MAX_LEN] = { 0 };CString fileExtension = GetFileExtension(CString(filePath));if (!outputParam.fileExtension.IsEmpty()&& 0 != outputParam.fileExtension.CompareNoCase(fileExtension)) {//不是指定的后綴直接返回return NO;}CFileStatus fileStatus = {0};if (YES == outputParam.isOutPutFileSize) {if (CFile::GetStatus(filePath, fileStatus)) {;//OK}}GetFileMD5(filePath, md5, sizeof(md5));if (YES == outputParam.isFullPath) {//全路徑resultStr.AppendFormat(_T("[%d] MD5:%s; FILE:%s"),index, md5, filePath);} else { resultStr.AppendFormat(_T("[%d] MD5:%s; FILE:%s"),index, md5, GetFileName(filePath, filePathLen));}if (YES == outputParam.isOutPutFileSize) {resultStr.AppendFormat(_T("; SIZE:%llu"), fileStatus.m_size);}resultStr.AppendFormat(_T("\r\n"));mEditCompareMD5Str = mEditMD5Str;mEditMD5Str = CString(md5); return YES; }//遞歸處理目錄 void CMD5CalculatorDlg::ProcessDir(OutputParam_t &outputParam, int &index, CString path, CString &resultStr) {LPTSTR lpszPath = new TCHAR[path.GetLength() + 1];_tcscpy(lpszPath, path);if (!IsDir(lpszPath)) {return;}// 查找當前路徑下的所有文件夾和文件CString strDir = path + _T("\\*.*");;CString strFullPath;//CString strFileName;// 遍歷得到所有子文件夾名CFileFind finder;BOOL bWorking = finder.FindFile(strDir);while (bWorking) {bWorking = finder.FindNextFile();if (0 == finder.GetFileName().Compare(".")|| 0 == finder.GetFileName().Compare("..")) {//排除“.”“..”,當前目錄和上層目錄continue;}if (finder.IsDirectory() ) {//遞歸調用ProcessDir(outputParam, index, finder.GetFilePath(), resultStr);} else {strFullPath = finder.GetFilePath();//strFileName = finder.GetFileName();if (YES == ProcessOneFile(outputParam, index, (char*)(LPCTSTR)strFullPath, strFullPath.GetLength(), resultStr)) {index++;} }}finder.Close(); }//獲取輸出參數 void CMD5CalculatorDlg::GetOutputParam(OutputParam_t & outputParam) {UpdateData(true);//控件值更新到關聯變量outputParam.isFullPath = mCheckIsFullPath.GetCheck();outputParam.isOutPutFileSize = mCheckOutPutFileSize.GetCheck();outputParam.fileExtension = mEditFileExtensionStr; }//比較MD5值 void CMD5CalculatorDlg::OnBnClickedButtonComparemd5() {// TODO: 在此添加控件通知處理程序代碼UpdateData(true);if (mEditMD5Str.IsEmpty() && mEditCompareMD5Str.IsEmpty()) {return;}#if 0if (0 == mEditMD5Str.Compare(mEditCompareMD5Str)) {MessageBox(_T("MD5值一致!"), _T("比較結果"), MB_ICONASTERISK);} else {MessageBox(_T("MD5值不一致!"), _T("比較結果"), MB_ICONHAND);} #elseint i;int len1 = mEditMD5Str.GetLength();int len2 = mEditCompareMD5Str.GetLength();int minLen = (len1 < len2) ? len1 : len2;if (0 == minLen) {MessageBox(_T("MD5值不一致!\r\n其中一個為空!"), _T("比較結果"), MB_ICONHAND);return;}for (i = 0; i < minLen; ++i) {if (mEditMD5Str[i] != mEditCompareMD5Str[i]) {break;}}TCHAR tmp_buf[128] = { 0 };if (i == minLen) {if (len1 == len2) {MessageBox(_T("MD5值一致!"), _T("比較結果"), MB_ICONASTERISK);} else {snprintf(tmp_buf, sizeof(tmp_buf) - 1, \"MMD5值不一致!\r\n前面的%d個字符相同,但長度不等: '%d' != '%d'", minLen, len1, len2);MessageBox(_T(tmp_buf), _T("比較結果"), MB_ICONHAND);}} else { snprintf(tmp_buf, sizeof(tmp_buf) - 1, \"MD5值不一致!\r\n第%d個字符不一致: '%c' != '%c'", i + 1, mEditMD5Str[i], mEditCompareMD5Str[i]);MessageBox(_T(tmp_buf), _T("比較結果"), MB_ICONHAND);} #endif }md5.h文件
#pragma once #ifndef MD5_H #define MD5_Htypedef struct {unsigned int count[2];unsigned int state[4];unsigned char buffer[64]; } MD5_CTX;#define F(x,y,z) ((x & y) | (~x & z)) #define G(x,y,z) ((x & z) | (y & ~z)) #define H(x,y,z) (x^y^z) #define I(x,y,z) (y ^ (x | ~z)) #define ROTATE_LEFT(x,n) ((x << n) | (x >> (32-n)))#define FF(a,b,c,d,x,s,ac) \ { \a += F(b,c,d) + x + ac; \a = ROTATE_LEFT(a,s); \a += b; \ } #define GG(a,b,c,d,x,s,ac) \ { \a += G(b,c,d) + x + ac; \a = ROTATE_LEFT(a,s); \a += b; \ } #define HH(a,b,c,d,x,s,ac) \ { \a += H(b,c,d) + x + ac; \a = ROTATE_LEFT(a,s); \a += b; \ } #define II(a,b,c,d,x,s,ac) \ { \a += I(b,c,d) + x + ac; \a = ROTATE_LEFT(a,s); \a += b; \ } void MD5Init(MD5_CTX *context); void MD5Update(MD5_CTX *context, unsigned char *input, unsigned int inputlen); void MD5Final(MD5_CTX *context, unsigned char digest[16]); void MD5Transform(unsigned int state[4], unsigned char block[64]); void MD5Encode(unsigned char *output, unsigned int *input, unsigned int len); void MD5Decode(unsigned int *output, unsigned char *input, unsigned int len);#endifmd5.cpp文件
#include "stdafx.h" #include "md5.h" #include <memory.h>unsigned char PADDING[] = {0x80,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 };void MD5Init(MD5_CTX *context) {context->count[0] = 0;context->count[1] = 0;context->state[0] = 0x67452301;context->state[1] = 0xEFCDAB89;context->state[2] = 0x98BADCFE;context->state[3] = 0x10325476; }void MD5Update(MD5_CTX *context, unsigned char *input, unsigned int inputlen) {unsigned int i = 0;unsigned int index = 0;unsigned int partlen = 0;index = (context->count[0] >> 3) & 0x3F;partlen = 64 - index;context->count[0] += inputlen << 3;if (context->count[0] < (inputlen << 3))context->count[1]++;context->count[1] += inputlen >> 29;if (inputlen >= partlen){memcpy(&context->buffer[index], input, partlen);MD5Transform(context->state, context->buffer);for (i = partlen; i + 64 <= inputlen; i += 64)MD5Transform(context->state, &input[i]);index = 0;}else{i = 0;}memcpy(&context->buffer[index], &input[i], inputlen - i); }void MD5Final(MD5_CTX *context, unsigned char digest[16]) {unsigned int index = 0, padlen = 0;unsigned char bits[8];index = (context->count[0] >> 3) & 0x3F;padlen = (index < 56) ? (56 - index) : (120 - index);MD5Encode(bits, context->count, 8);MD5Update(context, PADDING, padlen);MD5Update(context, bits, 8);MD5Encode(digest, context->state, 16); }void MD5Encode(unsigned char *output, unsigned int *input, unsigned int len) {unsigned int i = 0;unsigned int j = 0;while (j < len){output[j] = input[i] & 0xFF;output[j + 1] = (input[i] >> 8) & 0xFF;output[j + 2] = (input[i] >> 16) & 0xFF;output[j + 3] = (input[i] >> 24) & 0xFF;i++;j += 4;} }void MD5Decode(unsigned int *output, unsigned char *input, unsigned int len) {unsigned int i = 0;unsigned int j = 0;while (j < len){output[i] = (input[j]) |(input[j + 1] << 8) |(input[j + 2] << 16) |(input[j + 3] << 24);i++;j += 4;} }void MD5Transform(unsigned int state[4], unsigned char block[64]) {unsigned int a = state[0];unsigned int b = state[1];unsigned int c = state[2];unsigned int d = state[3];unsigned int x[64];MD5Decode(x, block, 64);FF(a, b, c, d, x[0], 7, 0xd76aa478); /* 1 */FF(d, a, b, c, x[1], 12, 0xe8c7b756); /* 2 */FF(c, d, a, b, x[2], 17, 0x242070db); /* 3 */FF(b, c, d, a, x[3], 22, 0xc1bdceee); /* 4 */FF(a, b, c, d, x[4], 7, 0xf57c0faf); /* 5 */FF(d, a, b, c, x[5], 12, 0x4787c62a); /* 6 */FF(c, d, a, b, x[6], 17, 0xa8304613); /* 7 */FF(b, c, d, a, x[7], 22, 0xfd469501); /* 8 */FF(a, b, c, d, x[8], 7, 0x698098d8); /* 9 */FF(d, a, b, c, x[9], 12, 0x8b44f7af); /* 10 */FF(c, d, a, b, x[10], 17, 0xffff5bb1); /* 11 */FF(b, c, d, a, x[11], 22, 0x895cd7be); /* 12 */FF(a, b, c, d, x[12], 7, 0x6b901122); /* 13 */FF(d, a, b, c, x[13], 12, 0xfd987193); /* 14 */FF(c, d, a, b, x[14], 17, 0xa679438e); /* 15 */FF(b, c, d, a, x[15], 22, 0x49b40821); /* 16 *//* Round 2 */GG(a, b, c, d, x[1], 5, 0xf61e2562); /* 17 */GG(d, a, b, c, x[6], 9, 0xc040b340); /* 18 */GG(c, d, a, b, x[11], 14, 0x265e5a51); /* 19 */GG(b, c, d, a, x[0], 20, 0xe9b6c7aa); /* 20 */GG(a, b, c, d, x[5], 5, 0xd62f105d); /* 21 */GG(d, a, b, c, x[10], 9, 0x2441453); /* 22 */GG(c, d, a, b, x[15], 14, 0xd8a1e681); /* 23 */GG(b, c, d, a, x[4], 20, 0xe7d3fbc8); /* 24 */GG(a, b, c, d, x[9], 5, 0x21e1cde6); /* 25 */GG(d, a, b, c, x[14], 9, 0xc33707d6); /* 26 */GG(c, d, a, b, x[3], 14, 0xf4d50d87); /* 27 */GG(b, c, d, a, x[8], 20, 0x455a14ed); /* 28 */GG(a, b, c, d, x[13], 5, 0xa9e3e905); /* 29 */GG(d, a, b, c, x[2], 9, 0xfcefa3f8); /* 30 */GG(c, d, a, b, x[7], 14, 0x676f02d9); /* 31 */GG(b, c, d, a, x[12], 20, 0x8d2a4c8a); /* 32 *//* Round 3 */HH(a, b, c, d, x[5], 4, 0xfffa3942); /* 33 */HH(d, a, b, c, x[8], 11, 0x8771f681); /* 34 */HH(c, d, a, b, x[11], 16, 0x6d9d6122); /* 35 */HH(b, c, d, a, x[14], 23, 0xfde5380c); /* 36 */HH(a, b, c, d, x[1], 4, 0xa4beea44); /* 37 */HH(d, a, b, c, x[4], 11, 0x4bdecfa9); /* 38 */HH(c, d, a, b, x[7], 16, 0xf6bb4b60); /* 39 */HH(b, c, d, a, x[10], 23, 0xbebfbc70); /* 40 */HH(a, b, c, d, x[13], 4, 0x289b7ec6); /* 41 */HH(d, a, b, c, x[0], 11, 0xeaa127fa); /* 42 */HH(c, d, a, b, x[3], 16, 0xd4ef3085); /* 43 */HH(b, c, d, a, x[6], 23, 0x4881d05); /* 44 */HH(a, b, c, d, x[9], 4, 0xd9d4d039); /* 45 */HH(d, a, b, c, x[12], 11, 0xe6db99e5); /* 46 */HH(c, d, a, b, x[15], 16, 0x1fa27cf8); /* 47 */HH(b, c, d, a, x[2], 23, 0xc4ac5665); /* 48 *//* Round 4 */II(a, b, c, d, x[0], 6, 0xf4292244); /* 49 */II(d, a, b, c, x[7], 10, 0x432aff97); /* 50 */II(c, d, a, b, x[14], 15, 0xab9423a7); /* 51 */II(b, c, d, a, x[5], 21, 0xfc93a039); /* 52 */II(a, b, c, d, x[12], 6, 0x655b59c3); /* 53 */II(d, a, b, c, x[3], 10, 0x8f0ccc92); /* 54 */II(c, d, a, b, x[10], 15, 0xffeff47d); /* 55 */II(b, c, d, a, x[1], 21, 0x85845dd1); /* 56 */II(a, b, c, d, x[8], 6, 0x6fa87e4f); /* 57 */II(d, a, b, c, x[15], 10, 0xfe2ce6e0); /* 58 */II(c, d, a, b, x[6], 15, 0xa3014314); /* 59 */II(b, c, d, a, x[13], 21, 0x4e0811a1); /* 60 */II(a, b, c, d, x[4], 6, 0xf7537e82); /* 61 */II(d, a, b, c, x[11], 10, 0xbd3af235); /* 62 */II(c, d, a, b, x[2], 15, 0x2ad7d2bb); /* 63 */II(b, c, d, a, x[9], 21, 0xeb86d391); /* 64 */state[0] += a;state[1] += b;state[2] += c;state[3] += d; }五、總結
5.1?文件拖拽
? ? 添加ON_WM_DROPFILES消息處理:OnDropFiles()
?? ?窗口Accept file屬性設置為true
5.2?窗口屏蔽回車關閉(默認在窗口、Edit控件按回車回關閉窗口)
?? ?edit、wantreturn屬性設置為true
?? ?重寫窗口onOK處理?
?
5.3 復制內容到粘貼板,
CString MD5String = "abc123";if (OpenClipboard()){UpdateData(true);HGLOBAL clipbuffer;char* buffer = NULL;EmptyClipboard();clipbuffer = GlobalAlloc(GMEM_DDESHARE, MD5String.GetLength() + 1);buffer = (char*)GlobalLock(clipbuffer);strcpy_s(buffer, MD5String.GetLength() + 1, (LPSTR)(LPCTSTR)MD5String);GlobalUnlock(clipbuffer);SetClipboardData(CF_TEXT, clipbuffer);CloseClipboard();}粘貼出來只有一個字節時可右鍵項目--屬性--設置字符集為使用多字節字符集
5.4 獲取/設置控件位置
//獲取相對于父窗口位置 CRect rect; GetDlgItem(IDC_STATIC_FileType)->GetWindowRect(&rect); ScreenToClient(&rect);//轉換為相對于父窗口的位置 int x = rect.left; int y = rect.top;//設置子控件的位置(相對于父窗口位置)//將文件后綴移動臺"復制MD5值"右邊 IDC_STATIC_FileType是控件IDGetDlgItem(IDC_STATIC_FileType)->SetWindowPos(NULL, 440, 23, 0, 0, SWP_NOZORDER | SWP_NOSIZE);GetDlgItem(IDC_EDIT_FileExtension)->SetWindowPos(NULL, 512, 18, 0, 0, SWP_NOZORDER | SWP_NOSIZE);//設置主窗口大小但不移動位置 SetWindowPos(NULL, 0, 0, 586, 380, SWP_NOMOVE);//設置窗口寬高但不移動位置SWP_NOMOVE:忽略x、y,維持位置不變; SWP_NOSIZE:忽略cx、cy,維持大小不變;==============================修改版==============================
例子打包:外鏈:https://wwi.lanzouq.com/b0c9zap6d?密碼:d49u
修改點:
1、默認不清空結果,方便比較多個文件的md5值。
2、結果信息輸出后自動滾動到底部,方便查看最新的文件MD5及文件個數。
3、將文件后綴設置移到右邊隱藏區,放大窗口可見。
?
總結
以上是生活随笔為你收集整理的MFC 简单的MD5计算器的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: LE5010蓝牙芯片(凌思微)开发总结
- 下一篇: 贝叶斯滤波和贝叶斯平滑(Kalman滤波