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

📄 selectfiles.h

📁 一个不同目录中多个文件拷贝的助手程序
💻 H
字号:
//-----------------------------------------------------------------------//
// This is a part of the Multicopier.									 //	
// Autor  :  Ahmed Ismaiel Zakaria										 //
// (C) 2002 FCIS Egypt  All rights reserved								 //
// This code is provided "as is", with absolutely no warranty expressed  //
// or implied. Any use is at your own risk.								 //		
// You must obtain the author's consent before you can include this code //
// in a software library.												 //
// If the source code in  this file is used in any application			 //
// then acknowledgement must be made to the author of this program		 //	
// ahmed_ismaiel@hotmail.com											 //
//-----------------------------------------------------------------------//

// SelectFiles.h : Declaration of the CSelectFiles

#ifndef __SELECTFILES_H_
#define __SELECTFILES_H_

#include "resource.h"       // main symbols
#include <atlhost.h>
#include "BrowseForFolder.h"
#include "CShellFileOp.h"

/////////////////////////////////////////////////////////////////////////////
// CSelectFiles
class CSelectFiles : 
public CAxDialogImpl<CSelectFiles>
{
public:
	CSelectFiles()
	{
	}
	
	~CSelectFiles()
	{
		m_small.Detach ();
	}
	
	enum { IDD = IDD_SELECTFILES };
	CStringArray *m_source;
	CString destnation;
	CImageList m_small;
	BEGIN_MSG_MAP(CSelectFiles)
		MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
		
		COMMAND_ID_HANDLER(IDOK, OnOK)
		COMMAND_ID_HANDLER(IDC_COPY, OnCopy)
		COMMAND_ID_HANDLER(IDC_MOVE, OnMove)
		COMMAND_ID_HANDLER(IDC_DELETE, OnDelete)
		COMMAND_ID_HANDLER(IDC_BROWSE, OnBrowse)
		END_MSG_MAP()
		//MESSAGE_HANDLER(WM_HELP ,OnHelp
		// Handler prototypes:
		//  LRESULT MessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
		//  LRESULT CommandHandler(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled);
		//  LRESULT NotifyHandler(int idCtrl, LPNMHDR pnmh, BOOL& bHandled);
		
		LRESULT OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
	{
		(CWnd::FromHandle (GetDlgItem(IDC_FOLDERNAME)))->SetWindowText(destnation);
		HICON icon=::LoadIcon(_Module.GetResourceInstance(), MAKEINTRESOURCE(IDI_BROWSE));
		CButton b;b.Attach(GetDlgItem(IDC_BROWSE));
		b.SetIcon(icon);
		b.Detach();
		CListCtrl	m_list;
		m_list.Attach (GetDlgItem(IDC_LIST1));
		m_list.InsertColumn ( 0,"File/folder names",LVCFMT_LEFT,400);
		//add the image list
			SHFILEINFO    shfi;
			m_small.Attach((HIMAGELIST)SHGetFileInfo(
				"c:\\",0,&shfi,
				sizeof(SHFILEINFO),
				SHGFI_SYSICONINDEX ));
		m_list.SetImageList(&m_small, LVSIL_SMALL);
		//
		int uCount=m_source->GetSize ();
		for(int i=0;i<uCount;i++)
		{
			CString s=m_source->GetAt (i);
			SHFILEINFO    shfi;
			if(PathIsDirectory((LPCTSTR)s))
			{
				UINT flags = SHGFI_SYSICONINDEX  | SHGFI_USEFILEATTRIBUTES;//| SHGFI_SMALLICON
				SHGetFileInfo(_T("TMP") ,  FILE_ATTRIBUTE_DIRECTORY , &shfi, sizeof(SHFILEINFO), flags);
			}
			else
			{
			UINT flags = SHGFI_SYSICONINDEX  | SHGFI_USEFILEATTRIBUTES;//| SHGFI_SMALLICON
			SHGetFileInfo(s ,  FILE_ATTRIBUTE_NORMAL, &shfi, sizeof(SHFILEINFO), flags);
			}
			int n=m_list.InsertItem ( i,(LPCTSTR)s,shfi.iIcon);
			if(n==-1)
			{AfxMessageBox ("bd");
			}
		}
		
		m_list.Detach ();
		return 1;  // Let the system set the focus
	}
	
	LRESULT OnOK(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
	{
		CListCtrl	m_list;m_list.Attach (GetDlgItem(IDC_LIST1));
		m_list.SetImageList((CImageList*)0, LVSIL_SMALL);
		m_source->RemoveAll ();
		int uCount=m_list.GetItemCount();
		for(int i=0;i<uCount;i++)
		{
			m_source->Add( m_list.GetItemText (i,0));
		}
		m_list.Detach ();
		EndDialog(wID);
		return 0;
	}
	LRESULT OnBrowse(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled) 
	{
		CBrowseForFolder bf;
		CString Path;
		bf.strTitle="Choose a folder";
		if (bf.GetFolder(Path))
			(CWnd::FromHandle (GetDlgItem(IDC_FOLDERNAME)))->SetWindowText(Path);
		return 0;
	}
	
	LRESULT OnDelete(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled) 
	{
		CListCtrl	m_list;m_list.Attach (GetDlgItem(IDC_LIST1));
		POSITION pos=m_list.GetFirstSelectedItemPosition ();
		while(pos!=NULL)
		{
			int n=	m_list.GetNextSelectedItem (pos);
			m_list.DeleteItem (n);
		}
		m_list.Detach ();
		return 0;
	}
	
	LRESULT OnMove(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled) 
	{
		// TODO: Add your control notification handler code here
		CListCtrl	m_list;
		CShellFileOp op;
		op.SetOperationFlags ( FO_MOVE, CWnd::FromHandle (::GetDesktopWindow ()),
			FOF_RENAMEONCOLLISION );
		CString dest;
		(CWnd::FromHandle (GetDlgItem(IDC_FOLDERNAME)))->GetWindowText(dest);
		if(PathFileExists(dest))
			op.AddDestFile ( dest );
		else
		{AfxMessageBox ("Path not exist") ;return 0;}
		m_list.Attach (GetDlgItem(IDC_LIST1));
		POSITION pos=m_list.GetFirstSelectedItemPosition ();
		while(pos!=NULL)
		{
			int n=	m_list.GetNextSelectedItem (pos);
			op.AddSourceFile ( m_list.GetItemText (n,0));
			m_list.DeleteItem (n);
		}
		m_list.Detach ();
		BOOL bSuccess, bAPICalled = FALSE, bAborted = FALSE;
		int  nAPIReturn = 0;
		bSuccess = op.Go ( &bAPICalled, &nAPIReturn, &bAborted );
		return 0;
	}
	
	LRESULT OnCopy(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled) 
	{
		CListCtrl	m_list;
		CRegDWORD  myword("Software\\Company\\Subkey\\mydword", 0, TRUE, HKEY_LOCAL_MACHINE);
		CShellFileOp op;
		op.SetOperationFlags ( FO_COPY, CWnd::FromHandle (::GetDesktopWindow ()),
			FOF_RENAMEONCOLLISION );
		CString dest;
		(CWnd::FromHandle (GetDlgItem(IDC_FOLDERNAME)))->GetWindowText(dest);
		if(PathFileExists(dest))
			op.AddDestFile ( dest );
		else
		{AfxMessageBox ("Path not exist") ;return 0;}
		m_list.Attach (GetDlgItem(IDC_LIST1));
		POSITION pos=m_list.GetFirstSelectedItemPosition ();
		while(pos!=NULL)
		{
			int n=	m_list.GetNextSelectedItem (pos);
			
			op.AddSourceFile ( m_list.GetItemText (n,0));
			if(1==(DWORD)myword)
			{
				m_list.DeleteItem (n);
			}//
		}
		m_list.Detach ();
		BOOL bSuccess, bAPICalled = FALSE, bAborted = FALSE;
		int  nAPIReturn = 0;
		bSuccess = op.Go ( &bAPICalled, &nAPIReturn, &bAborted );
		return 0;
	}
};

#endif //__SELECTFILES_H_

⌨️ 快捷键说明

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