📄 filedigestdlg.cpp
字号:
// FileDigestDlg.cpp : implementation file
//
#include "stdafx.h"
#include "FileDigest.h"
#include "FileDigestDlg.h"
#include "TransparentBitmap.h"
#include <shlwapi.h>
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
CString g_oStrInfo = _T("INFO");
CString g_oStrSuccess = _T("SUCCESS");
CString g_oStrFailure = _T("FAILURE");
CString g_oStrError = _T("ERROR");
//Error Beep Signal
void ErrorBeep()
{
//MessageBeep(MB_OK); //asynchronous
MessageBeep(0xFFFFFFFF); //asynchronous
}
//Optimized Function to convert an unsigned char to a Hex string of length 2
void Char2Hex(unsigned char ch, char* szHex)
{
static unsigned char saucHex[] = "0123456789ABCDEF";
szHex[0] = saucHex[ch >> 4];
szHex[1] = saucHex[ch&0xF];
szHex[2] = 0;
}
//Function to convert a Hex string of length 2 to an unsigned char
bool Hex2Char(char const* szHex, unsigned char& rch)
{
if(*szHex >= '0' && *szHex <= '9')
rch = *szHex - '0';
else if(*szHex >= 'A' && *szHex <= 'F')
rch = *szHex - 55; //-'A' + 10
else
//Is not really a Hex string
return false;
szHex++;
if(*szHex >= '0' && *szHex <= '9')
(rch <<= 4) += *szHex - '0';
else if(*szHex >= 'A' && *szHex <= 'F')
(rch <<= 4) += *szHex - 55; //-'A' + 10;
else
//Is not really a Hex string
return false;
return true;
}
//Function to convert binary string to hex string
void Binary2Hex(unsigned char const* pucBinStr, int iBinSize, char* pszHexStr)
{
int i;
char szHex[3];
unsigned char const* pucBinStr1 = pucBinStr;
*pszHexStr = 0;
for(i=0; i<iBinSize; i++,pucBinStr1++)
{
Char2Hex(*pucBinStr1, szHex);
strcat(pszHexStr, szHex);
}
}
//Function to convert hex string to binary string
bool Hex2Binary(char const* pszHexStr, unsigned char* pucBinStr, int iBinSize)
{
int i;
unsigned char ch;
for(i=0; i<iBinSize; i++,pszHexStr+=2,pucBinStr++)
{
if(false == Hex2Char(pszHexStr, ch))
return false;
*pucBinStr = ch;
}
return true;
}
/////////////////////////////////////////////////////////////////////////////
// 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()
/////////////////////////////////////////////////////////////////////////////
// CFileDigestDlg dialog
CFileDigestDlg::CFileDigestDlg(CWnd* pParent /*=NULL*/)
: CDialog(CFileDigestDlg::IDD, pParent), m_iMode(FILE), m_iMethod(MD128),
m_oRIPEMD128(CRIPEMD::RIPEMD128), m_oRIPEMD160(CRIPEMD::RIPEMD160),
m_oSHA160(CSHA::SHA160), m_oSHA256(CSHA::SHA256), m_oSHA384(CSHA::SHA384),
m_oSHA512(CSHA::SHA512),
m_oPlainFrg(RGB(190,0,0)), m_oPlainBg(RGB(200,255,200)), m_oPlainBg1(RGB(150,200,150)),
m_oDigFrg(RGB(0,130,0)), m_oDigBg(RGB(200,200,255)), m_oDigBg1(RGB(150,150,200)),
//FILE
m_oEditFile(m_oPlainFrg, m_oPlainBg),
//DIGEST
m_oEditStr1(m_oDigFrg, m_oDigBg), m_oEditHex1(m_oDigFrg, m_oDigBg),
//STRING
m_oEditAlpha(m_oPlainFrg, m_oPlainBg), m_oEditHex(m_oPlainFrg, m_oPlainBg1),
//DIGEST
m_oEditStr2(m_oDigFrg, m_oDigBg), m_oEditHex2(m_oDigFrg, m_oDigBg)
{
//{{AFX_DATA_INIT(CFileDigestDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CFileDigestDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CFileDigestDlg)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CFileDigestDlg, CDialog)
//{{AFX_MSG_MAP(CFileDigestDlg)
ON_MESSAGE_VOID(WM_KICKIDLE, OnKickIdle)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_WM_CLOSE()
ON_BN_CLICKED(IDC_RADSTR, OnRadstr)
ON_BN_CLICKED(IDC_RADFILE, OnRadfile)
ON_COMMAND(IDM_EXIT, OnExit)
ON_COMMAND(IDM_HELP, OnHelp)
ON_BN_CLICKED(IDC_BTNFILE, OnBtnfile)
ON_BN_CLICKED(IDC_BTNFILEDIGEST, OnBtnfiledigest)
ON_BN_CLICKED(IDC_BTNLOAD, OnBtnload)
ON_BN_CLICKED(IDC_BTNSAVEAS, OnBtnsaveas)
ON_BN_CLICKED(IDC_BTNCHECK, OnBtncheck)
ON_BN_CLICKED(IDC_RADALPHA, OnRadalpha)
ON_BN_CLICKED(IDC_RADHEX, OnRadhex)
ON_BN_CLICKED(IDC_BTNSTRINGDIGEST, OnBtnstringdigest)
ON_UPDATE_COMMAND_UI(IDC_BTNCHECK, OnUpdateBtnCheck)
ON_UPDATE_COMMAND_UI(IDC_BTNFILEDIGEST, OnUpdateBtnFileDigest)
ON_UPDATE_COMMAND_UI(IDC_BTNSAVEAS, OnUpdateBtnSave)
ON_CBN_SELCHANGE(IDC_COMBOMETHODS, OnSelchangeCombomethods)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CFileDigestDlg message handlers
void CFileDigestDlg::OnKickIdle()
{
//Call this member function to update the state of dialog buttons and other controls
//in a dialog box or window that uses the ON_UPDATE_COMMAND_UI callback mechanism
UpdateDialogControls( this, FALSE );
}
void CFileDigestDlg::OnUpdateBtnCheck(CCmdUI* pCmdUI)
{
CEdit* poEdit1 = static_cast<CEdit*>(GetDlgItem(IDC_EDITFILE));
CEdit* poEdit2 = static_cast<CEdit*>(GetDlgItem(IDC_EDITHEX1));
pCmdUI->Enable((poEdit1->GetWindowTextLength()>0) && (poEdit2->GetWindowTextLength()>0));
}
void CFileDigestDlg::OnUpdateBtnFileDigest(CCmdUI* pCmdUI)
{
CEdit* poEdit = static_cast<CEdit*>(GetDlgItem(IDC_EDITFILE));
pCmdUI->Enable(poEdit->GetWindowTextLength()>0);
}
void CFileDigestDlg::OnUpdateBtnSave(CCmdUI* pCmdUI)
{
CEdit* poEdit = static_cast<CEdit*>(GetDlgItem(IDC_EDITHEX1));
pCmdUI->Enable(poEdit->GetWindowTextLength()>0);
}
BOOL CFileDigestDlg::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);
}
}
//Setting Application's Menu
m_oMenu.LoadMenu(IDR_MENU);
SetMenu(&m_oMenu);
// 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
//Subclassing
m_oComboMethods.SubclassDlgItem(IDC_COMBOMETHODS, this);
m_oRadFile.SubclassDlgItem(IDC_RADFILE, this);
m_oRadStr.SubclassDlgItem(IDC_RADSTR, this);
m_oEditFile.SubclassDlgItem(IDC_EDITFILE, this);
m_oBtnFile.SubclassDlgItem(IDC_BTNFILE, this);
m_oBtnCheck.SubclassDlgItem(IDC_BTNCHECK, this);
m_oBtnFileDigest.SubclassDlgItem(IDC_BTNFILEDIGEST, this);
m_oEditStr1.SubclassDlgItem(IDC_EDITSTR1, this);
m_oBtnLoad.SubclassDlgItem(IDC_BTNLOAD, this);
m_oBtnSaveAs.SubclassDlgItem(IDC_BTNSAVEAS, this);
m_oEditHex1.SubclassDlgItem(IDC_EDITHEX1, this);
m_oEditAlpha.SubclassDlgItem(IDC_EDITALPHA, this);
m_oRadAlpha.SubclassDlgItem(IDC_RADALPHA, this);
m_oEditHex.SubclassDlgItem(IDC_EDITHEX, this);
m_oRadHex.SubclassDlgItem(IDC_RADHEX, this);
m_oBtnStringDigest.SubclassDlgItem(IDC_BTNSTRINGDIGEST, this);
m_oEditStr2.SubclassDlgItem(IDC_EDITSTR2, this);
m_oEditHex2.SubclassDlgItem(IDC_EDITHEX2, this);
//
//Create the ToolTip Control
if(!m_oToolTipCtrl.Create(this))
{
TRACE("\nUnable to create ToolTip control");
}
else
{
m_oToolTipCtrl.AddTool(&m_oComboMethods, IDS_COMBOMETHODS);
m_oToolTipCtrl.AddTool(&m_oRadFile, IDS_RADFILE);
m_oToolTipCtrl.AddTool(&m_oRadStr, IDS_RADSTR);
m_oToolTipCtrl.AddTool(&m_oEditFile, IDS_EDITFILE);
m_oToolTipCtrl.AddTool(&m_oBtnFile, IDS_BTNFILE);
m_oToolTipCtrl.AddTool(&m_oBtnCheck, IDS_BTNCHECK);
m_oToolTipCtrl.AddTool(&m_oBtnFileDigest, IDS_BTNFILEDIGEST);
m_oToolTipCtrl.AddTool(&m_oEditStr1, IDS_EDITSTR1);
m_oToolTipCtrl.AddTool(&m_oBtnLoad, IDS_BTNLOAD);
m_oToolTipCtrl.AddTool(&m_oBtnSaveAs, IDS_BTNSAVEAS);
m_oToolTipCtrl.AddTool(&m_oEditHex1, IDS_EDITHEX1);
m_oToolTipCtrl.AddTool(&m_oEditAlpha, IDS_EDITALPHA);
m_oToolTipCtrl.AddTool(&m_oRadAlpha, IDS_RADALPHA);
m_oToolTipCtrl.AddTool(&m_oEditHex, IDS_EDITHEX);
m_oToolTipCtrl.AddTool(&m_oRadHex, IDS_RADHEX);
m_oToolTipCtrl.AddTool(&m_oBtnStringDigest, IDS_BTNSTRINGDIGEST);
m_oToolTipCtrl.AddTool(&m_oEditStr2, IDS_EDITSTR2);
m_oToolTipCtrl.AddTool(&m_oEditHex2, IDS_EDITHEX2);
//
m_oToolTipCtrl.Activate(TRUE);
}
//
//Moving the Controls
MoveStringGroup();
MoveFileGroup();
//
CRect oRect, oRectDlg;
CWnd* poWnd = GetDlgItem(IDC_EDITHEX1);
poWnd->GetWindowRect(&oRect);
GetWindowRect(&oRectDlg);
SetWindowPos(NULL, 0, 0, oRectDlg.Width(), oRect.bottom-oRectDlg.top+15, SWP_NOMOVE|SWP_NOZORDER);
//Initialize Radio Buttons
CButton* poButton;
poButton = reinterpret_cast<CButton*>(GetDlgItem(IDC_RADFILE));
poButton->SetCheck(1);
poButton = reinterpret_cast<CButton*>(GetDlgItem(IDC_RADALPHA));
poButton->SetCheck(1);
//Initialize Methods Combo Box
CComboBox* poComboBox;
poComboBox = static_cast<CComboBox*>(GetDlgItem(IDC_COMBOMETHODS));
poComboBox->SetCurSel(0);
//Initialize the Transparent Bitmaps
m_oBMP.LoadBitmap(IDB_BMPARROWDOWN);
m_oTransparentBitmap1.SubclassDlgItem(IDC_STATICBMPARROW1, this);
m_oTransparentBitmap1.Initialize(HBITMAP(m_oBMP), RGB(255,255,255), 1.0, 1.0);
m_oTransparentBitmap2.SubclassDlgItem(IDC_STATICBMPARROW2, this);
m_oTransparentBitmap2.Initialize(HBITMAP(m_oBMP), RGB(255,255,255), 1.0, 1.0);
//
return TRUE; // return TRUE unless you set the focus to a control
}
void CFileDigestDlg::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 CFileDigestDlg::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);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -