Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VC++
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)
#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 28-Jan-13 18:41pm
Edited 29-Jan-13 6:35am
v3
Comments
jibesh at 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 at 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 at 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 at 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
Your Filters
Interested
Ignored
     
0 Shai Vashdi 1,628
1 Tadit Dash 375
2 Manas Bhardwaj 319
3 Sergey Alexandrovich Kryukov 275
4 OriginalGriff 243
0 Sergey Alexandrovich Kryukov 9,530
1 OriginalGriff 5,711
2 Peter Leow 4,320
3 Maciej Los 3,540
4 Abhinav S 3,373


Advertise | Privacy | Mobile
Web02 | 2.8.140415.2 | Last Updated 29 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Use
Layout: fixed | fluid