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

📄 dboxview.cpp

📁 Password Safe Password Safe is a password database utility. Users can keep their passwords securely
💻 CPP
📖 第 1 页 / 共 3 页
字号:
    if (item >= 0) {        menu.LoadMenu(IDR_POPMENU);        CMenu* pPopup = menu.GetSubMenu(0);        ASSERT(pPopup != NULL);        ASSERT(itemData != NULL);        if (!ExtractURL(itemData->GetNotes(), m_BrowseURL)) {            ASSERT(m_BrowseURL.IsEmpty());            pPopup->EnableMenuItem(ID_MENUITEM_BROWSE, MF_GRAYED);        } else {            ASSERT(!m_BrowseURL.IsEmpty());            pPopup->EnableMenuItem(ID_MENUITEM_BROWSE, MF_ENABLED);        }        pPopup->TrackPopupMenu(dwTrackPopupFlags, point.x, point.y, this); // use this window for commands    } // if (item >= 0)}void DboxMain::OnKeydownItemlist(NMHDR* pNMHDR, LRESULT* pResult) {   LV_KEYDOWN *pLVKeyDow = (LV_KEYDOWN*)pNMHDR;   switch (pLVKeyDow->wVKey) {   case VK_DELETE:      OnDelete();      break;   case VK_INSERT:      OnAdd();      break;   }   *pResult = 0;}#if !defined(POCKET_PC)voidDboxMain::OnSetfocusItemlist( NMHDR *, LRESULT *) {    const UINT statustext = IDS_STATMESSAGE;    if (m_toolbarsSetup == FALSE)        return;    m_statusBar.SetIndicators(&statustext, 1);	    // Make a sunken or recessed border around the first pane    m_statusBar.SetPaneInfo(0, m_statusBar.GetItemID(0), SBPS_STRETCH, NULL);}voidDboxMain::OnKillfocusItemlist( NMHDR *, LRESULT *) {   const UINT statustext = IDS_STATCOMPANY;   if (m_toolbarsSetup == FALSE)      return;   m_statusBar.SetIndicators(&statustext, 1);   // Make a sunken or recessed border around the first pane   m_statusBar.SetPaneInfo(0, m_statusBar.GetItemID(0), SBPS_STRETCH, NULL);}#endif////////////////////////////////////////////////////////////////////////////////// NOTE!// itemData must be the actual item in the item list.  if the item is remove// from the list, it must be removed from the display as well and vice versa.// a pointer is associated with the item in the display that is used for// sorting.// {kjp} We could use itemData.GetNotes(CString&) to reduce the number of// {kjp} temporary objects created and copied.//int DboxMain::insertItem(CItemData &itemData, int iIndex){  if (itemData.GetDisplayInfo() != NULL &&      ((DisplayInfo *)itemData.GetDisplayInfo())->list_index != -1) {    // true iff item already displayed    return iIndex;  }  int iResult = iIndex;  if (iResult < 0) {    iResult = m_ctlItemList.GetItemCount();  }  CMyString title = itemData.GetTitle();  CMyString username = itemData.GetUser();  iResult = m_ctlItemList.InsertItem(iResult, title);  if (iResult < 0) {    // TODO: issue error here...    return iResult;  }  DisplayInfo *di = (DisplayInfo *)itemData.GetDisplayInfo();  if (di == NULL)    di = new DisplayInfo;  di->list_index = iResult;  {    HTREEITEM ti;    CMyString treeDispString = title;    CMyString user = itemData.GetUser();    if (!user.IsEmpty()) {      treeDispString += _T(" [");      treeDispString += user;      treeDispString += _T("]");    }    // get path, create if necessary, add title as last node    ti = m_ctlItemTree.AddGroup(itemData.GetGroup());    ti = m_ctlItemTree.InsertItem(treeDispString, ti, TVI_SORT);    m_ctlItemTree.SetItemImage(ti, CMyTreeCtrl::LEAF, CMyTreeCtrl::LEAF);    m_ctlItemTree.SetItemData(ti, (DWORD)&itemData);    di->tree_item = ti;  }  itemData.SetDisplayInfo((void *)di);  // get only the first line for display  CMyString strNotes = itemData.GetNotes();  int iEOL = strNotes.Find('\r');  if (iEOL >= 0 && iEOL < strNotes.GetLength()) {    CMyString strTemp = strNotes.Left(iEOL);    strNotes = strTemp;  }  m_ctlItemList.SetItemText(iResult, 1, username);  m_ctlItemList.SetItemText(iResult, 2, strNotes);  m_ctlItemList.SetItemData(iResult, (DWORD)&itemData);  if (m_bShowPasswordInList) {    m_ctlItemList.SetItemText(iResult, 3, itemData.GetPassword());  }  return iResult;}CItemData *DboxMain::getSelectedItem(){    CItemData *retval = NULL;    if (m_ctlItemList.IsWindowVisible()) {        // flattened list mode.        POSITION p = m_ctlItemList.GetFirstSelectedItemPosition();        if (p) {            int i = m_ctlItemList.GetNextSelectedItem(p);            retval = (CItemData *)m_ctlItemList.GetItemData(i);            ASSERT(retval != NULL);            DisplayInfo *di = (DisplayInfo *)retval->GetDisplayInfo();            ASSERT(di != NULL && di->list_index == i);        }    } else {        // heirarchy tree mode; go from HTREEITEM to index        HTREEITEM ti = m_ctlItemTree.GetSelectedItem();        if (ti != NULL) {            retval = (CItemData *)m_ctlItemTree.GetItemData(ti);            if (retval != NULL) {  // leaf node                DisplayInfo *di = (DisplayInfo *)retval->GetDisplayInfo();                ASSERT(di != NULL && di->tree_item == ti);            }        }        }    return retval;}voidDboxMain::ClearData(void){    // Iterate over item list, delete DisplayInfo    POSITION listPos = m_core.GetFirstEntryPosition();    while (listPos != NULL) {        CItemData &ci = m_core.GetEntryAt(listPos);        delete ci.GetDisplayInfo(); // no need to Set to NULL        m_core.GetNextEntry(listPos);    }    m_core.ClearData();    //Because GetText returns a copy, we cannot do anything about the names    if (m_windowok) {        // For long lists, this is painful, so we disable updates        m_ctlItemList.LockWindowUpdate();        m_ctlItemList.DeleteAllItems();        m_ctlItemList.UnlockWindowUpdate();        m_ctlItemTree.LockWindowUpdate();        m_ctlItemTree.DeleteAllItems();        m_ctlItemTree.UnlockWindowUpdate();    }}void DboxMain::OnColumnClick(NMHDR* pNMHDR, LRESULT* pResult) {  NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;  if (m_iSortedColumn == pNMListView->iSubItem) {    m_bSortAscending = !m_bSortAscending;  }  else {    m_iSortedColumn = pNMListView->iSubItem;    m_bSortAscending = true;  }  m_ctlItemList.SortItems(CompareFunc, (LPARAM)this);  FixListIndexes(m_ctlItemList);  *pResult = 0;}voidDboxMain::OnListView() {   SetListView();}voidDboxMain::OnTreeView() {   SetTreeView();}voidDboxMain::SetListView(){  m_ctlItemTree.ShowWindow(SW_HIDE);  m_ctlItemList.ShowWindow(SW_SHOW);  PWSprefs::GetInstance()->SetPref(PWSprefs::StringPrefs::LastView,				   _T("list"));}voidDboxMain::SetTreeView(){  m_ctlItemList.ShowWindow(SW_HIDE);  m_ctlItemTree.ShowWindow(SW_SHOW);  PWSprefs::GetInstance()->SetPref(PWSprefs::StringPrefs::LastView,				   _T("tree"));}voidDboxMain::OnOldToolbar() {    PWSprefs::GetInstance()->SetPref(PWSprefs::BoolPrefs::UseNewToolbar, false);    SetToolbar(ID_MENUITEM_OLD_TOOLBAR);}voidDboxMain::OnNewToolbar() {    PWSprefs::GetInstance()->SetPref(PWSprefs::BoolPrefs::UseNewToolbar, true);    SetToolbar(ID_MENUITEM_NEW_TOOLBAR);}voidDboxMain::SetToolbar(int menuItem){    UINT Flags = 0;    CBitmap bmTemp;     COLORREF Background = RGB(192, 192, 192);    switch (menuItem) {        case ID_MENUITEM_NEW_TOOLBAR: {            int NumBits = 32;            CDC* pDC = this->GetDC();            if ( pDC )  {                NumBits = pDC->GetDeviceCaps(12 /*BITSPIXEL*/);            }            if (NumBits >= 32) {                bmTemp.LoadBitmap(IDR_MAINBAR);                Flags = ILC_MASK | ILC_COLOR32;            } else {                bmTemp.LoadBitmap(IDB_TOOLBAR1);                Flags = ILC_MASK | ILC_COLOR8;                Background = RGB( 196,198,196 );            }            break;        }        case ID_MENUITEM_OLD_TOOLBAR:            bmTemp.LoadBitmap(IDB_TOOLBAR2);            Flags = ILC_MASK | ILC_COLOR8;            break;        default:            ASSERT(false);            return;    }    m_toolbarMode = menuItem;    CToolBarCtrl& tbcTemp = m_wndToolBar.GetToolBarCtrl();    CImageList ilTemp;     ilTemp.Create(16, 16, Flags, 10, 10);    ilTemp.Add(&bmTemp, Background);    tbcTemp.SetImageList(&ilTemp);    ilTemp.Detach();    bmTemp.Detach();    m_wndToolBar.Invalidate();    CRect rect;    RepositionBars(AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST, 0);    RepositionBars(AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST, 0, reposQuery, &rect);    m_ctlItemList.MoveWindow(&rect, TRUE);    m_ctlItemTree.MoveWindow(&rect, TRUE); // Fix Bug 940585}voidDboxMain::OnTimer(UINT nIDEvent ){			    if(nIDEvent==TIMER_CHECKLOCK){      /*       * Since we clear the data, any unchanged changes will be lost,       * so we force a save if database is modified, and fail       * to lock if the save fails.       * Also, if m_LockDisabled is set, do nothing - this is set when       * a dialog box is open.       */        if(IsWorkstationLocked() &&	   (!m_core.IsChanged() || Save() == PWScore::SUCCESS) &&	   !m_LockDisabled){            TRACE("locking database\n");            ClearData();            if(IsWindowVisible()){                ShowWindow(SW_MINIMIZE);            }            m_needsreading = true;            KillTimer(TIMER_CHECKLOCK);        }    }}// This function determines if the workstation is locked.BOOL DboxMain::IsWorkstationLocked(){    HDESK hDesktop;     BOOL Result = false;    hDesktop = OpenDesktop("default", 0, false, DESKTOP_SWITCHDESKTOP);    if( hDesktop != 0 ) {        // SwitchDesktop fails if hDesktop invisible, screensaver or winlogin.        Result = ! SwitchDesktop(hDesktop);        CloseDesktop(hDesktop);    }    return Result;}// onAutoType handles menu item ID_MENUITEM_AUTOTYPEvoidDboxMain::OnAutoType(){	if (SelItemOk() == TRUE)	{		CItemData *ci = getSelectedItem();		ASSERT(ci != NULL);		CMyString AutoCmd = ci->GetNotes();		// get the notes and then extract te autotype command			ExtractAutoTypeCmd(AutoCmd);				if(AutoCmd.IsEmpty()){ 			// checking for user and password for default settings 			if(!ci->GetPassword().IsEmpty()){ 				if(!ci->GetUser().IsEmpty()) 					AutoCmd="\\u\\t\\p\\n"; 				else 					AutoCmd="\\p\\n"; 			} 					}				CMyString tmp;				char curChar;			CKeySend ks;		ks.ResetKeyboardState();		ks.SetDelay(10);		ShowWindow(SW_MINIMIZE);		for(int n=0; n<AutoCmd.GetLength();n++){			curChar=AutoCmd[n];			if(curChar=='\\'){				n++;				if(n<AutoCmd.GetLength())					curChar=AutoCmd[n];					switch(curChar){					case '\\':						tmp+='\\';						break;					case 'n':case 'r':						tmp+='\r';						break;					case 't':						tmp+='\t';						break;					case 'u':						tmp+= ci->GetUser();						break;					case 'p':						tmp+=ci->GetPassword();						break;					case 'd':						ks.SendString(tmp);												tmp="";						int c;						int newdelay;												newdelay=0;											for(n++,c=1;n<AutoCmd.GetLength() && c < 1000;c*=10,n++)						{														if(isdigit(AutoCmd[n])){								newdelay+=c*(AutoCmd[n]-'0');							} else {								break;							}								}						n--;														ks.SetAndDelay(newdelay);						break;					default:						tmp+="\\"+curChar;						break;					}			}			else				tmp+=curChar;		}								ks.SendString(tmp);	}}void DboxMain::ExtractAutoTypeCmd(CMyString &str){    int left = str.Find(_T("autotype:"));    if (left == -1) {        str = _T("");     } else {        CString tmp(str);        tmp = tmp.Mid(left+9); // throw out everything left of "autotype:"        int right = tmp.FindOneOf(_T("\r\n"));        if (right != -1) {            tmp = tmp.Left(right);            str = CMyString(tmp);        } else {            str=CMyString(tmp);        }    }}

⌨️ 快捷键说明

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