Click here to Skip to main content
13,507,590 members
Rate this:
Please Sign up or sign in to vote.
See more:

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)
#pragma region IShellExtInit

// Initialize the drag and drop handler.
IFACEMETHODIMP FileDragDropExt::Initialize(
    // 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;

    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;
			wchar_t *src=wcstok (srcfile,L".");
			while (src != NULL)
		   src = wcstok (NULL,L".");

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


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



    // 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 28-Jan-13 18:41pm
Updated 29-Jan-13 6:35am
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)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web02 | 2.8.180417.1 | Last Updated 29 Jan 2013
Copyright © CodeProject, 1999-2018
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100