Click here to Skip to main content
16,008,954 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionRe: Help Please Pin
Rajesh R Subramanian13-Oct-06 22:51
professionalRajesh R Subramanian13-Oct-06 22:51 
AnswerRe: Help Please Pin
radhika2813-Oct-06 23:57
radhika2813-Oct-06 23:57 
GeneralRe: Help Please Pin
Hamid_RT14-Oct-06 3:42
Hamid_RT14-Oct-06 3:42 
GeneralRe: Help Please [modified] Pin
radhika2814-Oct-06 4:03
radhika2814-Oct-06 4:03 
GeneralRe: Help Please Pin
Hamid_RT14-Oct-06 4:17
Hamid_RT14-Oct-06 4:17 
GeneralRe: Help Please Pin
radhika2815-Oct-06 20:15
radhika2815-Oct-06 20:15 
GeneralRe: Help Please Pin
Hamid_RT16-Oct-06 8:33
Hamid_RT16-Oct-06 8:33 
GeneralRe: Help Please Pin
radhika2817-Oct-06 1:35
radhika2817-Oct-06 1:35 
ya i have gone through some applications in that,but no use.Now i have decided to attach a menu to the tree items.It consists of copy and paste menu items.When i copy a tree item from tree contol and pasting it on the explorer it is working.Similaly when i copy from explorer and paste it in the tree control it is not occuring.I have written the code like this.Is there any wrong in this.

void CTreeFileCtrl::OnTreefilectrlPaste()
{
COleDataObject DataObject;

if( DataObject.AttachClipboard() )
{

DataObjectToTree(&DataObject);

}

}

void CTreeFileCtrl::OnUpdateTreefilectrlPaste(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
COleDataObject odj;
pCmdUI->Enable(FALSE);

if( odj.AttachClipboard() )
{
if( odj.IsDataAvailable( CF_HDROP ) )
{
pCmdUI->Enable(TRUE);
}
}


}

void CTreeFileCtrl::OnTreefilectrlCopy()
{
// TODO: Add your command handler code here
FileNamesToClipBoard();

}

void CTreeFileCtrl::OnUpdateTreefilectrlCopy(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
HTREEITEM hItem = GetSelectedItem();


if(hItem){
pCmdUI->Enable(TRUE);
}
else{
pCmdUI->Enable(FALSE);
}

}

void CTreeFileCtrl::FileNamesToClipBoard()
{

CDropFiles DropFiles;

if(!PrepareFileBuff(DropFiles)){
return;
}

if (OpenClipboard())
{
BeginWaitCursor();
::EmptyClipboard();

HGLOBAL hMem = ::GlobalAlloc(GMEM_ZEROINIT|GMEM_MOVEABLE|GMEM_DDESHARE, DropFiles.GetBuffSize());
memcpy( (char*)::GlobalLock(hMem), DropFiles.GetBuffer(), DropFiles.GetBuffSize() );
::SetClipboardData (CF_HDROP, hMem );

::CloseClipboard();
EndWaitCursor();
}
}

BOOL CTreeFileCtrl::PrepareFileBuff(CDropFiles &DropFiles) const
{
HTREEITEM hItem = GetSelectedItem();

if( hItem == NULL){
return FALSE;
}

else if(hItem) {
//int index = mylist.GetNextSelectedItem(pos);
DropFiles.AddFile(ItemToPath(hItem));
}

DropFiles.CreateBuffer();

return TRUE;

}

