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
IFACEMETHODIMP FileDragDropExt::Initialize(
LPCITEMIDLIST pidlFolder, LPDATAOBJECT pDataObj, HKEY hKeyProgID)
{
if (!SHGetPathFromIDList(pidlFolder, this->m_szTargetDir))
{
return E_FAIL;
}
if (NULL == pDataObj)
{
return E_INVALIDARG;
}
HRESULT hr = E_FAIL;
FORMATETC fe = { CF_HDROP, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL };
STGMEDIUM stm;
if (SUCCEEDED(pDataObj->GetData(&fe, &stm)))
{
HDROP hDrop = static_cast<hdrop>(GlobalLock(stm.hGlobal));
if (hDrop != NULL)
{
UINT nFiles = DragQueryFile(hDrop, 0xFFFFFFFF, NULL, 0);
if (nFiles == 1)
{
if (0 != DragQueryFile(hDrop, 0, m_szSrcFile, ARRAYSIZE(m_szSrcFile)))
{
if (!PathIsDirectory(m_szSrcFile))
{
hr = S_OK;
}
TCHAR srcfile[210];
StringCchPrintf(srcfile, ARRAYSIZE(srcfile),
L"%s", m_szSrcFile);
TCHAR szMessage[210];
StringCchPrintf(szMessage, ARRAYSIZE(szMessage), L"%s", m_szTargetDir); 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);
}
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.