Click here to Skip to main content
15,905,679 members
Please Sign up or sign in to vote.
2.33/5 (3 votes)
See more:
Hi

In the drag and drop functionality, i want to copy a file into a folder in a drive, if the file type and the folder type is similar the drop should occur otherwise the drop should fail.
For eg:
I want to copy a .txt/.java/.cpp file to text/java/cpp folder then only the copy should occur (i.e the folder type and the file extention type should be same)otherwise the copying should fail.
What i mean to say here is when .txt file is copied to text folder the copy should occur, if it is copied to java or cpp folder the copy should not occur.

NOTE: The functionality is happen from one drive to other drive.(i.e one explorer to another explorer)
C++
#pragma region IShellExtInit

// Initialize the drag and drop handler.
IFACEMETHODIMP FileDragDropExt::Initialize(
    LPCITEMIDLIST pidlFolder, LPDATAOBJECT pDataObj, HKEY hKeyProgID)
{
    // Get the directory where the file is dropped to.
    if (!SHGetPathFromIDList(pidlFolder, this->m_szTargetDir))
    {
		return E_FAIL;
    }

    // Get the file(s) being dragged.
    if (NULL == pDataObj)
    {
        return E_INVALIDARG;
    }

    HRESULT hr = E_FAIL;

    FORMATETC fe = { CF_HDROP, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL };
    STGMEDIUM stm;

    // The pDataObj pointer contains the objects being acted upon. In this 
    // example, we get an HDROP handle for enumerating the dragged files and 
    // folders.
    if (SUCCEEDED(pDataObj->GetData(&fe, &stm)))
    {
        // Get an HDROP handle.
        HDROP hDrop = static_cast<hdrop>(GlobalLock(stm.hGlobal));
        if (hDrop != NULL)
        {
            // Determine how many files are involved in this operation. This 
            // code sample displays the menu item when only one file (not 
            // directory) is dragged.
            UINT nFiles = DragQueryFile(hDrop, 0xFFFFFFFF, NULL, 0);
            if (nFiles == 1)
            {
                // Get the path of the file.
                if (0 != DragQueryFile(hDrop, 0, m_szSrcFile, ARRAYSIZE(m_szSrcFile)))
                {
                    // The path must not be a directory because hard link is only 
                    // for files, not directories.
                    if (!PathIsDirectory(m_szSrcFile))
                    {
                        hr = S_OK;
                    }

						TCHAR srcfile[210];
			StringCchPrintf(srcfile, ARRAYSIZE(srcfile), 
				L"%s", m_szSrcFile);//contains source path drive upto 8 elements
		
			TCHAR szMessage[210];
			StringCchPrintf(szMessage, ARRAYSIZE(szMessage), L"%s", m_szTargetDir);//contains target path drive upto 8 elements
			wchar_t *dscpath;
			PathStripPath(szMessage);
			PathStripPath(srcfile);
			wchar_t *src=wcstok (srcfile,L".");
			while (src != NULL)
			 {
				 
			dscpath=src;
		   src = wcstok (NULL,L".");
				}
				
		if(!_tcscmp(dscpath,L"txt")&&!_tcsicmp(szMessage,L"text")){

			hr=S_OK;
		}else if(!_tcscmp(dscpath,L"java")&&!_tcsicmp(szMessage,L"java")){

			hr=S_OK;

         }else if(!_tcscmp(dscpath,L"cpp")&&!_tcsicmp(szMessage,L"cpp")){

			hr=S_OK;
		}else{hr=E_FAIL;}
            }
			}
            GlobalUnlock(stm.hGlobal);
        }

        ReleaseStgMedium(&stm);
    }

    // If any value other than S_OK is returned from the method, the menu 
    // item is not displayed.
    return hr;
}

#pragma endregion

This is the code which i implemented.I even have a doubt that is this the correct method i implemented, if there are any other methods to do this functionality please let me know.
Posted
Updated 29-Jan-13 6:35am
v3
Comments
Jibesh 29-Jan-13 1:02am    
are you asking us to code this functionality for you. if you are ready to pay for your work you may find other rent a coder sites. sorry wrong place.

This is not a valid question. what is your question here? do not expect someone to code for you.
srikanthcool 29-Jan-13 1:19am    
I already started working on it .I used ishellextint interface to get source and destination but i am unable to stop drop event at specific folder.

It would be good if u help me out in this problem.
Jibesh 29-Jan-13 1:56am    
can you update the code where you are having trouble. You can use the Improve Question link to edit your question. Your question really looks like "some one code for me" style. Please update with some code so that someone can able to understand the real problem and give a helping hand.
J.Surjith Kumar 29-Jan-13 4:56am    
If you have any trouble with your code post here and tell where you'r getting trouble.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900