BOOL CTreeFileCtrl::DataObjectToTree(COleDataObject *const pDataObject)
{


if( pDataObject->IsDataAvailable( CF_HDROP ) )
{
STGMEDIUM StgMed;
FORMATETC fmte = { CF_HDROP,
(DVTARGETDEVICE FAR *)NULL,
DVASPECT_CONTENT,
-1,
TYMED_HGLOBAL };
if( pDataObject->GetData( CF_HDROP, &StgMed, &fmte ) )
{
HDROP hDrop= (HDROP)StgMed.hGlobal;
UINT cFiles = ::DragQueryFile(hDrop, (UINT)-1, NULL, 0);
char szFile[MAX_PATH];
CString pszFileTo=ItemToPath(GetSelectedItem());
SHFILEOPSTRUCT shfo;
WORD wFunc=FO_COPY;
//TCHAR pszTo[1024] = {0};
// TCHAR pszFrom[1024] = {0};
WORD wFlags = 0;


// wFlags |= FOF_SILENT;


ZeroMemory(&shfo, sizeof(SHFILEOPSTRUCT));
//szFileTo +="\0"
if(cFiles <= 0){
ASSERT(0);
return FALSE;
}
else
{

for( UINT count = 0; count < cFiles; count++ )
{
::DragQueryFile(hDrop, count, szFile, sizeof(szFile));
CString szFileFrom = szFile;
//szFileFrom+="\\0";

shfo.wFunc = wFunc;

shfo.fFlags = static_cast<fileop_flags>(wFlags);
shfo.pTo = pszFileTo;
shfo.pFrom = szFileFrom;

CopyFile(szFileFrom, pszFileTo,0);

SHFileOperation(&shfo);
if(shfo.fAnyOperationsAborted)
{
MessageBox("Aborted!");
return FALSE;
}

}
}

if (StgMed.pUnkForRelease){
StgMed.pUnkForRelease->Release();
}
else {
::GlobalFree(StgMed.hGlobal);
}
return TRUE;
}

}
}

Thanks.
GeneralRe: Help Please Pin
Hamid_RT17-Oct-06 7:39
Hamid_RT17-Oct-06 7:39 
Questionrefresh screen, then get it , but bad? [modified] Pin
seeQe13-Oct-06 20:28
seeQe13-Oct-06 20:28 
AnswerRe: refresh screen, then get it , but bad? Pin
Hamid_RT14-Oct-06 3:43
Hamid_RT14-Oct-06 3:43 
GeneralRe: refresh screen, then get it , but bad? Pin
seeQe15-Oct-06 1:36
seeQe15-Oct-06 1:36 
GeneralRe: refresh screen, then get it , but bad? Pin
Hamid_RT16-Oct-06 8:33
Hamid_RT16-Oct-06 8:33 
QuestionDrag and drop files and folders to and from tree control Pin
kiranin13-Oct-06 19:05
kiranin13-Oct-06 19:05 
AnswerRe: Drag and drop files and folders to and from tree control Pin
Michael Dunn13-Oct-06 19:19
sitebuilderMichael Dunn13-Oct-06 19:19 
GeneralRe: Drag and drop files and folders to and from tree control Pin
kiranin13-Oct-06 19:27
kiranin13-Oct-06 19:27 
QuestionUse Bitwise Operators to switch the values of two variables Pin
Wcbzero13-Oct-06 13:12
Wcbzero13-Oct-06 13:12 
AnswerRe: Use Bitwise Operators to switch the values of two variables Pin
dighn13-Oct-06 13:39
dighn13-Oct-06 13:39 
AnswerRe: Use Bitwise Operators to switch the values of two variables Pin
PJ Arends13-Oct-06 13:51
professionalPJ Arends13-Oct-06 13:51 
Answer"Cuteness hurts" - Herb Sutter Pin
George L. Jackson13-Oct-06 15:56
George L. Jackson13-Oct-06 15:56 
Questionwindows service account query Pin
ku1983200113-Oct-06 12:37
ku1983200113-Oct-06 12:37 
QuestionLocking exe Pin
dhawi13-Oct-06 11:03
dhawi13-Oct-06 11:03 
AnswerRe: Locking exe Pin
led mike13-Oct-06 11:12
led mike13-Oct-06 11:12 
QuestionWhat's the standard way to handle change detection in dialogs? Pin
Lord Kixdemp13-Oct-06 10:25
Lord Kixdemp13-Oct-06 10:25 
AnswerRe: What's the standard way to handle change detection in dialogs? Pin
PJ Arends13-Oct-06 10:40
professionalPJ Arends13-Oct-06 10:40 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.