Click to See Complete Forum and Search --> : [Q] About Drag and Drop....


Lee. young hwan
April 2nd, 1999, 05:14 AM
I want to enable my application to support drag and drop function.

draging is started from CListCtrl,
and then droping is done at CMainFrame or CChildFrame.

How can i put file path selected from CListCtrl to clipboard?

following my code did not work.


void CSearchListCtrlEx::OnBegindrag(NMHDR* pNMHDR, LRESULT* pResult)
{
int nItemCount = GetSelectedCount();

if ( nItemCount <= 0)
return ;

CString* pStrItem = new CString[ nItemCount];

int nItemSpace = 0;
unsigned char c;
int i, j;
int nLength;

POSITION pos = GetFirstSelectedItemPosition();
if (pos != NULL) {
for ( i = 0; pos; ++i) {
int nItem = GetNextSelectedItem(pos);
// Get mpeg file name
CString strItemText = GetItemText( nItem, 8);

pStrItem[i] = strItemText;
}
}

for ( i = 0; i < nItemCount; ++i) {
nLength = pStrItem.GetLength();
for ( j = 0; j < nLength; ++j) {
c = (unsigned char)pStrItem.GetAt(j);
if ( c >=0 && c <= 127) {
nItemSpace += 2;
}
else {
nItemSpace += 1;
}
}
nItemSpace += 2;
}
nItemSpace += 2;

char prefix[20];
prefix[0] = 20;
for ( i = 1; i <= 15; ++i)
prefix = 0;
prefix[i++] = 1;
for ( j = 0; j < 3; ++j, ++i)
prefix = 0;

HGLOBAL hMem = ::GlobalAlloc( GMEM_SHARE, 20 + nItemSpace);

char* pText = (char*)::GlobalLock( hMem);
ASSERT(pText);

int k = 0;
for ( k = 0; k < 20; ++k)
pText[k] = prefix[k];
for ( i = 0; i < nItemCount; ++i) {
nLength = pStrItem.GetLength();
for ( j = 0; j < nLength; ++j, ++k) {
c = pStrItem.GetAt( j);
if ( c >=0 && c <= 127) {
pText[k++] = c;
pText[k] = 0;
}
else
pText[k] = c;
}
pText[k++] = 0;
pText[k++] = 0;
}
pText[k++] = 0;
pText[k] = 0;

::GlobalUnlock( hMem);

// Cache data
COleDataSource* pSource = new COleDataSource();
pSource->CacheGlobalData(CF_HDROP, hMem);

delete [] pStrItem;

m_bDrag = TRUE;
pSource->DoDragDrop(DROPEFFECT_COPY, CRect(0,0,0,0));
// DROPEFFECT dropEffect = pSource->DoDragDrop(DROPEFFECT_COPY, CRect(0, 0,0, 0));
// if ( dropEffect == DROPEFFECT_COPY ) {
// }

m_bDrag = FALSE;

delete pSource;

*pResult = 0;
}