📄 chapter2_2dlg.cpp
字号:
// chapter2_2Dlg.cpp : implementation file
//
#include "stdafx.h"
#include "chapter2_2.h"
#include "chapter2_2Dlg.h"
#include "STPasswordManager.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CChapter2_2Dlg dialog
CChapter2_2Dlg::CChapter2_2Dlg(CWnd* pParent /*=NULL*/)
: CDialog(CChapter2_2Dlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CChapter2_2Dlg)
m_strOldPassword = _T("");
m_bIsOldPasswordFound = FALSE;
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CChapter2_2Dlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CChapter2_2Dlg)
DDX_Text(pDX, IDC_PASSWORD, m_strOldPassword);
DDX_Check(pDX, IDC_PASSWORD_ACTIVE, m_bIsOldPasswordFound);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CChapter2_2Dlg, CDialog)
//{{AFX_MSG_MAP(CChapter2_2Dlg)
ON_BN_CLICKED(IDC_SET_PASSWORD, OnSetPassword)
ON_BN_CLICKED(IDC_READ_PASSWORD, OnReadPassword)
ON_BN_CLICKED(IDC_SET_ACTIVE, OnSetActive)
ON_BN_CLICKED(IDC_READ_ACTIVE, OnReadActive)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CChapter2_2Dlg message handlers
BOOL CChapter2_2Dlg::OnInitDialog()
{
CDialog::OnInitDialog();
// 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
CenterWindow(GetDesktopWindow()); // center to the hpc screen
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
}
void CChapter2_2Dlg::OnSetPassword()
{
UpdateData(TRUE);
CSTPasswordManager pm;
if (!m_bIsOldPasswordFound) {
::AfxMessageBox(_T("Current password was not found. Cannot change password without current password."));
} else {
BOOL bResult = pm.SetPassword(m_strOldPassword, m_strPassword);
if (!bResult) {
::AfxMessageBox(_T("Cannot change password"));
} else {
m_strOldPassword = m_strPassword;
}
}
}
void CChapter2_2Dlg::OnReadPassword()
{
CWaitCursor wc;
CSTPasswordManager pm;
for (int i1=0; i1<9; i1++) {
for (int i2=0; i2<9; i2++) {
for (int i3=0; i3<9; i3++) {
for (int i4=0; i4<9; i4++) {
CString strTestPassword;
strTestPassword.Format(_T("%d%d%d%d"), i1, i2, i3, i4);
if (pm.CheckPassword(strTestPassword)) {
m_strPassword = strTestPassword;
m_strOldPassword = strTestPassword;
m_bIsOldPasswordFound = TRUE;
UpdateData(FALSE);
return;
}
} } } }
CString strTestPassword = _T("");
if (pm.CheckPassword(strTestPassword)) {
m_strPassword = strTestPassword;
m_strOldPassword = strTestPassword;
UpdateData(FALSE);
m_bIsOldPasswordFound = TRUE;
return;
}
m_strPassword = _T("- Unknown password - ");
m_strOldPassword = _T("");
UpdateData(FALSE);
}
void CChapter2_2Dlg::OnSetActive()
{
UpdateData(TRUE);
CSTPasswordManager pm;
if (!m_bIsOldPasswordFound) {
::AfxMessageBox(_T("Current password was not found. Cannot change active flag without current password."));
} else {
BOOL bResult = pm.SetPasswordActive(m_strOldPassword, m_bPasswordActive);
if (!bResult) {
::AfxMessageBox(_T("Cannot change active flag"));
}
}
}
void CChapter2_2Dlg::OnReadActive()
{
CSTPasswordManager pm;
m_bPasswordActive = pm.GetPasswordActive();
UpdateData(FALSE);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -