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

📄 dboxmain.cpp

📁 Password Safe Password Safe is a password database utility. Users can keep their passwords securely
💻 CPP
📖 第 1 页 / 共 4 页
字号:
    {      DBGMSG("PasskeyEntry returns IDOK\n");      passkey = dbox_pkentry.GetPasskey();      retval = PWScore::SUCCESS;    }  else /*if (rc==IDCANCEL) */ //Determine reason for cancel    {      int cancelreturn = dbox_pkentry.GetStatus();      switch (cancelreturn)	{	case TAR_OPEN:	case TAR_NEW:	  DBGMSG("PasskeyEntry TAR_OPEN or TAR_NEW\n");	  retval = cancelreturn; //Return either open or new flag... 	  break;	default:	  DBGMSG("Default to WRONG_PASSWORD\n");	  retval = PWScore::WRONG_PASSWORD;	//Just a normal cancel	  break;	}    }  app.m_pMainWnd = NULL; // done with dbox_pkentry  return retval;}intDboxMain::NewFile(void){   CPasskeySetup dbox_pksetup(this);   //app.m_pMainWnd = &dbox_pksetup;   int rc = dbox_pksetup.DoModal();   if (rc == IDCANCEL)      return PWScore::USER_CANCEL;  //User cancelled password entry   ClearData();   m_core.NewFile(dbox_pksetup.m_passkey);   m_needsreading = false;   startLockCheckTimer();   return PWScore::SUCCESS;}BOOLDboxMain::OnToolTipText(UINT,                        NMHDR* pNMHDR,                        LRESULT* pResult)// This code is copied from the DLGCBR32 example that comes with MFC{#if !defined(POCKET_PC)   ASSERT(pNMHDR->code == TTN_NEEDTEXTA || pNMHDR->code == TTN_NEEDTEXTW);   // allow top level routing frame to handle the message   if (GetRoutingFrame() != NULL)      return FALSE;   // need to handle both ANSI and UNICODE versions of the message   TOOLTIPTEXTA* pTTTA = (TOOLTIPTEXTA*)pNMHDR;   TOOLTIPTEXTW* pTTTW = (TOOLTIPTEXTW*)pNMHDR;   TCHAR szFullText[256];   CString strTipText;   UINT nID = pNMHDR->idFrom;   if (pNMHDR->code == TTN_NEEDTEXTA && (pTTTA->uFlags & TTF_IDISHWND) ||       pNMHDR->code == TTN_NEEDTEXTW && (pTTTW->uFlags & TTF_IDISHWND))   {      // idFrom is actually the HWND of the tool      nID = ((UINT)(WORD)::GetDlgCtrlID((HWND)nID));   }   if (nID != 0) // will be zero on a separator   {      AfxLoadString(nID, szFullText);      // this is the command id, not the button index      AfxExtractSubString(strTipText, szFullText, 1, '\n');   }#ifndef _UNICODE   if (pNMHDR->code == TTN_NEEDTEXTA)      lstrcpyn(pTTTA->szText, strTipText,               (sizeof(pTTTA->szText)/sizeof(pTTTA->szText[0])));#if 0 // build problem with new cl? - jpr   else      _mbstowcsz(pTTTW->szText, strTipText,                 (sizeof(pTTTW->szText)/sizeof(pTTTW->szText[0])));#endif // 0#else   if (pNMHDR->code == TTN_NEEDTEXTA)      _wcstombsz(pTTTA->szText, strTipText,                 (sizeof(pTTTA->szText)/sizeof(pTTTA->szText[0])));   else      lstrcpyn(pTTTW->szText, strTipText,               (sizeof(pTTTW->szText)/sizeof(pTTTW->szText[0])));#endif   *pResult = 0;   // bring the tooltip window above other popup windows   ::SetWindowPos(pNMHDR->hwndFrom, HWND_TOP, 0, 0, 0, 0,                  SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOMOVE);#endif   return TRUE;    // message was handled}#if !defined(POCKET_PC)voidDboxMain::OnDropFiles(HDROP hDrop){   //SetActiveWindow();   SetForegroundWindow();   MessageBox(_T("go away you silly git"), _T("File drop"), MB_OK);#if 0   // here's what we really want - sorta   HDROP m_hDropInfo = hDropInfo;           CString Filename;   if (m_hDropInfo)   {      int iFiles = DragQueryFile(m_hDropInfo, (UINT)-1, NULL, 0);      for (int i=0; i<ifiles; i++)      {         char* pFilename = Filename.GetBuffer(_MAX_PATH);         // do whatever...      }   // for each files...   }       // if DropInfo   DragFinish(m_hDropInfo);   m_hDropInfo = 0;#endif   DragFinish(hDrop);} #endifBOOLDboxMain::CheckExtension(const CMyString &name, const CMyString &ext) const{   int pos = name.Find(ext);   return (pos == name.GetLength() - ext.GetLength()); //Is this at the end??}voidDboxMain::UpdateAlwaysOnTop(){#if !defined(POCKET_PC)	CMenu*	sysMenu = GetSystemMenu( FALSE );	if ( m_bAlwaysOnTop )	{		SetWindowPos( &wndTopMost, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE );		sysMenu->CheckMenuItem( ID_SYSMENU_ALWAYSONTOP, MF_BYCOMMAND | MF_CHECKED );	}	else	{		SetWindowPos( &wndNoTopMost, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE );		sysMenu->CheckMenuItem( ID_SYSMENU_ALWAYSONTOP, MF_BYCOMMAND | MF_UNCHECKED );	}#endif}void DboxMain::OnSysCommand( UINT nID, LPARAM lParam ){#if !defined(POCKET_PC)  m_LockDisabled = true;  CDialog::OnSysCommand( nID, lParam );  if ( ID_SYSMENU_ALWAYSONTOP == nID )    {      m_bAlwaysOnTop = !m_bAlwaysOnTop;      PWSprefs::GetInstance()->SetPref(PWSprefs::BoolPrefs::AlwaysOnTop,				       m_bAlwaysOnTop);      UpdateAlwaysOnTop();    }  m_LockDisabled = false;#endif}voidDboxMain::ConfigureSystemMenu(){#if defined(POCKET_PC)	m_wndCommandBar = (CCeCommandBar*) m_pWndEmptyCB;	m_wndMenu		= m_wndCommandBar->InsertMenuBar( IDR_MAINMENU );	ASSERT( m_wndMenu != NULL );#else	CMenu*	sysMenu = GetSystemMenu( FALSE );	CString	str;	str.LoadString( IDS_ALWAYSONTOP );	sysMenu->InsertMenu( 5, MF_BYPOSITION | MF_STRING, ID_SYSMENU_ALWAYSONTOP, (LPCTSTR)str );#endif}//-----------------------------------------------------------------------------//-----------------------------------------------------------------------------voidDboxMain::OnUpdateMRU(CCmdUI* pCmdUI) {	app.GetMRU()->UpdateMenu( pCmdUI );	}#if _MFC_VER > 1200BOOL#elsevoid #endifDboxMain::OnOpenMRU(UINT nID){	UINT	uMRUItem = nID - ID_FILE_MRU_ENTRY1;	CString mruItem = (*app.GetMRU())[uMRUItem];	Open( mruItem );#if _MFC_VER > 1200	return TRUE;#endif}// Called just before any pulldown or popup menu is displayed, so that menu items// can be enabled/disabled or checked/unchecked dynamically.void DboxMain::OnInitMenu(CMenu* pMenu){    const BOOL bTreeView = m_ctlItemTree.IsWindowVisible();    const BOOL bItemSelected = SelItemOk();    UINT uiItemCmdFlags = MF_BYCOMMAND | (bItemSelected ? MF_ENABLED : MF_GRAYED);    pMenu->EnableMenuItem(ID_MENUITEM_COPYPASSWORD, uiItemCmdFlags);    pMenu->EnableMenuItem(ID_MENUITEM_COPYUSERNAME, uiItemCmdFlags);    pMenu->EnableMenuItem(ID_MENUITEM_EDIT, uiItemCmdFlags);#if defined(POCKET_PC)    pMenu->EnableMenuItem(ID_MENUITEM_SHOWPASSWORD, uiItemCmdFlags);#endif    pMenu->EnableMenuItem(ID_MENUITEM_AUTOTYPE, uiItemCmdFlags);    bool bGroupSelected = false;    bool bEmptyGroupSelected = false;    if (bTreeView) {        HTREEITEM hi = m_ctlItemTree.GetSelectedItem();        bGroupSelected = (hi != NULL && !m_ctlItemTree.IsLeafNode(hi));        bEmptyGroupSelected = (bGroupSelected && !m_ctlItemTree.ItemHasChildren(hi));    }    pMenu->EnableMenuItem(ID_MENUITEM_DELETE, ((bItemSelected || bEmptyGroupSelected) ? MF_ENABLED : MF_GRAYED));    pMenu->EnableMenuItem(ID_MENUITEM_RENAME, ((bTreeView && (bItemSelected || bGroupSelected)) ? MF_ENABLED : MF_GRAYED));    pMenu->EnableMenuItem(ID_MENUITEM_ADDGROUP, (bTreeView ? MF_ENABLED : MF_GRAYED));    pMenu->CheckMenuRadioItem(ID_MENUITEM_LIST_VIEW, ID_MENUITEM_TREE_VIEW,         (bTreeView ? ID_MENUITEM_TREE_VIEW : ID_MENUITEM_LIST_VIEW), MF_BYCOMMAND);    CDC* pDC = this->GetDC();    int NumBits = ( pDC ? pDC->GetDeviceCaps(12 /*BITSPIXEL*/) : 32 );    if (NumBits < 16 && m_toolbarMode == ID_MENUITEM_OLD_TOOLBAR) {        // Less that 16 color bits available, no choice, disable menu items        pMenu->EnableMenuItem(ID_MENUITEM_NEW_TOOLBAR, MF_GRAYED | MF_BYCOMMAND);        pMenu->EnableMenuItem(ID_MENUITEM_OLD_TOOLBAR, MF_GRAYED | MF_BYCOMMAND);    } else {        // High-color screen mode so all choices available.        // (or a low-color screen, but leave choices enabled so that the user still can switch.)        pMenu->EnableMenuItem(ID_MENUITEM_NEW_TOOLBAR, MF_ENABLED | MF_BYCOMMAND);        pMenu->EnableMenuItem(ID_MENUITEM_OLD_TOOLBAR, MF_ENABLED | MF_BYCOMMAND);    }    pMenu->CheckMenuRadioItem(ID_MENUITEM_NEW_TOOLBAR, ID_MENUITEM_OLD_TOOLBAR,         m_toolbarMode, MF_BYCOMMAND);   pMenu->EnableMenuItem(ID_MENUITEM_SAVE,			m_core.IsChanged() ? MF_ENABLED : MF_GRAYED);}// helps with MRU by allowing ON_UPDATE_COMMAND_UIvoidDboxMain::OnInitMenuPopup(CMenu* pPopupMenu, UINT, BOOL) {    // http://www4.ncsu.edu:8030/~jgbishop/codetips/dialog/updatecommandui_menu.html    // This code comes from the MFC Documentation, and is adapted from CFrameWnd::OnInitMenuPopup() in WinFrm.cpp.    ASSERT(pPopupMenu != NULL);    CCmdUI state; // Check the enabled state of various menu items    state.m_pMenu = pPopupMenu;    ASSERT(state.m_pOther == NULL);    ASSERT(state.m_pParentMenu == NULL);        // Is the menu in question a popup in the top-level menu? If so, set m_pOther    // to this menu. Note that m_pParentMenu == NULL indicates that the menu is a    // secondary popup.    CMenu *hParentMenu;    if(AfxGetThreadState()->m_hTrackingMenu == pPopupMenu->m_hMenu) {        state.m_pParentMenu = pPopupMenu; // Parent == child for tracking popup.    }    else if((hParentMenu = this->GetMenu()) != NULL)    {        CWnd* pParent = this;        // Child windows don't have menus--need to go to the top!        if(pParent != NULL && (hParentMenu = pParent->GetMenu()) != NULL)        {            int nIndexMax = hParentMenu->GetMenuItemCount();            for (int nIndex = 0; nIndex < nIndexMax; nIndex++)            {                CMenu *submenu = hParentMenu->GetSubMenu(nIndex);                if(submenu != NULL && submenu->m_hMenu == pPopupMenu->m_hMenu)                {                    // When popup is found, m_pParentMenu is containing menu.                    state.m_pParentMenu = CMenu::FromHandle(hParentMenu->GetSafeHmenu());                    break;                }            }        }    }        state.m_nIndexMax = pPopupMenu->GetMenuItemCount();    for(state.m_nIndex = 0; state.m_nIndex < state.m_nIndexMax; state.m_nIndex++)    {        state.m_nID = pPopupMenu->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 = pPopupMenu->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, TRUE); // 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, FALSE);        }        // Adjust for menu deletions and additions.        UINT nCount = pPopupMenu->GetMenuItemCount();        if(nCount < state.m_nIndexMax)        {            state.m_nIndex -= (state.m_nIndexMax - nCount);            while(state.m_nIndex < nCount &&                pPopupMenu->GetMenuItemID(state.m_nIndex) == state.m_nID)            {                state.m_nIndex++;            }        }        state.m_nIndexMax = nCount;    }}#if defined(POCKET_PC)void DboxMain::OnShowPassword(){	if (SelItemOk() == TRUE)	{		CItemData			item;		CMyString			password;		CMyString			name;		CMyString			title;		CMyString			username;		CShowPasswordDlg	pwDlg( this );		item	= m_pwlist.GetAt( Find(getSelectedItem()) );		item.GetPassword(password);		item.GetName( name );		SplitName( name, title, username );		pwDlg.SetTitle( title );		pwDlg.SetPassword( password );		pwDlg.DoModal();	}}#endifLRESULT DboxMain::OnTrayNotification(WPARAM , LPARAM ){#if 0  return m_TrayIcon.OnTrayNotification(wParam, lParam);#else  return 0;#endif}void DboxMain::OnMinimize(){  ShowWindow(SW_MINIMIZE);}void DboxMain::OnUnMinimize(){  ShowWindow(SW_RESTORE);}voidDboxMain::startLockCheckTimer(){	UINT nTimer;	const UINT INTERVAL = 5000; // every 5 seconds should suffice	TRACE("startLockCheckTimer\n");	if (PWSprefs::GetInstance()->	    GetPref(PWSprefs::BoolPrefs::LockOnWindowLock )==TRUE ){			TRACE("Starting timer\n");		nTimer=SetTimer(TIMER_CHECKLOCK, INTERVAL, NULL);		TRACE("Going %d\n",nTimer);	}	else		TRACE("Not Starting\n");}BOOL DboxMain::PreTranslateMessage(MSG* pMsg){    // Do NOT pass the ESC along.    if (pMsg->message == WM_KEYDOWN && pMsg->wParam == VK_ESCAPE)    {         return TRUE;    }    return CDialog::PreTranslateMessage(pMsg);}

⌨️ 快捷键说明

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