📄 optionsdlg.cpp
字号:
m_btnColorRowHighlight.SetColor(m_rgbRowHighlight);
m_btnColorRowHighlight.SetCustomText(TRL("More Colors..."));
m_btnColorRowHighlight.SetDefaultText(TRL("Default"));
if(m_dwDefaultExpire == 0)
{
m_bDefaultExpire = FALSE;
GetDlgItem(IDC_EDIT_DEFAULTEXPIRE)->EnableWindow(FALSE);
}
else m_bDefaultExpire = TRUE;
UpdateData(FALSE);
OnCheckLockAfterTime();
return TRUE;
}
void COptionsDlg::AddTcItem(LPCTSTR lpName, int iImageIndex)
{
TCITEM tci;
ZeroMemory(&tci, sizeof(TCITEM));
tci.mask = TCIF_TEXT | TCIF_IMAGE;
tci.cchTextMax = static_cast<int>(_tcslen(lpName));
tci.pszText = const_cast<LPTSTR>(lpName);
tci.iImage = iImageIndex;
m_tabMenu.InsertItem(m_tabMenu.GetItemCount(), &tci);
}
void COptionsDlg::OnOK()
{
UpdateData(TRUE);
WORD wVK = 0, wMod = 0;
m_hkAutoType.GetHotKey(wVK, wMod);
DWORD dwNewHotKey = ((DWORD)wMod << 16) | (DWORD)wVK;
if(dwNewHotKey != m_dwATHotKey)
{
if(m_pParentDlg->RegisterGlobalHotKey(HOTKEYID_AUTOTYPE, dwNewHotKey, (m_dwATHotKey != 0) ? TRUE : FALSE, TRUE) == FALSE)
return;
m_dwATHotKey = dwNewHotKey;
}
m_rgbRowHighlight = m_btnColorRowHighlight.GetColor();
if((m_bLockAfterTime == TRUE) && (m_nLockAfter < 5)) m_nLockAfter = 5;
if(m_bDefaultExpire == FALSE) m_dwDefaultExpire = 0;
m_ilIcons.DeleteImageList();
m_ilOptionIcons.DeleteImageList();
CDialog::OnOK();
}
void COptionsDlg::OnCancel()
{
m_ilIcons.DeleteImageList();
m_ilOptionIcons.DeleteImageList();
CDialog::OnCancel();
}
void COptionsDlg::OnBtnSelFont()
{
CString strFontSpec = m_strFontSpec;
CString strFace, strSize, strFlags;
int nChars = strFontSpec.ReverseFind(_T(';'));
int nSizeEnd = strFontSpec.ReverseFind(_T(','));
strFace = strFontSpec.Left(nChars);
strSize = strFontSpec.Mid(nChars + 1, nSizeEnd - nChars - 1);
strFlags = strFontSpec.Right(4);
int nSize = _ttoi((LPCTSTR)strSize);
int nWeight = FW_NORMAL;
if(strFlags.GetAt(0) == _T('1')) nWeight = FW_BOLD;
BYTE bItalic = (BYTE)((strFlags.GetAt(1) == _T('1')) ? TRUE : FALSE);
BYTE bUnderlined = (BYTE)((strFlags.GetAt(2) == _T('1')) ? TRUE : FALSE);
BYTE bStrikeOut = (BYTE)((strFlags.GetAt(3) == _T('1')) ? TRUE : FALSE);
LOGFONT lf;
CDC *pDC = GetDC();
HDC hDC = pDC->m_hDC;
ASSERT(hDC != NULL);
if(hDC != NULL) lf.lfHeight = -MulDiv(nSize, GetDeviceCaps(hDC, LOGPIXELSY), 72);
else { ASSERT(FALSE); lf.lfHeight = -nSize; }
ReleaseDC(pDC); pDC = NULL;
lf.lfWidth = 0; lf.lfEscapement = 0; lf.lfOrientation = 0;
lf.lfWeight = nWeight; lf.lfItalic = bItalic; lf.lfUnderline = bUnderlined;
lf.lfStrikeOut = bStrikeOut; lf.lfCharSet = DEFAULT_CHARSET;
lf.lfOutPrecision = OUT_DEFAULT_PRECIS; lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
lf.lfQuality = DEFAULT_QUALITY; lf.lfPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE;
_tcscpy_s(lf.lfFaceName, _countof(lf.lfFaceName), strFace);
CFontDialog dlg(&lf);
CString strTemp;
if(dlg.DoModal() == IDOK)
{
int dSize = dlg.GetSize();
dSize = (dSize >= 0) ? dSize : -dSize;
m_strFontSpec = dlg.GetFaceName();
m_strFontSpec += _T(";");
strTemp.Format(_T("%d"), dSize / 10);
m_strFontSpec += strTemp;
m_strFontSpec += _T(",");
m_strFontSpec += (dlg.IsBold() == TRUE) ? _T('1') : _T('0');
m_strFontSpec += (dlg.IsItalic() == TRUE) ? _T('1') : _T('0');
m_strFontSpec += (dlg.IsUnderline() == TRUE) ? _T('1') : _T('0');
m_strFontSpec += (dlg.IsStrikeOut() == TRUE) ? _T('1') : _T('0');
}
}
void COptionsDlg::OnSelChangeTabMenu(NMHDR* pNMHDR, LRESULT* pResult)
{
int nCurSel = m_tabMenu.GetCurSel();
UNREFERENCED_PARAMETER(pNMHDR);
UpdateData(TRUE);
switch(nCurSel)
{
case OPTGRP_SECURITY:
m_wndgrp.HideAllExcept(OPTGRP_SECURITY);
if(m_bLockAfterTime == FALSE)
GetDlgItem(IDC_EDIT_LOCKSECONDS)->EnableWindow(FALSE);
if(m_bDefaultExpire == FALSE)
GetDlgItem(IDC_EDIT_DEFAULTEXPIRE)->EnableWindow(FALSE);
break;
case OPTGRP_GUI:
m_wndgrp.HideAllExcept(OPTGRP_GUI);
break;
case OPTGRP_FILES:
m_wndgrp.HideAllExcept(OPTGRP_FILES);
break;
case OPTGRP_MEMORY:
m_wndgrp.HideAllExcept(OPTGRP_MEMORY);
if(m_nClipboardMethod != CM_TIMED)
GetDlgItem(IDC_EDIT_CLIPBOARDTIME)->EnableWindow(FALSE);
break;
case OPTGRP_SETUP:
m_wndgrp.HideAllExcept(OPTGRP_SETUP);
if(m_bDisableAutoType == TRUE)
m_hkAutoType.EnableWindow(FALSE);
break;
case OPTGRP_ADVANCED:
m_wndgrp.HideAllExcept(OPTGRP_ADVANCED);
break;
default:
ASSERT(FALSE);
break;
}
*pResult = 0;
}
void COptionsDlg::OnBtnCreateAssoc()
{
if(CPwSafeApp::RegisterShellAssociation() == TRUE)
{
NotifyAssocChanged();
MessageBox(TRL("Successfully associated KeePass with .kdb files! A double-click on a .kdb file will now start KeePass automatically!"),
TRL("Password Safe"), MB_OK | MB_ICONINFORMATION);
}
else
{
MessageBox(TRL("Failed to change the .kdb file association. Make sure you have the rights to write to the registry and change file associations."),
TRL("Password Safe"), MB_OK | MB_ICONWARNING);
}
}
void COptionsDlg::OnBtnDeleteAssoc()
{
if(CPwSafeApp::UnregisterShellAssociation() == TRUE)
{
NotifyAssocChanged();
MessageBox(TRL("Successfully removed association! KeePass won't be started any more when double-clicking on a .kdb file!"),
TRL("Password Safe"), MB_OK | MB_ICONINFORMATION);
}
else
{
MessageBox(TRL("Failed to change the .kdb file association. Make sure you have the rights to write to the registry and change file associations."),
TRL("Password Safe"), MB_OK | MB_ICONWARNING);
}
}
void COptionsDlg::NotifyAssocChanged()
{
HINSTANCE hShell32 = LoadLibrary(_T("Shell32.dll"));
if(hShell32 != NULL)
{
LPSHCHANGENOTIFY lpSHChangeNotify = (LPSHCHANGENOTIFY)GetProcAddress(
hShell32, "SHChangeNotify");
if(lpSHChangeNotify != NULL)
{
lpSHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, NULL, NULL);
}
else { ASSERT(FALSE); }
FreeLibrary(hShell32);
}
else { ASSERT(FALSE); }
}
void COptionsDlg::OnRadioClipMethodSecure()
{
CString str = TRL("Warning! It is possible that this option won't work correctly on your system, especially if you are using any clipboard enhancing or clipboard backup tools.");
str += _T("\r\n\r\n");
str += TRL("If you notice any problems with the enhanced method, switch back to the timed clipboard clearing method.");
MessageBox((LPCTSTR)str, TRL("Password Safe"), MB_ICONINFORMATION | MB_OK);
UpdateData(TRUE);
if(m_nClipboardMethod == CM_TIMED) GetDlgItem(IDC_EDIT_CLIPBOARDTIME)->EnableWindow(TRUE);
else GetDlgItem(IDC_EDIT_CLIPBOARDTIME)->EnableWindow(FALSE);
}
void COptionsDlg::OnRadioClipMethodTimed()
{
UpdateData(TRUE);
if(m_nClipboardMethod == CM_TIMED) GetDlgItem(IDC_EDIT_CLIPBOARDTIME)->EnableWindow(TRUE);
else GetDlgItem(IDC_EDIT_CLIPBOARDTIME)->EnableWindow(FALSE);
}
void COptionsDlg::OnCheckDefaultExpire()
{
UpdateData(TRUE);
if(m_bDefaultExpire == TRUE) GetDlgItem(IDC_EDIT_DEFAULTEXPIRE)->EnableWindow(TRUE);
else GetDlgItem(IDC_EDIT_DEFAULTEXPIRE)->EnableWindow(FALSE);
}
void COptionsDlg::OnCheckLockAfterTime()
{
UpdateData(TRUE);
if(m_bLockAfterTime == FALSE) GetDlgItem(IDC_EDIT_LOCKSECONDS)->EnableWindow(FALSE);
else GetDlgItem(IDC_EDIT_LOCKSECONDS)->EnableWindow(TRUE);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -