Click here to Skip to main content
15,896,497 members
Articles / Desktop Programming / ATL

MultiCopier Software

Rate me:
Please Sign up or sign in to vote.
4.90/5 (20 votes)
29 Sep 20021 min read 98.6K   3.8K   68  
The fastest, easy way to copy files from different folders at the same time
//-----------------------------------------------------------------------//
// 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											 //
//-----------------------------------------------------------------------//

// CopierMenu.cpp : Implementation of CCopierMenu
#include "stdafx.h"
#include "Copier.h"
#include "CopierMenu.h"
#include "AboutDlg.h"
#include "options.h"
/////////////////////////////////////////////////////////////////////////////
// CCopierMenu


HRESULT CCopierMenu::Initialize(LPCITEMIDLIST pidlFolder,LPDATAOBJECT lpdobj, HKEY hkeyProgID)
{
	// Get the file associated with this object, if applicable.

	STGMEDIUM   medium;
	FORMATETC   fe = {CF_HDROP, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL};
	UINT        uCount;      
	TCHAR szPath[MAX_PATH];    // path to file or folder in question

	if(SUCCEEDED(lpdobj->GetData(&fe, &medium)))
	{         
		// Get the file name from the HDROP.
		uCount = DragQueryFile((HDROP)medium.hGlobal, (UINT)-1, NULL, 0);

		// store a list of filenames
		for (UINT i=0;i<uCount;i++)
		{
			DragQueryFile((HDROP)medium.hGlobal, i, szPath, sizeof(szPath));
			m_listPaths.Add (szPath);
		}

		ReleaseStgMedium(&medium);      
	}
	return NOERROR;
}

HRESULT CCopierMenu::QueryContextMenu(HMENU hmenu, UINT indexMenu, UINT idCmdFirst, UINT idCmdLast, UINT uFlags)
{
    if ( (uFlags & CMF_DEFAULTONLY))
	{
        return MAKE_HRESULT ( SEVERITY_SUCCESS, FACILITY_NULL, 0 );
	}
	LoadFile(&source);
	int uCmd=idCmdFirst;
	CMenu main;main.Attach (hmenu);
	CMenu menu,*menu2;
	HMENU m=::LoadMenu (_Module.GetResourceInstance(), MAKEINTRESOURCE(IDR_COPIER));
	if(m!=NULL)
	{
		menu.Attach (m);
		CString s;
		menu2=menu.GetSubMenu (0);
		menu.Detach ();
		UINT state = menu2->GetMenuState(2, MF_BYPOSITION);
		CString empty;
		menu2->GetMenuString(2,empty,MF_BYPOSITION);
		empty.Format ("%s (%d)",(LPSTR)(LPCSTR)empty,source.GetSize ());
		menu2->ModifyMenu (2,state|MF_BYPOSITION|MF_STRING,0,empty);

		//Modify the menu
		int mcount=menu2->GetMenuItemCount ();
		for(int i=0;i<mcount;i++)
		{
			//	MENUITEMINFO info;
			//menu2->GetMenuItemInfo(i,&info,TRUE);
			UINT state = menu2->GetMenuState(i, MF_BYPOSITION);
			ASSERT(state != 0xFFFFFFFF);
			if(!(state & MF_SEPARATOR))
			{
				CString menustring="";
			menu2->GetMenuString(i,menustring,MF_BYPOSITION);
			menu2->ModifyMenu (i,state|MF_BYPOSITION ,uCmd++,menustring);
			}
		}

		//////////////////
		main.InsertMenu (indexMenu,MF_SEPARATOR|MF_BYPOSITION,0);
		indexMenu++;
		main.InsertMenu (indexMenu,MF_STRING|MF_POPUP|MF_BYPOSITION,(UINT)menu2->Detach (),"MultiCopier");
		indexMenu++;//nAdd++;
		main.InsertMenu (indexMenu,MF_SEPARATOR|MF_BYPOSITION,0);
		indexMenu++;
		menu.Detach ();main.Detach ();
	}
	return MAKE_HRESULT ( SEVERITY_SUCCESS, FACILITY_NULL,uCmd- idCmdFirst+1 );
}

HRESULT CCopierMenu::InvokeCommand(LPCMINVOKECOMMANDINFO lpici)
{
	if (!HIWORD(lpici->lpVerb))    
	{      
		int n=LOWORD(lpici->lpVerb);
		switch (n)       
		{ 
		case 0:
			{
			//	::AfxMessageBox ("cool",MB_OK);
				int uCount = m_listPaths.GetSize();
				
				// store a list of filenames
				for (UINT i=0;i<uCount;i++)
				{
					source.Add (m_listPaths.GetAt(i) );
				}
				SaveFile(&source);
			}
			break;
		case 1:
			source.RemoveAll ();
			SaveFile(&source);
			break;
		case 2:
			{
				COptions dlg;
				dlg.DoModal ();
			}
		break;
		case 3:
				::AfxBeginThread(SendMail,0,
			THREAD_PRIORITY_NORMAL, 0, 0);
					break;
		case 4:
			{
				CString file;
				::GetModuleFileName(::GetModuleHandle ("Copier"),file.GetBuffer (256),255);
				file.ReleaseBuffer (256);
				LPSTR folder=file.GetBuffer (file.GetLength ());
				PathRemoveFileSpec(folder);
				CString f=folder;
				
				ShellExecute(NULL,"open",f+"\\MultiCopier Help.chm",NULL,NULL,SW_MAXIMIZE );
			}
			break;
		case 5:
		CAboutDlg dlg;
			dlg.DoModal ();
			break;
		}
	}

	return NOERROR;
}

HRESULT CCopierMenu::GetCommandString(UINT idCmd, UINT uType,UINT* pwReserved,LPSTR pszName,UINT cchMax)
{
	return NOERROR;
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
Egypt Egypt
My name is Ahmed Ismaiel Zakaria
i'm programming c++ & visual c++ (MFC )& Visual basic and recently COM,ATL
Student in Faculty of computer and information science in Egypt

Comments and Discussions