本文整理汇总了C++中COleDataSource::DoDragDrop方法的典型用法代码示例。如果您正苦于以下问题:C++ COleDataSource::DoDragDrop方法的具体用法?C++ COleDataSource::DoDragDrop怎么用?C++ COleDataSource::DoDragDrop使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类COleDataSource
的用法示例。
在下文中一共展示了COleDataSource::DoDragDrop方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ASSERT
void CNSToolbar2::MoveButton(int nIndex)
{
ASSERT(nIndex >= 0 && nIndex <m_nNumButtons);
COleDataSource * pDataSource = new COleDataSource;
m_pButtonArray[nIndex]->FillInOleDataSource(pDataSource);
CToolbarButton *pButton = m_pButtonArray[nIndex];
// Don't start drag until outside this rect
RECT rectDragStart;
pButton->GetClientRect(&rectDragStart);
pButton->MapWindowPoints(this, &rectDragStart);
DROPEFFECT effect;
CToolbarDropSource * pDropSource = new CToolbarDropSource;
effect=pDataSource->DoDragDrop(DROPEFFECT_COPY | DROPEFFECT_LINK | DROPEFFECT_MOVE | DROPEFFECT_SCROLL | DROPEFFECT_NONE,
&rectDragStart, pDropSource);
delete pDropSource;
delete pDataSource;
}
示例2: DragItem
BOOL CXTPCoreTreeControl::DragItem(CXTPCoreTreeItem* pItem, DROPEFFECT dropEffectMask)
{
ASSERT(pItem);
if (!pItem)
return FALSE;
COleDataSource ds;
if (!pItem->PrepareDrag(ds))
return FALSE;
m_pDraggingItem = pItem;
DROPEFFECT dropEffect = ds.DoDragDrop(dropEffectMask);
BOOL bRemoved = FALSE;
if ((dropEffect == DROPEFFECT_MOVE) && (dropEffectMask & DROPEFFECT_MOVE))
{
if (m_pDraggingItem)
{
m_pDraggingItem->Remove();
bRemoved = TRUE;
}
}
m_pDraggingItem = NULL;
return bRemoved;
}
示例3: OnBegindrag
void CExplorerTestView::OnBegindrag(NMHDR* pNMHDR, LRESULT* pResult)
{
NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
// TODO: Add your control notification handler code here
int nItem = -1;
CObList fileList;
LIST_VIEW* pListView;
CListCtrl& listCtrl = GetListCtrl();
CSharedFile sharedFile;
COleDataSource* dataSource = new COleDataSource;
while((nItem = listCtrl.GetNextItem(nItem, LVNI_SELECTED)) != -1)
{
pListView = (LIST_VIEW*)listCtrl.GetItemData(nItem);
fileList.AddTail((CObject*)pListView);
}
CArchive ar(&sharedFile, CArchive::store);
CExplorerTestDoc* pDoc = (CExplorerTestDoc*)GetDocument();
pDoc->SetCopyFileList(&fileList);
pDoc->SerializeCopyFiles(ar);
ar.Close();
dataSource->CacheGlobalData(m_cbFormat, sharedFile.Detach());
dataSource->DoDragDrop();
delete dataSource;
*pResult = 0;
}
示例4: OnItemClick
HRESULT __stdcall CXMiLFilesControl::OnItemClick(DWORD item)
{
#if 0
HGLOBAL hData = BuildSelectedFilesClipboard();
if (hData)
{
CMyDropSource* dropSource = new CMyDropSource;
CMyDataObject* dataObject = new CMyDataObject;
STGMEDIUM stg = {0};
stg.tymed = TYMED_HGLOBAL;
stg.hGlobal = hData;
stg.pUnkForRelease = NULL;
FORMATETC etc = {0};
etc.cfFormat = CF_HDROP;//CF_UNICODETEXT;//49285;//RegisterClipboardFormat(CFSTR_SHELLURL);//CF_TEXT;
etc.tymed = TYMED_HGLOBAL;
etc.ptd = NULL;
etc.dwAspect = DVASPECT_CONTENT;
etc.lindex = -1;
dataObject->SetData(&etc, &stg, TRUE);
DWORD dropEffect = 0;
HRESULT hr = ::DoDragDrop(dataObject, dropSource, DROPEFFECT_LINK | DROPEFFECT_COPY | DROPEFFECT_MOVE, &dropEffect);
if (hr == DRAGDROP_S_DROP)
{
if (dropEffect/* & DROPEFFECT_MOVE*/)
{
}
}
GlobalFree(hData);
// delete dataObject;
// delete dropSource;
#if 0
COleDataSource source;
source.CacheGlobalData(CF_HDROP, hData, NULL);
if (source.DoDragDrop(DROPEFFECT_COPY | DROPEFFECT_MOVE, NULL, NULL) == DROPEFFECT_COPY)
{
}
source.Empty();
#endif
GlobalFree(hData);
}
#endif
return S_OK;
}
示例5: DoDragDrop
DROPEFFECT COleServerItem::DoDragDrop(LPCRECT lpItemRect, CPoint ptOffset,
BOOL bIncludeLink, DWORD dwEffects, LPCRECT lpRectStartDrag)
{
ASSERT(AfxIsValidAddress(lpItemRect, sizeof(RECT)));
ASSERT_VALID(this);
ASSERT_VALID(this);
DROPEFFECT dropEffect = DROPEFFECT_NONE;
COleDataSource *pDataSource = NULL;
TRY
{
// get clipboard data for this item
CSize sizeItem(
lpItemRect->right - lpItemRect->left,
lpItemRect->bottom - lpItemRect->top);
pDataSource = OnGetClipboardData(bIncludeLink, &ptOffset, &sizeItem);
// add DROPEFFECT_LINK if link source is available
LPDATAOBJECT lpDataObject = (LPDATAOBJECT)
pDataSource->GetInterface(&IID_IDataObject);
ASSERT(lpDataObject != NULL);
FORMATETC formatEtc;
formatEtc.cfFormat = (CLIPFORMAT)_oleData.cfLinkSource;
formatEtc.ptd = NULL;
formatEtc.dwAspect = DVASPECT_CONTENT;
formatEtc.lindex = -1;
formatEtc.tymed = (TYMED)-1;
if (lpDataObject->QueryGetData(&formatEtc) == S_OK)
dwEffects |= DROPEFFECT_LINK;
// calculate default sensitivity rectangle
CRect rectDrag;
if (lpRectStartDrag == NULL)
{
rectDrag.SetRect(lpItemRect->left, lpItemRect->top, lpItemRect->left,
lpItemRect->top);
lpRectStartDrag = &rectDrag;
}
// do drag drop operation
dropEffect = pDataSource->DoDragDrop(dwEffects, lpRectStartDrag);
pDataSource->InternalRelease();
}
CATCH_ALL(e)
{
if (pDataSource != NULL)
pDataSource->InternalRelease();
THROW_LAST();
}
END_CATCH_ALL
return dropEffect;
}
示例6: OnLButtonDown
void CButtonsTextList::OnLButtonDown(UINT nFlags, CPoint point)
{
CListBox::OnLButtonDown(nFlags, point);
int iIndex = GetCurSel ();
if (iIndex == LB_ERR)
{
return;
}
//-------------------------------------------
// Be sure that we realy click into the item!
//-------------------------------------------
CRect rect;
GetItemRect (iIndex, &rect);
if (!rect.PtInRect (point))
{
return;
}
//-----------------------------------------------------------
// Trigger mouse up event (to change selection notification):
//-----------------------------------------------------------
SendMessage (WM_LBUTTONUP, nFlags, MAKELPARAM (point.x, point.y));
//---------------------
// Get selected button:
//---------------------
CBCGPToolbarButton* pButton = (CBCGPToolbarButton*) GetItemData (iIndex);
ASSERT_VALID(pButton);
//--------------------------------------
// Prepare clipboard data and start drag:
//--------------------------------------
COleDataSource* pSrcItem = new COleDataSource();
pButton->m_bDragFromCollection = TRUE;
pButton->PrepareDrag (*pSrcItem);
pButton->m_bDragFromCollection = FALSE;
{
CBCGPLocalResource locaRes;
::SetCursor (AfxGetApp ()->LoadCursor (IDC_BCGBARRES_DELETE));
}
pSrcItem->DoDragDrop(DROPEFFECT_COPY|DROPEFFECT_MOVE, &rect, &CBCGPToolBar::m_DropSource);
pSrcItem->InternalRelease();
}
示例7: GetTreeCtrl
afx_msg void
MFCQuaSymbolIndexView::OnBeginDrag(NMHDR *pnmh, LRESULT* bHandled)
{
cerr << "MFCQuaSymbolIndexView begin drag" << endl;
NM_TREEVIEW* tvp = (NM_TREEVIEW*)pnmh;
if (!draggingNow) {
if (tvp->itemNew.lParam > QSI_SYMBOL_LPARAM ) {
StabEnt *s = (StabEnt *)tvp->itemNew.lParam;
bool draggable = false;
UINT dragFormat = 0;
switch (s->type) {
case TypedValue::S_CLIP: // move an instance
draggable = true;
dragFormat = QuaDrop::clipFormat;
break;
case TypedValue::S_INSTANCE: // move an instance
draggable = true;
dragFormat = QuaDrop::instanceFormat;
break;
case TypedValue::S_SAMPLE: // create a sample instance
draggable = true;
dragFormat = QuaDrop::sampleFormat;
break;
case TypedValue::S_VOICE: // create a voice instance
draggable = true;
dragFormat = QuaDrop::voiceFormat;
break;
}
if (!draggable) {
*bHandled = TRUE;
return;
}
COleDataSource srcItem;
CTreeCtrl& tree = GetTreeCtrl();
QuaDrop::SetSymbolSource(&srcItem, dragFormat, s);
tree.Select(tvp->itemNew.hItem, TVGN_CARET);
selectedItem = tvp->itemNew.hItem;
srcItem.DoDragDrop();
}
}
*bHandled = 0;
}
示例8: OnLButtonDown
void CArxdrawView::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CPoint local = point;
m_lastPoint = local;
// find out which object is selected
// 0 = circle
// 1 - square
// 2 - up triangle
// 3 - down triangle
int objType = -1;
if (point.x < 65)
{ // circle or square
if (point.y < 45)
objType = 0;
else
objType = 1;
}
else
{
if (point.y < 45)
objType = 2;
else
objType = 3;
}
COleDataSource *pSource = generateDataSource(objType, CRect(CPoint(0,0), CSize(m_sliderVal, m_sliderVal )));
CMyOverrideDropTarget myDT;
CDropSource myDS;
// Start overriding AutoCAD's Droptarget
if (!acedStartOverrideDropTarget(&myDT))
TRACE("Error in overriding Custom drop target!\n");
DROPEFFECT dwEffect = pSource->DoDragDrop( DROPEFFECT_NONE |DROPEFFECT_MOVE | DROPEFFECT_COPY, NULL, &myDS);
// End overriding AutoCAD default droptarget
if (!acedEndOverrideDropTarget(&myDT))
TRACE("Error in ending override drop target\n");
delete pSource;
}
示例9: OnBegindrag
void CModuleWnd::OnBegindrag(NMHDR* pNMHDR, LRESULT* pResult)
{
NMLISTVIEW * phdn = (NMLISTVIEW *) pNMHDR;
if (m_pCurrentDocument != NULL)
{
COleDataSource* pData = PrepareDataSource();
if (pData != NULL)
{
m_isDragBeginer = TRUE;
DROPEFFECT dropEffect = pData->DoDragDrop(DROPEFFECT_COPY);
delete pData;
m_isDragBeginer = FALSE;
}
}
*pResult = 0;
}
示例10: OnLvnBegindrag
void CGumpListView::OnLvnBegindrag(NMHDR *pNMHDR, LRESULT *pResult)
{
LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
*pResult = 0;
COleDataSource srcItem;
CString sType = _T("");
HGLOBAL hTextData = 0;
CSharedFile clipb (GMEM_MOVEABLE|GMEM_DDESHARE|GMEM_ZEROINIT);
dynDropSource.nControlType = DYN_PICTURE;
CString strText;
strText.Format("%d",0);
sType = strText;
clipb.Write(sType, sType.GetLength()*sizeof(TCHAR));
hTextData = clipb.Detach();
srcItem.CacheGlobalData(m_nIDClipFormat, hTextData);
srcItem.DoDragDrop(DROPEFFECT_COPY,NULL,&dynDropSource);
}
示例11: BeginDrag
//-------------------------------------------------------------------//
// BeginDrag()
//-------------------------------------------------------------------//
// This function attempts a drag when the left button has been
// pressed on an item. It returns true if a drag was made.
//-------------------------------------------------------------------//
BOOL OleListCtrl::BeginDrag(
int nUnderCursor,
UINT nKeyFlags
) {
// Attempt a drag.
/////////////////////////////////////////////////////
// Next, we provide a ClipFormat holding the item reference.
// Make sure ClipFormat is ready to go.
ASSERT( ClipFormat != NULL );
// Dump the current selection into drag data array.
ExtractItemsToDragData(
true,
nUnderCursor
);
// To drag, we need a COleDataSource that is loaded with our data.
// Get a new one.
COleDataSource DataSource;
// Put the drag data into the DS.
ArchiveAndRenderClipFormats( &DataSource );
// Now we can clear the previous drag contents.
Items.RemoveAll();
//
/////////////////////////////////////////////////////
// Get the rectangle of the list item.
// This will help us avoid a drag unless the user really means it.
CRect ItemRect;
GetItemRect( nUnderCursor, &ItemRect, LVIR_BOUNDS );
ClientToScreen( &ItemRect );
// Set flags to indicate that we are dragging.
nListItemBeingDragged = nUnderCursor;
bDraggingFromThisList = true;
// Now drag it.
DROPEFFECT deResult = DataSource.DoDragDrop(
DROPEFFECT_COPY | DROPEFFECT_MOVE, // | DROPEFFECT_LINK,
ItemRect
);
InsertStart();
// Indicate that we are no longer dragging.
bDraggingFromThisList = false;
nListItemBeingDragged = -1;
// If it was a move, remove the item(s).
if ( deResult == DROPEFFECT_MOVE )
{
// Delete the current selection, then
// highlight the dragged items.
DeleteOldAndHighlightNew();
}
// Successful drag and drop operation.
if ( deResult != DROPEFFECT_NONE )
{
// Allow derived classes to do any additional clean up steps.
FinishDragAndDrop();
}
InsertEnd();
return ( deResult != DROPEFFECT_NONE );
}
示例12: DoDrag
//.........这里部分代码省略.........
pDrop->pFiles = sizeof(DROPFILES);
// If we're compiling for Unicode, set the Unicode flag in the struct to
// indicate it contains Unicode strings.
#ifdef _UNICODE
pDrop->fWide = TRUE;
#endif;
// Copy all the filenames into memory after the end of the DROPFILES struct.
pos = lsDraggedFiles.GetHeadPosition();
pszBuff = (TCHAR*) (LPBYTE(pDrop) + sizeof(DROPFILES));
while ( pos )
{
lstrcpy ( pszBuff, (LPCTSTR) lsDraggedFiles.GetNext ( pos ) );
pszBuff = 1 + _tcschr ( pszBuff, '\0' );
}
GlobalUnlock ( hgDrop );
// Put the data in the data source.
datasrc.CacheGlobalData ( CF_HDROP, hgDrop, &etc );
// Add in our own custom data, so we know that the drag originated from our
// window. CMyDropTarget::DragEnter() checks for this custom format, and
// doesn't allow the drop if it's present. This is how we prevent the user
// from dragging and then dropping in our own window.
// The data will just be a dummy bool.
HGLOBAL hgBool;
hgBool = GlobalAlloc ( GHND | GMEM_SHARE, sizeof(bool) );
if ( NULL == hgBool )
{
GlobalFree ( hgDrop );
return;
}
// Put the data in the data source.
etc.cfFormat = m_DropID;
datasrc.CacheGlobalData ( m_DropID, hgBool, &etc );
// Start the drag 'n' drop!
DROPEFFECT dwEffect = datasrc.DoDragDrop ( DROPEFFECT_COPY | DROPEFFECT_MOVE );
// If the DnD completed OK, we remove all of the dragged items from our
// list.
switch ( dwEffect )
{
case DROPEFFECT_COPY:
case DROPEFFECT_MOVE:
{
// the copy completed successfully
// do whatever we need to do here
TRACE0( "DND from playlist completed successfully. The data has a new owner.\n" );
}
break;
case DROPEFFECT_NONE:
{
// This needs special handling, because on NT, DROPEFFECT_NONE
// is returned for move operations, instead of DROPEFFECT_MOVE.
// See Q182219 for the details.
// So if we're on NT, we check each selected item, and if the
// file no longer exists, it was moved successfully and we can
// remove it from the list.
if ( m_IsWinNT )
{
// the copy completed successfully
// on a windows nt machine.
// do whatever we need to do here
bool bDeletedAnything = false;
if ( ! bDeletedAnything )
{
// The DnD operation wasn't accepted, or was canceled, so we
// should call GlobalFree() to clean up.
GlobalFree ( hgDrop );
GlobalFree ( hgBool );
TRACE0( "DND had a problem. We had to manually free the data.\n" );
}
}
// not windows NT
else
{
// We're on 9x, and a return of DROPEFFECT_NONE always means
// that the DnD operation was aborted. We need to free the
// allocated memory.
GlobalFree ( hgDrop );
GlobalFree ( hgBool );
TRACE0( "DND had a problem. We had to manually free the data.\n" );
}
}
break;
}
}
示例13: OnTvnBegindrag
//.........这里部分代码省略.........
csIconName = m_csaL3IconName.GetAt(i);
csBlockName = m_csaL3MenuName.GetAt(i); // Needs to be set to trigger a subsystem drop action
}
}
// next check if a level3 item is selected
for (int i=0; i<m_iL4MenuSize; i++) {
if (m_hItemClicked==forthlev[i]) {
csIconName = m_csaL4IconName.GetAt(i);
csBlockName = m_csaL4MenuName.GetAt(i);// Needs to be set to trigger a subsystem drop action
}
}
LPNMTREEVIEW pNMTreeView = reinterpret_cast<LPNMTREEVIEW>(pNMHDR);
//NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
*pResult = 0;
#ifdef LEGACY
// Create the drag&drop source and data objects
COleDropSource *pDropSource = new COleDropSource;
COleDataSource *pDataSource = new COleDataSource;
#endif
// now determine which rows are selected
// here it's a dirty copy from the CodeGurus's
// CListCtrl section
//int idx = GetSelectedItem();
// nothing selected (must be for dragging)
// or error while registering the clipboard format
if (/*idx == -1 ||*/ !m_DragDropFormat)
{
ASSERT(FALSE);
return;
}
// now grab the data (here: the count and text)
// and serialize it into an clipboard archive
INXString Data;
// getting the column count, thanks Zafir!
// CHeaderCtrl* pHeader = (CHeaderCtrl*)m_Table.GetDlgItem(0);
//int number = m_Table.GetSelectedCount(),
// colCou = pHeader?pHeader->GetItemCount():0;
/* This is some rubbish serialisation that is needed to retrieve data from files in the draw windows etc.. !!! */
TRY
{
CSharedFile file(GMEM_ZEROINIT|GMEM_DDESHARE|GMEM_MOVEABLE);
TRY
{
CArchive ar(&file, CArchive::store);
TRY
{
INXString format = AfxGetApp()->GetProfileString("DragDrop", "Clipformat", "Common");
if (format == "Private")
{
ar << (CString)csIconName;
ar << (CString)csBlockName;
}
else // common data format
{
ar.WriteString( csIconName + "\n" + csBlockName + "\n" );
}
ar.Close();
}
CATCH_ALL(eInner)
{
// exception while writing into or closing the archive
ASSERT(FALSE);
}
END_CATCH_ALL;
}
CATCH_ALL(eMiddle)
{
// exception in the destructor of ar
ASSERT(FALSE);
}
END_CATCH_ALL;
// put the file object into the data object
#ifdef LEGACY
pDataSource->CacheGlobalData(m_DragDropFormat, file.Detach());
pDataSource->DoDragDrop(DROPEFFECT_MOVE|DROPEFFECT_COPY, NULL, pDropSource);
#endif
}
CATCH_ALL(eOuter)
{
// exception while destructing the file
ASSERT(FALSE);
}
END_CATCH_ALL;
#ifdef LEGACY
delete pDropSource;
delete pDataSource;
#endif
*pResult = 0;
} // if( leafIsSelected() )
}
示例14: PrepareDrop
///////////////////////////////////////////////////
//Copy this object out to the clipboard or drag/drop
//buffer based on Keith Rule's
//serialization algorithm
//from the MFC Programmer's Sourcebook website,
//and Chapter 1 of "the Essence of OLE with Active X"
//by David S. Platt.
//
//pDropEffect is only set if doing a drag-drop.
//
//You usually call this function from:
//
//1) Your view class's OnLButtonDown() method
// when starting a drag-drop.
//
//2) Your document class when copying data
// to the clipboard.
///////////////////////////////////////////////////
BOOL CDragDropMgr::PrepareDrop(
BOOL bToClipboard,
LPCTSTR lpstrFormat,
CObject* pObj,
DROPEFFECT* pDropEffect,
LPCTSTR lpstrFormat2,
CObject* pObj2)
{
if (pObj == NULL)
return FALSE;
CSharedFile sf(GMEM_MOVEABLE|GMEM_DDESHARE|GMEM_ZEROINIT);
CSharedFile sf2(GMEM_MOVEABLE|GMEM_DDESHARE|GMEM_ZEROINIT);
UINT format = ::RegisterClipboardFormat(lpstrFormat);
if (format == 0)
return FALSE;
TRY
{
CArchive ar(&sf, CArchive::store);
pObj->Serialize(ar);
ar.Close();
HGLOBAL hMem = sf.Detach();
if (hMem == NULL)
return FALSE;
COleDataSource* pSrc = new COleDataSource();
if (pSrc == NULL)
return FALSE;
pSrc->CacheGlobalData(format,hMem);
if (pObj2) { // special case for when the second data type is a filelist
UINT format2 = (strcmp(lpstrFormat2, "CF_HDROP") ? ::RegisterClipboardFormat(lpstrFormat2) : CF_HDROP);
if (format2 != CF_HDROP) {
CArchive ar2(&sf2, CArchive::store);
pObj2->Serialize(ar2);
ar2.Close();
HGLOBAL hMem2 = sf2.Detach();
if (hMem2 == NULL)
return FALSE;
pSrc->CacheGlobalData(format2,hMem2);
}
else { // fake file list
DROPFILES *pDrop = (DROPFILES*)pObj2;
HGLOBAL hgDrop = GlobalAlloc ( GHND | GMEM_SHARE, sizeof(DROPFILES)+1 );
DROPFILES *pDrop2 = (DROPFILES*) GlobalLock ( hgDrop );
memcpy((void*)pDrop2, (void*)pDrop, sizeof(DROPFILES)+1);
GlobalUnlock(hgDrop);
pSrc->CacheGlobalData(format2, hgDrop);
}
}
//Pasting to the clipboard:
//do not free the data source
//(OLE will free it when no longer needed)
if (bToClipboard)
pSrc->SetClipboard();
//Starting a drag-drop:
//Set the type of drag-drop effect, and
//free the data source object.
//OLE has created a data source object in
//the drag-drop global cache; it's
//not our problem anymore...
else if (pDropEffect != NULL)
{
*pDropEffect = pSrc->DoDragDrop();
delete pSrc;
//.........这里部分代码省略.........