⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dboxmain.cpp

📁 Password Safe Password Safe is a password database utility. Users can keep their passwords securely
💻 CPP
📖 第 1 页 / 共 4 页
字号:
    HINSTANCE stat = ::ShellExecute(NULL, NULL, m_BrowseURL,				    NULL, _T("."), SW_SHOWNORMAL);    if (int(stat) < 32) {    #ifdef _DEBUG        AfxMessageBox("oops");    #endif    }  }}voidDboxMain::OnCopyPassword() {	bool	bCopyPassword = true;	// will get set to false if user hits cancel	if (!SelItemOk()) 		return;	//Remind the user about clipboard security	CClearQuestionDlg clearDlg(this);	if (clearDlg.m_dontaskquestion == FALSE)	{		int rc = clearDlg.DoModal();		if (rc == IDOK)		{		}		else if (rc == IDCANCEL)		{			bCopyPassword = false;		}	}	if ( !bCopyPassword )		return;	CItemData *ci = getSelectedItem();	ASSERT(ci != NULL);	CMyString curPassString = ci->GetPassword();			uGlobalMemSize = (curPassString.GetLength() + 1) * sizeof(TCHAR);	hGlobalMemory = GlobalAlloc(GMEM_MOVEABLE|GMEM_DDESHARE, uGlobalMemSize);	// {kjp} fix to use UNICODE safe string definitions and string copy functions	LPTSTR pGlobalLock = (LPTSTR)GlobalLock(hGlobalMemory);			strCopy( pGlobalLock, curPassString );			GlobalUnlock(hGlobalMemory);				if (OpenClipboard() == TRUE) {		if (EmptyClipboard()!=TRUE)			AfxMessageBox(_T("The clipboard was not emptied correctly"));		if (SetClipboardData(CLIPBOARD_TEXT_FORMAT, hGlobalMemory) == NULL)			AfxMessageBox(_T("The data was not pasted into the clipboard correctly"));		if (CloseClipboard() != TRUE)			AfxMessageBox(_T("The clipboard could not be closed"));	} else {		AfxMessageBox(_T("The clipboard could not be opened correctly"));	}}voidDboxMain::OnFind() {  m_LockDisabled = true;  CFindDlg::Doit(this); // create modeless or popup existing  // XXX Gross hack to fix aesthetic bug in tree view  // without this, multiple "selected" displayed  // if treeview && there's a selected item, then#if 0      m_ctlItemTree.SetItemState(di->tree_item,				 TVIS_SELECTED,				 TVIS_DROPHILITED | TVIS_SELECTED);#endif  m_LockDisabled = false;}voidDboxMain::ClearClipboard(){   if (OpenClipboard() != TRUE)      AfxMessageBox(_T("The clipboard could not be opened correctly"));   if (IsClipboardFormatAvailable(CLIPBOARD_TEXT_FORMAT) != 0)   {      HGLOBAL hglb = GetClipboardData(CLIPBOARD_TEXT_FORMAT);       if (hglb != NULL)      {         LPTSTR lptstr = (LPTSTR)GlobalLock(hglb);          if (lptstr != NULL)         {			trashMemory( lptstr, strLength(lptstr) );            GlobalUnlock(hglb);          }       }    }   if (EmptyClipboard()!=TRUE)      AfxMessageBox(_T("The clipboard was not emptied correctly"));   if (CloseClipboard() != TRUE)      AfxMessageBox(_T("The clipboard could not be closed"));}// Change the master password for the database.voidDboxMain::OnPasswordChange() {   m_LockDisabled = true;   CPasskeyChangeDlg changeDlg(this);   int rc = changeDlg.DoModal();   m_LockDisabled = false;   if (rc == IDOK)   {     m_core.ChangePassword(changeDlg.m_newpasskey);   }   else if (rc == IDCANCEL)   {   }}voidDboxMain::OnClearClipboard() {   ClearClipboard();}// this tells OnSize that the user is currently// changing the size of the dialog, and not restoring itvoid DboxMain::OnSizing(UINT fwSide, LPRECT pRect) {#if !defined(POCKET_PC)	CDialog::OnSizing(fwSide, pRect);		m_bSizing = true;#endif}voidDboxMain::OnSave() {   m_LockDisabled = true;   Save();   m_LockDisabled = false;}voidDboxMain::OnExportV17(){  int rc;  CMyString newfile;  //SaveAs-type dialog box  while (1)    {      m_LockDisabled = true;      CFileDialog fd(FALSE,                     "dat",                     m_core.GetCurFile(),                     OFN_PATHMUSTEXIST|OFN_HIDEREADONLY                     |OFN_LONGNAMES|OFN_OVERWRITEPROMPT,                     "Password Safe Databases (*.dat)|*.dat|"                     "All files (*.*)|*.*|"                     "|",                     this);      fd.m_ofn.lpstrTitle =	_T("Please name the exported database");      rc = fd.DoModal();      m_LockDisabled = false;      if (rc == IDOK)	{	  newfile = (CMyString)fd.GetPathName();	  break;	}      else	return;    }  rc = m_core.WriteV17File(newfile);  if (rc == PWScore::CANT_OPEN_FILE)    {      CMyString temp = newfile + _T("\n\nCould not open file for writing!");      MessageBox(temp, _T("File write error."), MB_OK|MB_ICONWARNING);    }}voidDboxMain::OnExportText(){  CExportTextDlg et;  m_LockDisabled = true;  int rc = et.DoModal();  m_LockDisabled = false;  if (rc == IDOK) {    CMyString newfile;    CMyString pw(et.m_exportTextPassword);    if (m_core.CheckPassword(m_core.GetCurFile(), pw) == PWScore::SUCCESS) {      // do the export      //SaveAs-type dialog box      while (1) {	CFileDialog fd(FALSE,		       _T("txt"),		       _T(""),		       OFN_PATHMUSTEXIST|OFN_HIDEREADONLY		       |OFN_LONGNAMES|OFN_OVERWRITEPROMPT,		       _T("Text files (*.txt)|*.txt|")		       _T("CSV files (*.csv)|*.csv|")		       _T("All files (*.*)|*.*|")		       _T("|"),		       this);	fd.m_ofn.lpstrTitle =	  _T("Please name the plaintext file");	m_LockDisabled = true;	rc = fd.DoModal();	m_LockDisabled = false;	if (rc == IDOK) {	  newfile = (CMyString)fd.GetPathName();	  break;	} else	  return;      } // while (1)      rc = m_core.WritePlaintextFile(newfile);      if (rc == PWScore::CANT_OPEN_FILE)	{	  CMyString temp = newfile + _T("\n\nCould not open file for writing!");	  MessageBox(temp, _T("File write error."), MB_OK|MB_ICONWARNING);	}    } else {      MessageBox(_T("Passkey incorrect"), _T("Error"));      Sleep(3000); // protect against automatic attacks    }  }}voidDboxMain::OnExportXML(){  m_LockDisabled = true;    // TODO - currently disabled in menubar  m_LockDisabled = false;}voidDboxMain::OnImportText(){    // TODO    CFileDialog fd(TRUE,        _T("txt"),        NULL,        OFN_FILEMUSTEXIST|OFN_HIDEREADONLY|OFN_LONGNAMES,        _T("Text files (*.txt)|*.txt|")        _T("CSV files (*.csv)|*.csv|")        _T("All files (*.*)|*.*|")        _T("|"),        this);    fd.m_ofn.lpstrTitle = _T("Please Choose a Text File to Import:");    m_LockDisabled = true;    int rc = fd.DoModal();    m_LockDisabled = false;    if (rc == IDOK)    {        CMyString newfile = (CMyString)fd.GetPathName();        rc = m_core.ImportPlaintextFile(newfile);        if (rc == PWScore::CANT_OPEN_FILE) {	    CMyString temp = newfile + _T("\n\nCould not open file for reading!");            MessageBox(temp, _T("File open error."), MB_OK|MB_ICONWARNING);        }        RefreshList();            }}voidDboxMain::OnImportXML(){  m_LockDisabled = true;    // TODO - currently disabled in menubar  m_LockDisabled = false;}void DboxMain::SetChanged(bool changed) // for MyTreeCtrl{  if (PWSprefs::GetInstance()->GetPref(PWSprefs::BoolPrefs::SaveImmediately)) {    Save();  } else {    m_core.SetChanged(changed);  }}intDboxMain::Save(){   int rc;   if (m_core.GetCurFile().IsEmpty())      return SaveAs();   if (m_core.GetReadFileVersion() == PWSfile::V17) {     CString OldName(m_core.GetCurFile());     int dotIndex = OldName.ReverseFind(TCHAR('.'));     if (dotIndex != -1)       OldName = OldName.Left(dotIndex);     OldName += _T(".old");     CString msg = _T("The original database, \"");     msg += CString(m_core.GetCurFile());     msg += _T("\", is in pre-2.0 format."	       " It will be unchanged, and renamed to \"");     msg += OldName;     msg += _T("\"\nYour changes will be written in the new"	       " format, which is unusable by old versions of PasswordSafe."	       " To save your changes in the old format, use the \"File->Export To"	       "-> Old (1.x) format\" command.\n\n"	       "Press OK to continue saving, or Cancel to stop.");     if (MessageBox(msg, _T("File version warning"),		    MB_OKCANCEL|MB_ICONWARNING) == IDCANCEL)       return PWScore::USER_CANCEL;     if (m_core.RenameFile(m_core.GetCurFile(), OldName) != PWScore::SUCCESS) {       MessageBox(_T("Could not rename file"), _T("File rename error"),		  MB_OK|MB_ICONWARNING);       return PWScore::CANT_OPEN_FILE;     }   }   rc = m_core.WriteCurFile();   if (rc == PWScore::CANT_OPEN_FILE)   {      CMyString temp = m_core.GetCurFile() + "\n\nCould not open file for writing!";      MessageBox(temp, _T("File write error"), MB_OK|MB_ICONWARNING);      return PWScore::CANT_OPEN_FILE;   }   ChangeOkUpdate();   return PWScore::SUCCESS;}voidDboxMain::ChangeOkUpdate(){   if (! m_windowok)      return;#if defined(POCKET_PC)   CMenu *menu	= m_wndMenu;#else   CMenu *menu	= GetMenu();#endif   menu->EnableMenuItem(ID_MENUITEM_SAVE,			m_core.IsChanged() ? MF_ENABLED : MF_GRAYED);   /*     This doesn't exactly belong here, but it makes sure that the     title is fresh...   */#if !defined(POCKET_PC)   SetWindowText(LPCTSTR(m_title));#endif}voidDboxMain::OnAbout() {   DboxAbout dbox;   m_LockDisabled = true;   dbox.DoModal();   m_LockDisabled = false;}void DboxMain::OnPasswordSafeWebsite(){  HINSTANCE stat = ::ShellExecute(NULL, NULL, "http://passwordsafe.sourceforge.net/",				  NULL, _T("."), SW_SHOWNORMAL);  if (int(stat) < 32) {#ifdef _DEBUG    AfxMessageBox("oops");#endif  }}voidDboxMain::OnCopyUsername() {   if (SelItemOk() != TRUE)      return;   CItemData *ci = getSelectedItem();   ASSERT(ci != NULL);   CMyString username = ci->GetUser();   if (username.IsEmpty())   {      AfxMessageBox(_T("There is no username associated with this item."));   }   else   {      uGlobalMemSize = (username.GetLength() + 1) * sizeof(TCHAR);      hGlobalMemory = GlobalAlloc(GMEM_MOVEABLE|GMEM_DDESHARE,                                  uGlobalMemSize);      LPTSTR pGlobalLock = (LPTSTR)GlobalLock(hGlobalMemory);	  strCopy( pGlobalLock, username );      GlobalUnlock(hGlobalMemory);			      if (OpenClipboard() == TRUE)      {         if (EmptyClipboard()!=TRUE)            AfxMessageBox(_T("The clipboard was not emptied correctly"));         if (SetClipboardData(CLIPBOARD_TEXT_FORMAT, hGlobalMemory) == NULL)            AfxMessageBox(_T("The data was not pasted into the clipboard correctly"));         if (CloseClipboard() != TRUE)            AfxMessageBox(_T("The clipboard could not be closed"));      }      else      {         AfxMessageBox(_T("The clipboard could not be opened correctly"));      }      //No need to remind the user about clipboard security      //as this is only a username   }}voidDboxMain::OnBackupSafe() {   m_LockDisabled = true;   BackupSafe();   m_LockDisabled = false;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -