|
// StoragePropertiesDialog.cpp : implementation file
//
#include "stdafx.h"
#include "exile.h"
#include "StoragePropertiesDialog.h"
#include "predefined.h"
#include "security.h"
#include "messagebox.h"
#include "PasswordGeneratorDialog.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CStoragePropertiesDialog dialog
CStoragePropertiesDialog::CStoragePropertiesDialog(CWnd* pParent /*=NULL*/)
: CDialog(CStoragePropertiesDialog::IDD, pParent)
{
//{{AFX_DATA_INIT(CStoragePropertiesDialog)
m_strMasterPassword = _T("");
m_strUserName = _T("");
m_nRounds = 0;
//}}AFX_DATA_INIT
m_bPassword = FALSE;
}
CStoragePropertiesDialog::~CStoragePropertiesDialog()
{
CleanString(m_strMasterPassword);
CleanString(m_strUserName);
}
void CStoragePropertiesDialog::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CStoragePropertiesDialog)
DDX_Text(pDX, IDC_MASTERPASSWORD, m_strMasterPassword);
DDX_Text(pDX, IDC_USERNAME, m_strUserName);
DDX_Text(pDX, IDC_ROUNDS, m_nRounds);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CStoragePropertiesDialog, CDialog)
//{{AFX_MSG_MAP(CStoragePropertiesDialog)
ON_COMMAND(ID_PASSWORDCONTEXT_GENERATEPASSWORD, OnPasswordcontextGeneratepassword)
ON_COMMAND(ID_PASSWORDCONTEXT_HIDEPASSWORD, OnPasswordcontextHidepassword)
ON_COMMAND(ID_PASSWORDCONTEXT_SHOWPASSWORD, OnPasswordcontextShowpassword)
ON_CBN_SELCHANGE(IDC_KEYSIZE, OnSelchangeKeysize)
ON_BN_CLICKED(IDC_MASTERPASSWORD_TITLE, OnMasterpasswordTitle)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CStoragePropertiesDialog message handlers
BOOL CStoragePropertiesDialog::OnInitDialog()
{
CDialog::OnInitDialog();
CDialog::OnInitDialog();
CComboBox *pCombo = (CComboBox *)GetDlgItem(IDC_KEYSIZE);
int nSel = -1;
for(int n = 0; n < sizeof(g_aKeySizes) / sizeof(g_aKeySizes[0]); ++n)
{
pCombo->InsertString(n, g_aKeySizes[n].szItem);
pCombo->SetItemData(n, g_aKeySizes[n].lInfo);
if(m_nKeySize == LOWORD(g_aKeySizes[n].lInfo))
nSel = n;
} // for
pCombo->SetCurSel(nSel);
m_ctrlPassword.SubclassDlgItem(IDC_MASTERPASSWORD_TITLE, this);
SwitchPassword();
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CStoragePropertiesDialog::OnPasswordcontextGeneratepassword()
{
CPasswordGeneratorDialog dlgPassword;
if(IDOK == dlgPassword.DoModal())
{
UpdateData();
m_strMasterPassword = dlgPassword.m_strPassword;
UpdateData(FALSE);
CleanString(dlgPassword.m_strPassword);
} // if
}
void CStoragePropertiesDialog::OnPasswordcontextHidepassword()
{
m_bPassword = !m_bPassword;
SwitchPassword();
}
void CStoragePropertiesDialog::OnPasswordcontextShowpassword()
{
m_bPassword = !m_bPassword;
SwitchPassword();
}
void CStoragePropertiesDialog::OnOK()
{
UpdateData();
if(m_strUserName.IsEmpty())
{
MessageBoxEx(*this, IDS_ENTERUSERNAME, IDS_TITLE);
return;
} // if
if(m_strMasterPassword.IsEmpty())
{
MessageBoxEx(*this, IDS_ENTERMASTERPASSWORD, IDS_TITLE);
return;
} // if
if((0 > m_nRounds) || (255 < m_nRounds))
{
MessageBoxEx(*this, IDS_ENTERROUNDS, IDS_TITLE);
return;
} // if
CComboBox *pCombo = (CComboBox *)GetDlgItem(IDC_KEYSIZE);
if(CB_ERR != pCombo->GetCurSel())
{
m_nKeySize = LOWORD(pCombo->GetItemData(pCombo->GetCurSel()));
} // if
else
{
MessageBoxEx(*this, IDS_SELECTKEYSIZE, IDS_TITLE);
return;
} // else
CDialog::OnOK();
}
void CStoragePropertiesDialog::OnSelchangeKeysize()
{
CComboBox *pCombo = (CComboBox *)GetDlgItem(IDC_KEYSIZE);
if(CB_ERR != pCombo->GetCurSel())
{
UpdateData(TRUE);
m_nRounds = HIWORD(pCombo->GetItemData(pCombo->GetCurSel()));
UpdateData(FALSE);
} // if
}
void CStoragePropertiesDialog::OnMasterpasswordTitle()
{
CRect rc;
GetDlgItem(IDC_MASTERPASSWORD_TITLE)->GetWindowRect(rc);
//GetDlgItem(IDC_MASTERPASSWORD_TITLE)->ClientToScreen(rc);
CMenu mCtx;
mCtx.LoadMenu(IDR_PASSWORD_CONTEXT);
CMenu *pmCtx = mCtx.GetSubMenu(0);
pmCtx->EnableMenuItem(ID_PASSWORDCONTEXT_HIDEPASSWORD, MF_BYCOMMAND |
(m_bPassword ? MF_ENABLED : MF_DISABLED | MF_GRAYED));
pmCtx->EnableMenuItem(ID_PASSWORDCONTEXT_SHOWPASSWORD, MF_BYCOMMAND |
(!m_bPassword ? MF_ENABLED : MF_DISABLED | MF_GRAYED));
pmCtx->TrackPopupMenu(TPM_LEFTALIGN, rc.left, rc.bottom, this);
}
void CStoragePropertiesDialog::SwitchPassword()
{
if(!m_bPassword)
{
((CEdit *)GetDlgItem(IDC_MASTERPASSWORD))->SetPasswordChar(_T('*'));
GetDlgItem(IDC_MASTERPASSWORD)->Invalidate();
} // if
else
{
((CEdit *)GetDlgItem(IDC_MASTERPASSWORD))->SetPasswordChar(0);
GetDlgItem(IDC_MASTERPASSWORD)->Invalidate();
} // if
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.
A list of licenses authors might use can be found here