📄 pwsafedlg.cpp
字号:
return TRUE;
}
void CPwSafeDlg::_ParseSpecAndSetFont(const TCHAR *pszSpec)
{
HFONT hPre = (HFONT)m_fListFont;
CDC *pDC = GetDC();
HDC hDC = pDC->m_hDC;
CString strFontSpec, strTemp;
LOGFONT lf;
int nSize;
ASSERT(pszSpec != NULL);
if(pszSpec == NULL) { ReleaseDC(pDC); return; }
ZeroMemory(&lf, sizeof(LOGFONT));
if(hPre != NULL) m_fListFont.DeleteObject();
if(_tcslen(pszSpec) != 0) // Font spec format: <FACE>;<SIZE>,<FLAGS>
{
strFontSpec = pszSpec;
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);
nSize = _ttoi(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);
if(nSize < 0) nSize = -nSize;
if(strFace.GetLength() >= 32) strFace = strFace.Left(31);
lf.lfCharSet = DEFAULT_CHARSET; lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
lf.lfEscapement = 0; lf.lfItalic = bItalic; lf.lfOrientation = 0;
lf.lfOutPrecision = OUT_DEFAULT_PRECIS; lf.lfQuality = DEFAULT_QUALITY;
lf.lfPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE;
lf.lfStrikeOut = bStrikeOut; lf.lfUnderline = bUnderlined;
lf.lfWeight = nWeight; lf.lfWidth = 0;
_tcscpy_s(lf.lfFaceName, _countof(lf.lfFaceName), strFace);
lf.lfHeight = -MulDiv(nSize, GetDeviceCaps(hDC, LOGPIXELSY), 72);
m_fListFont.CreateFontIndirect(&lf);
}
else
{
nSize = 8;
m_fListFont.CreateFont(nSize, 0, 0, 0, FW_NORMAL, 0, 0, 0, ANSI_CHARSET,
OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
DEFAULT_PITCH | FF_DONTCARE, _T("MS Shell Dlg"));
}
ZeroMemory(&lf, sizeof(LOGFONT));
m_fListFont.GetLogFont(&lf);
strFontSpec = lf.lfFaceName;
strFontSpec += _T(';');
strTemp.Format(_T("%d"), nSize);
strFontSpec += strTemp;
strFontSpec += _T(",");
if(lf.lfWeight == FW_BOLD) strFontSpec += _T('1'); else strFontSpec += _T('0');
if(lf.lfItalic != 0) strFontSpec += _T('1'); else strFontSpec += _T('0');
if(lf.lfUnderline != 0) strFontSpec += _T('1'); else strFontSpec += _T('0');
if(lf.lfStrikeOut != 0) strFontSpec += _T('1'); else strFontSpec += _T('0');
m_strFontSpec = strFontSpec;
m_strListFontFace = lf.lfFaceName;
m_nListFontSize = nSize;
ASSERT(m_fListFont.m_hObject != NULL);
m_cGroups.SetFont(&m_fListFont, TRUE);
m_cList.SetFont(&m_fListFont, TRUE);
ReleaseDC(pDC);
}
// This should be replaced by a function that scans the accelerator table
const TCHAR *CPwSafeDlg::_GetCmdAccelExt(const TCHAR *psz)
{
static const TCHAR *pEmpty = _T("");
ASSERT(psz != NULL); if(psz == NULL) return pEmpty;
if(_tcsicmp(psz, _T("&New...")) == 0) return _T("Ctrl+N");
if(_tcsicmp(psz, _T("&Open...")) == 0) return _T("Ctrl+O");
if(_tcsicmp(psz, _T("&Save")) == 0) return _T("Ctrl+S");
if(_tcsicmp(psz, _T("&Close")) == 0) return _T("Ctrl+W");
if(_tcsicmp(psz, _T("&Print...")) == 0) return _T("Ctrl+P");
if(_tcsicmp(psz, _T("&Database Settings...")) == 0) return _T("Ctrl+I");
if(_tcsicmp(psz, _T("&Lock Workspace")) == 0) return _T("Ctrl+L");
if(_tcsicmp(psz, _T("E&xit")) == 0) return _T("Ctrl+X");
if(_tcsicmp(psz, _T("&Add Entry...")) == 0) return _T("Ctrl+Y");
if(_tcsicmp(psz, _T("&Edit/View Entry...")) == 0) return _T("Ctrl+E");
if(_tcsicmp(psz, _T("&Delete Entry")) == 0) return _T("Ctrl+D");
if(_tcsicmp(psz, _T("Se&lect All")) == 0) return _T("Ctrl+A");
if(_tcsicmp(psz, _T("&Find in Database...")) == 0) return _T("Ctrl+F");
if(_tcsicmp(psz, _T("Add Password &Group...")) == 0) return _T("Ctrl+G");
if(_tcsicmp(psz, _T("Open &URL(s)")) == 0) return _T("Ctrl+U");
if(_tcsicmp(psz, _T("Copy &Password to Clipboard")) == 0) return _T("Ctrl+C");
if(_tcsicmp(psz, _T("Copy User &Name to Clipboard")) == 0) return _T("Ctrl+B");
if(_tcsicmp(psz, _T("Dupli&cate Entry")) == 0) return _T("Ctrl+K");
if(_tcsicmp(psz, _T("&Options...")) == 0) return _T("Ctrl+M");
if(_tcsicmp(psz, _T("Perform Auto-&Type")) == 0) return _T("Ctrl+V");
if(_tcsicmp(psz, _T("Password &Generator...")) == 0) return _T("Ctrl+Z");
if(_tcsicmp(psz, _T("Hide &User Names Behind Asterisks (***)")) == 0) return _T("Ctrl+J");
if(_tcsicmp(psz, _T("Hide &Passwords Behind Asterisks (***)")) == 0) return _T("Ctrl+H");
if(_tcsicmp(psz, _T("Move Entry to &Top")) == 0) return _T("Alt+Home");
if(_tcsicmp(psz, _T("Move Entry &One Up")) == 0) return _T("Alt+Up");
if(_tcsicmp(psz, _T("Mo&ve Entry One Down")) == 0) return _T("Alt+Down");
if(_tcsicmp(psz, _T("Move Entry to &Bottom")) == 0) return _T("Alt+End");
if(_tcsicmp(psz, _T("Move Group to &Top")) == 0) return _T("Alt+Home");
if(_tcsicmp(psz, _T("Move Group One &Up")) == 0) return _T("Alt+Up");
if(_tcsicmp(psz, _T("Move Group &One Down")) == 0) return _T("Alt+Down");
if(_tcsicmp(psz, _T("Move Group to &Bottom")) == 0) return _T("Alt+End");
if(_tcsicmp(psz, _T("Move Group One &Left")) == 0) return _T("Alt+Left");
if(_tcsicmp(psz, _T("Move Group One &Right")) == 0) return _T("Alt+Right");
if(_tcsicmp(psz, _T("&Help Contents")) == 0) return _T("F1");
return pEmpty;
}
void CPwSafeDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
// Map close button to minimize button if the user wants this
if((nID == SC_CLOSE) && (m_bCloseMinimizes == TRUE))
{
::SendMessage(this->m_hWnd, WM_SYSCOMMAND, SC_MINIMIZE, 0);
return;
}
if((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
return;
}
else if(nID == SC_MINIMIZE)
{
_SaveWindowPositionAndSize(NULL);
if(m_bMinimizeToTray == TRUE)
{
SetTrayState(TRUE);
return;
}
}
CDialog::OnSysCommand(nID, lParam);
}
void CPwSafeDlg::OnPaint()
{
if(IsIconic())
{
CPaintDC dc(this);
SendMessage(WM_ICONERASEBKGND, (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
{
CDialog::OnPaint();
}
}
HCURSOR CPwSafeDlg::OnQueryDragIcon()
{
return (HCURSOR)m_hIcon;
}
void CPwSafeDlg::OnMeasureItem(int nIDCtl, LPMEASUREITEMSTRUCT lpMeasureItemStruct)
{
BOOL setflag = FALSE;
if(lpMeasureItemStruct->CtlType==ODT_MENU)
{
if(IsMenu((HMENU)(UINT_PTR)lpMeasureItemStruct->itemID) &&
BCMenu::IsMenu((HMENU)(UINT_PTR)lpMeasureItemStruct->itemID))
{
m_menu.MeasureItem(lpMeasureItemStruct);
setflag = TRUE;
}
}
if(!setflag)CDialog::OnMeasureItem(nIDCtl, lpMeasureItemStruct);
}
LRESULT CPwSafeDlg::OnMenuChar(UINT nChar, UINT nFlags, CMenu* pMenu)
{
LRESULT lresult = 0;
if(BCMenu::IsMenu(pMenu))
lresult = BCMenu::FindKeyboardShortcut(nChar, nFlags, pMenu);
else
lresult = CDialog::OnMenuChar(nChar, nFlags, pMenu);
return(lresult);
}
void CPwSafeDlg::OnInitMenuPopup(CMenu* pPopupMenu, UINT nIndex, BOOL bSysMenu)
{
NotifyUserActivity();
m_dwLastFirstSelectedItem = GetSelectedEntry();
m_dwLastNumSelectedItems = GetSelectedEntriesCount();
m_hLastSelectedGroup = m_cGroups.GetSelectedItem();
// CMenu *p = m_menu.GetSubMenu(TRL("&Tools"));
// if(p == pPopupMenu) RebuildPluginMenu();
_CALLPLUGINS(KPM_INIT_MENU_POPUP, 0, 0);
CDialog::OnInitMenuPopup(pPopupMenu, nIndex, bSysMenu);
OnUpdateFlush(pPopupMenu);
if(!bSysMenu)
if(BCMenu::IsMenu(pPopupMenu)) BCMenu::UpdateMenu(pPopupMenu);
}
// BCMenu function
void CPwSafeDlg::OnUpdateFlush(CMenu *pMenu)
{
ASSERT(pMenu != NULL);
// check the enabled state of various menu items
CCmdUI state;
state.m_pMenu = pMenu;
ASSERT(state.m_pOther == NULL);
ASSERT(state.m_pParentMenu == NULL);
// determine if menu is popup in top-level menu and set m_pOther to
// it if so (m_pParentMenu == NULL indicates that it is secondary popup)
HMENU hParentMenu;
if(AfxGetThreadState()->m_hTrackingMenu == pMenu->m_hMenu)
state.m_pParentMenu = pMenu; // parent == child for tracking popup
else if ((hParentMenu = ::GetMenu(m_hWnd)) != NULL)
{
CWnd* pParent = GetTopLevelParent();
// child windows don't have menus -- need to go to the top!
if(pParent != NULL && (hParentMenu = ::GetMenu(pParent->m_hWnd)) != NULL)
{
int nIndexMax = ::GetMenuItemCount(hParentMenu);
for (int nIndex = 0; nIndex < nIndexMax; nIndex++)
{
if (::GetSubMenu(hParentMenu, nIndex) == pMenu->m_hMenu)
{
// when popup is found, m_pParentMenu is containing menu
state.m_pParentMenu = CMenu::FromHandle(hParentMenu);
break;
}
}
}
}
state.m_nIndexMax = pMenu->GetMenuItemCount();
for (state.m_nIndex = 0; state.m_nIndex < state.m_nIndexMax; state.m_nIndex++)
{
state.m_nID = pMenu->GetMenuItemID(state.m_nIndex);
if(state.m_nID == 0) continue; // menu separator or invalid cmd - ignore it
ASSERT(state.m_pOther == NULL);
ASSERT(state.m_pMenu != NULL);
if (state.m_nID == (UINT)-1)
{
// possibly a popup menu, route to first item of that popup
state.m_pSubMenu = pMenu->GetSubMenu(state.m_nIndex);
if((state.m_pSubMenu == NULL) ||
((state.m_nID = state.m_pSubMenu->GetMenuItemID(0)) == 0) ||
(state.m_nID == (UINT)(-1)))
{
continue; // first item of popup can't be routed to
}
state.DoUpdate(this, FALSE); // popups are never auto disabled
}
else
{
// normal menu item
// Auto enable/disable if frame window has 'm_bAutoMenuEnable'
// set and command is _not_ a system command.
state.m_pSubMenu = NULL;
state.DoUpdate(this, state.m_nID < 0xF000);
}
// adjust for menu deletions and additions
UINT nCount = pMenu->GetMenuItemCount();
if (nCount < state.m_nIndexMax)
{
state.m_nIndex -= (state.m_nIndexMax - nCount);
while (state.m_nIndex < nCount &&
pMenu->GetMenuItemID(state.m_nIndex) == state.m_nID)
{
state.m_nIndex++;
}
}
state.m_nIndexMax = nCount;
}
}
void CPwSafeDlg::OnSize(UINT nType, int cx, int cy)
{
if(cx < MWS_MIN_CX) cx = MWS_MIN_CX; // Minimum sizes
if(cy < MWS_MIN_CY) cy = MWS_MIN_CY;
CDialog::OnSize(nType, cx, cy);
BOOL bWasInvisible = FALSE;
if(m_bMinimized == TRUE) bWasInvisible = TRUE;
if(nType == SIZE_MAXIMIZED) m_bWasMaximized = TRUE;
else if(m_bTrayed == FALSE)
{
if((nType == SIZE_RESTORED) && (m_bWasMaximized == TRUE)) m_bWasMaximized = FALSE;
else if((nType == SIZE_RESTORED) && (m_bMinimized == FALSE)) m_bWasMaximized = FALSE;
}
if(nType == SIZE_MINIMIZED) m_bMinimized = TRUE;
else if((nType == SIZE_RESTORED) && (m_bMinimized == TRUE)) m_bMinimized = FALSE;
else if((nType == SIZE_MAXIMIZED) && (m_bMinimized == TRUE)) m_bMinimized = FALSE;
if(m_bIgnoreSizeEvent == TRUE) return;
if(nType == SIZE_MINIMIZED)
{
if(m_bMinimizeToTray == TRUE) SetTrayState(TRUE);
}
if(nType != SIZE_MINIMIZED) ProcessResize();
BOOL m_bRestore = FALSE;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -