📄 organizefavoritesdlg.cpp
字号:
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// Use of this source code is subject to the terms of the Microsoft end-user
// license agreement (EULA) under which you licensed this SOFTWARE PRODUCT.
// If you did not accept the terms of the EULA, you are not authorized to use
// this source code. For a copy of the EULA, please see the LICENSE.RTF on your
// install media.
//
#include "Precomp.h"
#ifndef NO_FAVORITES
#include "resource.h"
#include "mainwnd.h"
#include "OrganizeFavoritesDlg.h"
#include "FavInUseDlg.h"
#include "FavFolders.h"
#include "debug.h"
#include "regkeys.h"
COrgFavoritesDlg::COrgFavoritesDlg(CMainWnd* pMainWnd)
{
m_wndMainWnd = pMainWnd; // Main window object pointer
m_nOpenFolder = 0; // Index to the open folder icon
m_nCloseFolder = 0; // Index to the close folder icon
m_nURL = 0; // Index to the URl icon
m_hIml = NULL;
m_fOnRename = FALSE;
m_fOnCreate = FALSE;
m_bIsDirty = FALSE;
INIT_STR (m_szSrcPath);
INIT_STR (m_szBtnTxt);
}
COrgFavoritesDlg::~COrgFavoritesDlg()
{
m_wndMainWnd = NULL;
if (m_hIml)
{
ImageList_Destroy(m_hIml);
m_hIml = NULL;
}
if (m_wndTreeCtrl.m_hWnd)
TreeView_DeleteAllItems(m_wndTreeCtrl.m_hWnd);
m_wndTreeCtrl.Detach();
}
LRESULT COrgFavoritesDlg::OnCreate (UINT uMsg, WPARAM wParam, LPARAM lParam,BOOL& bHandled)
{
CREATESTRUCT *lpcs = NULL;
lpcs = (LPCREATESTRUCT) lParam;
return 0;
}
LRESULT COrgFavoritesDlg::OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
CenterWindow ();
m_wndTreeCtrl.Attach(GetDlgItem(IDC_FAV_TREE));
if (!m_wndMainWnd->_pIFavStorage)
return 0;
if (!m_FavHelper.InitHelper (g_hInstance,
&m_wndTreeCtrl,
m_wndMainWnd->_pIFavStorage,
MODE_ORGANIZEFAV))
return 0;
if (m_FavHelper.InitTreeViewImageLists ())
m_FavHelper.PopulateTreeControl (m_wndMainWnd->_pIFavStorage->GetRootFolder());
else
return 0;
return 1;
}
LRESULT COrgFavoritesDlg::OnBeginEditLabel(int idCtrl, LPNMHDR pnmh, BOOL& bHandled)
{
return m_FavHelper.BeginEditLabel (idCtrl, pnmh, bHandled);
}
LRESULT COrgFavoritesDlg::OnEndEditLabel(int idCtrl, LPNMHDR pnmh, BOOL& bHandled)
{
return m_FavHelper.EndEditLabel (idCtrl, pnmh, bHandled, m_fOnRename, m_szSrcPath);
}
LRESULT COrgFavoritesDlg::OnItemExpand(int idCtrl, LPNMHDR pnmh, BOOL& bHandled)
{
LPNM_TREEVIEW tView = (LPNM_TREEVIEW)pnmh;
if (TreeView_GetChild (m_wndTreeCtrl.m_hWnd,
tView->itemNew.hItem) == NULL)
return TRUE;
return FALSE;
}
LRESULT COrgFavoritesDlg::OnDeleteItem(int idCtrl, LPNMHDR pnmh, BOOL& bHandled)
{
LPNMTREEVIEW pNMTreeView = (LPNMTREEVIEW) pnmh;
TVITEM tv = pNMTreeView->itemOld;
if (tv.lParam != NULL)
{
delete[] reinterpret_cast<LPTSTR>(tv.lParam);
tv.lParam = NULL;
}
bHandled = FALSE;
return 1;
}
BOOL COrgFavoritesDlg::DeleteItem (HTREEITEM hTreeItem)
{
TVITEM tvi;
TVITEM tviParent;
HKEY hRegKey = NULL;
BOOL bRetVal = TRUE;
TCHAR szPath[MAX_REGKEY_LEN-1];
INIT_STR (szPath);
// Check if this is a leaf item or a folder
if (m_FavHelper.IsLeafItem(hTreeItem,tvi)) // Leaf item in the tree
{
if (m_FavHelper.GetParentItem (hTreeItem, tviParent))
wsprintf (szPath,L"%s\\%s",reinterpret_cast<LPTSTR>(tviParent.lParam),
tvi.pszText);
else
wsprintf (szPath,L"%s\\%s",m_wndMainWnd->_pIFavStorage->
GetRootFolder(),
tvi.pszText);
}
else
wcscpy (szPath, reinterpret_cast<LPTSTR>(tvi.lParam));
if (m_wndMainWnd->_pIFavStorage->
DeleteFolder (szPath) != ERROR_SUCCESS)
goto ERR_RET;
// Delete the item in tree view
if (!TreeView_DeleteItem(m_wndTreeCtrl.m_hWnd,hTreeItem))
goto ERR_RET;
goto RETURN;
ERR_RET:
bRetVal = FALSE;
RETURN:
if (tvi.pszText != NULL)
{
delete[] tvi.pszText;
tvi.pszText = NULL;
}
return bRetVal;
}
LRESULT COrgFavoritesDlg::OnCreateFolder (WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
{
if (ERROR_SUCCESS == m_FavHelper.CreateFolder (wNotifyCode, wID, hWndCtl, bHandled))
{
m_fOnCreate = TRUE;
m_bIsDirty = TRUE;
}
return 0;
}
LRESULT COrgFavoritesDlg::OnDelete (WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL &bHandled)
{
HTREEITEM hCurItem = NULL;
TCHAR szTxt[128];
TCHAR szTitle[32];
INIT_STR (szTxt);
INIT_STR (szTitle);
// Get the selected item
if (NULL == (hCurItem = TreeView_GetSelection(m_wndTreeCtrl.m_hWnd)))
return 0;
// Display the dialog to confirm deletion
if ((0 != LoadString(g_hInstance, IDS_CONFIRM_DELETE_TEXT, szTxt, 128)) &&
(0 != LoadString(g_hInstance, IDS_CONFIRM_DELETE_TITLE, szTitle, 32)))
{
if (IDYES == MessageBox(szTxt, szTitle, MB_YESNO|MB_ICONQUESTION))
DeleteItem ( hCurItem );
}
else
return 0;
m_bIsDirty = TRUE;
return 0;
}
LRESULT COrgFavoritesDlg::OnMoveTo (WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL &bHandled)
{
HTREEITEM hItem = NULL;
TVITEM tv;
TVITEM tvParent;
TCHAR *szTmpStr;
TCHAR *szParent;
CFavFoldersDlg dlg (this,IDS_MOVEFAV_TITLE,IDS_MOVEFAV_MESSAGE,FALSE);
long lRes = 0;
szTmpStr = new TCHAR[MAX_REGKEY_LEN];
szParent = new TCHAR[MAX_REGKEY_LEN];
if(!szTmpStr || !szParent)
goto Cleanup;
INIT_STR (szTmpStr);
INIT_STR (szParent);
// Get the selected item
if (NULL == (hItem = TreeView_GetSelection(m_wndTreeCtrl.m_hWnd)))
goto Cleanup;
if (m_FavHelper.IsLeafItem(hItem,tv))
{
if (m_FavHelper.GetParentItem(hItem, tvParent))
{
wsprintf (m_szSrcPath, L"%s\\%s",reinterpret_cast<LPTSTR>(tvParent.lParam),tv.pszText);
wcscpy (szParent, reinterpret_cast<LPTSTR>(tvParent.lParam));
}
else
{
wsprintf (m_szSrcPath, L"%s\\%s",m_wndMainWnd->_pIFavStorage->GetRootFolder(),tv.pszText);
wcscpy (szParent,m_wndMainWnd->_pIFavStorage->GetRootFolder());
}
}
else
{
if (m_FavHelper.GetParentItem(hItem, tvParent))
wcscpy (szParent, reinterpret_cast<LPTSTR>(tvParent.lParam));
else
wcscpy (szParent, m_wndMainWnd->_pIFavStorage->GetRootFolder());
wcscpy (m_szSrcPath, reinterpret_cast<LPTSTR>(tv.lParam));
}
dlg.DoModal();
if (NULL != dlg.GetDestinationFolder())
wcscpy (szTmpStr,dlg.GetDestinationFolder());
if (!szTmpStr[0])
goto Cleanup;
// If source and destination are same, popup an error dialog
if (!_tcsicmp(m_szSrcPath,szTmpStr)||
!_tcsicmp(szTmpStr,szParent))
{
TCHAR szMessage[128];
TCHAR szTitle[32];
INIT_STR (szMessage);
INIT_STR (szTitle);
// Display a message box
if ((0 != LoadString(g_hInstance, IDS_MOVFAV_FAIL_MSG, szMessage, 128)) &&
(0 != LoadString(g_hInstance, IDS_MOVFAV_FAIL_TITLE, szTitle, 32)))
MessageBox(szMessage,szTitle,MB_OK|MB_ICONERROR);
else
goto Cleanup;
}
else
{
if (ERROR_SUCCESS == m_wndMainWnd->_pIFavStorage->
CopyFolder (m_szSrcPath, szTmpStr))
{
if (ERROR_SUCCESS == m_wndMainWnd->_pIFavStorage->
DeleteFolder (m_szSrcPath))
{
// Refresh the tree view
TreeView_DeleteAllItems(m_wndTreeCtrl.m_hWnd);
m_wndTreeCtrl.Invalidate();
m_wndTreeCtrl.RedrawWindow();
m_wndTreeCtrl.UpdateWindow();
m_FavHelper.PopulateTreeControl(m_wndMainWnd->_pIFavStorage->GetRootFolder());
}
}
}
m_bIsDirty = TRUE;
lRes = 1;
Cleanup:
delete[] szTmpStr;
delete[] szParent;
return lRes;
}
LRESULT COrgFavoritesDlg::OnRename (WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL &bHandled)
{
HTREEITEM hCurItem = NULL;
TVITEM tv;
TVITEM tvParent;
// Get the selected item
if (NULL == (hCurItem = TreeView_GetSelection(m_wndTreeCtrl.m_hWnd)))
return 0;
// Store the information about registry key for this
INIT_STR(m_szSrcPath);
if (m_FavHelper.IsLeafItem(hCurItem,tv))
{
if (m_FavHelper.GetParentItem(hCurItem, tvParent))
wsprintf (m_szSrcPath, L"%s\\%s",reinterpret_cast<LPTSTR>(tvParent.lParam),tv.pszText);
else
wsprintf (m_szSrcPath, L"%s\\%s",m_wndMainWnd->_pIFavStorage->GetRootFolder(),tv.pszText);
}
else
wcscpy (m_szSrcPath, reinterpret_cast<LPTSTR>(tv.lParam));
m_fOnRename = TRUE;
// Make the user edit this item
if (hCurItem != NULL)
{
m_FavHelper.SetNewItem(hCurItem);
m_wndTreeCtrl.SetFocus();
TreeView_EditLabel(m_wndTreeCtrl.m_hWnd, hCurItem);
}
m_bIsDirty = TRUE;
return 0;
}
BOOL COrgFavoritesDlg::IsRegistryChanged()
{
return m_bIsDirty;
}
LRESULT COrgFavoritesDlg::OnOk (WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL &bHandled)
{
EndDialog (IDOK);
return 1;
}
LRESULT COrgFavoritesDlg::OnCancel (WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL &bHandled)
{
EndDialog (0);
return 1;
}
#endif // ndef NO_FAVORITES
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -