コード例 #1
1
void CHexEdit::OnEditCopy() 
{
	COleDataSource*		pSource = new COleDataSource();
	EmptyClipboard();
	int	dwLen = GetSelLength();
	HGLOBAL		hMemb = ::GlobalAlloc(GMEM_MOVEABLE|GMEM_DDESHARE|GMEM_ZEROINIT, dwLen);
	HGLOBAL		hMema = ::GlobalAlloc(GMEM_MOVEABLE|GMEM_DDESHARE|GMEM_ZEROINIT, (dwLen) * 3);
	if (!hMemb || !hMema) 
		return;
	LPBYTE	p = (BYTE*)::GlobalLock(hMemb);
	// copy binary
	memcpy(p, m_pData+m_selStart, dwLen);
	::GlobalUnlock(hMemb);
	p = (BYTE*)::GlobalLock(hMema);
	// copy ascii
	memcpy(p, m_pData+m_selStart, dwLen);
	::GlobalUnlock(hMema);
	for(int	 i = 0; i < dwLen;i++)
	{
		if(m_currentMode != EDIT_ASCII)
		{
			TOHEX(m_pData[m_selStart+i], p);
			*p++ = ' ';
		}
		else
			if(!isprint(*p))
				*p++ = '.';
	}
	pSource->CacheGlobalData(RegisterClipboardFormat("BinaryData"), hMemb);	
	pSource->CacheGlobalData(CF_TEXT, hMema);	
	pSource->SetClipboard();
}
コード例 #2
0
ファイル: ModuleWnd.cpp プロジェクト: JackWangCUMT/SuperCxHMI
void CModuleWnd::OnLibCopy()
{
	COleDataSource* pDataSource = PrepareDataSource();

	ASSERT_VALID(pDataSource);
	pDataSource->SetClipboard();
}
コード例 #3
0
ファイル: OleListCtrl.cpp プロジェクト: moodboom/Reusable
//-------------------------------------------------------------------//
// Copy()																				//
//-------------------------------------------------------------------//
void OleListCtrl::Copy()
{
	// We provide a ClipFormat, so make sure ClipFormat is ready to go.
	ASSERT( ClipFormat != NULL );

	// Dump the current selection into drag data array.
	ExtractItemsToDragData( 
		true,
		-1				/// nUnderCursor
	);

	// To drag, we need a COleDataSource that is loaded with our data.
	// Get a new one.
	// From "Using the OLE Clipboard Mechanism" in MSDN:
	// Create an OLE data source on the heap
	// COleDataSource DataSource;
	COleDataSource* pSource = new COleDataSource;

	// Put the drag data into the DS.
	// This renders to the clipboard.
	ArchiveAndRenderClipFormats( pSource );

	// The Clipboard now owns the allocated memory
	// and will delete this data object
	// when new data is put on the Clipboard
	pSource->SetClipboard();

	// Clear the drag contents, now that we have copied them to the clipboard.
	Items.RemoveAll();

}
コード例 #4
0
ファイル: ModuleWnd.cpp プロジェクト: JackWangCUMT/SuperCxHMI
COleDataSource* CModuleWnd::PrepareDataSource()
{
	ASSERT(m_pCurrentDocument != NULL);
	
	int nSelectedObjects = GetListCtrl()->GetSelectedCount();
	if (nSelectedObjects < 1)
		return NULL;
	
	STGMEDIUM stgMedium;
	COleDataSource* pDataSource;
	
	pDataSource = new COleDataSource;
	if(pDataSource == NULL)
	{
		AfxThrowMemoryException();
	}
	
	if (!GetSelectModuleData(&stgMedium))
	{
		delete pDataSource;
		return NULL;
	}
	
	pDataSource->CacheData(CDevDoc::m_cfDocData, &stgMedium);
	
	GetDragInfoData(&stgMedium);
	pDataSource->CacheData(CLayoutView::m_cfDragInfo, &stgMedium);
	
	return pDataSource;
}
コード例 #5
0
ファイル: ex27bView.cpp プロジェクト: jiayuehua/InsideVC
void CEx27bView::OnEditCopy() 
{
	COleDataSource* pSource = SaveObject();
	if(pSource) {
		pSource->SetClipboard(); // OLE deletes data source 
    }
}
コード例 #6
0
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;
}
コード例 #7
0
void CUIDesignerView::OnEditCopy()
{
	ASSERT(m_cfUI != NULL);

	TiXmlDocument xmlDoc;
	TiXmlDeclaration Declaration("1.0","utf-8","yes");
	xmlDoc.InsertEndChild(Declaration);
	TiXmlElement* pCopyElm = new TiXmlElement("UICopy");
	CopyUI(pCopyElm);
	xmlDoc.InsertEndChild(*pCopyElm);
	TiXmlPrinter printer;
	xmlDoc.Accept(&printer);
	delete pCopyElm;
	CSharedFile file(GMEM_MOVEABLE, printer.Size() + 1);
	file.Write(printer.CStr(), printer.Size());
	file.Write("\0", 1);
	COleDataSource* pDataSource = NULL;
	TRY
	{
		pDataSource = new COleDataSource;
		pDataSource->CacheGlobalData(m_cfUI, file.Detach());
		pDataSource->SetClipboard();
	}
	CATCH_ALL(e)
	{
		delete pDataSource;
		THROW_LAST();
	}
	END_CATCH_ALL
}
コード例 #8
0
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;
}
コード例 #9
0
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;

}
コード例 #10
0
ファイル: olesvr2.cpp プロジェクト: rickerliang/OpenNT
void COleServerItem::CopyToClipboard(BOOL bIncludeLink)
{
	ASSERT_VALID(this);

	COleDataSource* pDataSource = OnGetClipboardData(bIncludeLink, NULL, NULL);

	// put it on the clipboard
	pDataSource->SetClipboard();
}
コード例 #11
0
ファイル: olesvr2.cpp プロジェクト: rickerliang/OpenNT
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;
}
コード例 #12
0
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;
}
コード例 #13
0
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();
}
コード例 #14
0
ファイル: MFCQuaSymbolIndexView.cpp プロジェクト: dakyri/qua
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;
}
コード例 #15
0
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;
}
コード例 #16
0
ファイル: ModuleWnd.cpp プロジェクト: JackWangCUMT/SuperCxHMI
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;
}
コード例 #17
0
ファイル: olecli3.cpp プロジェクト: shuowen/OpenNT
void COleClientItem::CopyToClipboard(BOOL bIncludeLink)
{
    ASSERT_VALID(this);
    ASSERT(m_lpObject != NULL);

    // get clipboard data for this item
    COleDataSource* pDataSource = OnGetClipboardData(bIncludeLink, NULL, NULL);
    TRY
    {
        // put it on the clipboard
        pDataSource->SetClipboard();
    }
    CATCH_ALL(e)
    {
        delete pDataSource;
        THROW_LAST();
    }
    END_CATCH_ALL
}
コード例 #18
0
COleDataSource* CArxdrawView::generateDataSource(int objType, const CRect& rect)
{
    COleDataSource* pSource = new COleDataSource();
    char buf[50];

    sprintf(buf,"%d %d %d %d %d", objType,
                               rect.left,
                               rect.top,
                               rect.right,
                               rect.bottom);

    HGLOBAL temp = GlobalAlloc(GHND, strlen(buf)+1);
    char *data = (char*) GlobalLock(temp);
    strcpy(data, buf);
    GlobalUnlock(temp);
    pSource->CacheGlobalData(CF_TEXT, temp);
    
    return pSource;                               
}
コード例 #19
0
ファイル: ex27bView.cpp プロジェクト: jiayuehua/InsideVC
// helper function used for clipboard and drag-drop 
COleDataSource* CEx27bView::SaveObject()
{
	TRACE("Entering CEx27bView::SaveObject\n");
	CEx27bDoc* pDoc = GetDocument();
    if (pDoc->m_lpOleObj != NULL) {
		COleDataSource* pSource = new COleDataSource();
        
        // CODE FOR OBJECT DATA
        FORMATETC fmte;
        SETFORMATETC(fmte, m_cfEmbedded, DVASPECT_CONTENT, NULL,
            TYMED_ISTORAGE, -1);
        STGMEDIUM stgm;
        stgm.tymed = TYMED_ISTORAGE;
        stgm.pstg = pDoc->m_pTempStgSub;
        stgm.pUnkForRelease = NULL;
		pDoc->m_pTempStgSub->AddRef();   // must do both!
		pDoc->m_pTempStgRoot->AddRef();
		pSource->CacheData(m_cfEmbedded, &stgm, &fmte);

		// metafile needed too
		MakeMetafilePict(pSource);
		
		// CODE FOR OBJECT DESCRIPTION DATA
		HGLOBAL hObjDesc = ::GlobalAlloc(GMEM_SHARE, sizeof(OBJECTDESCRIPTOR));
		LPOBJECTDESCRIPTOR pObjDesc =
		    (LPOBJECTDESCRIPTOR) ::GlobalLock(hObjDesc);
		pObjDesc->cbSize = sizeof(OBJECTDESCRIPTOR);
		pObjDesc->clsid	= CLSID_NULL;
		pObjDesc->dwDrawAspect = 0;
		pObjDesc->dwStatus = 0;
		pObjDesc->dwFullUserTypeName = 0;
		pObjDesc->dwSrcOfCopy = 0;
	   	pObjDesc->sizel.cx = 0;
    	pObjDesc->sizel.cy = 0;
    	pObjDesc->pointl.x = 0;
    	pObjDesc->pointl.y = 0;
		::GlobalUnlock(hObjDesc);
		pSource->CacheGlobalData(m_cfObjDesc, hObjDesc);
		return pSource;
	}
	return NULL;
}
コード例 #20
0
ファイル: AboutDlg.cpp プロジェクト: JavanWang/mpc-hc
void CAboutDlg::OnCopyToClipboard()
{
    CStringW info = m_appname;
    info += _T("\n----------------------------------\n\n");
    info += _T("Build information:\n");
    info += _T("    Version:            ") + m_strBuildNumber + _T("\n");
    info += _T("    Compiler:           ") + m_MPCCompiler + _T("\n");
    info += _T("    Build date:         ") + m_buildDate + _T("\n\n");
#ifndef MPCHC_LITE
    info += _T("LAV Filters:\n");
    info += _T("    LAV Splitter:       ") + CFGFilterLAV::GetVersion(CFGFilterLAV::SPLITTER) + _T("\n");
    info += _T("    LAV Video:          ") + CFGFilterLAV::GetVersion(CFGFilterLAV::VIDEO_DECODER) + _T("\n");
    info += _T("    LAV Audio:          ") + CFGFilterLAV::GetVersion(CFGFilterLAV::AUDIO_DECODER) + _T("\n");
    info += _T("    FFmpeg compiler:    ") + CString(g_Gcc_Compiler) + _T("\n\n");
#endif
    info += _T("Operating system:\n");
    info += _T("    Name:               ") + m_OSName + _T("\n");
    info += _T("    Version:            ") + m_OSVersion + _T("\n");

    COleDataSource* pData = DEBUG_NEW COleDataSource();

    int len = info.GetLength() + 1;
    HGLOBAL hGlob = GlobalAlloc(GMEM_FIXED, len * sizeof(WCHAR));

    if (pData && hGlob) {
        wcscpy_s((WCHAR*)hGlob, len, (LPCWSTR)info);

        pData->CacheGlobalData(CF_UNICODETEXT, hGlob);

        // The system will take care of removing the allocated memory
        pData->SetClipboard();
    } else if (pData) {
        delete pData;
    } else if (hGlob) {
        GlobalFree(hGlob);
    }
}
コード例 #21
0
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);
}
コード例 #22
0
BOOL CBCGPMSOffice2007DemoView::InsertBitmap (UINT uiBmpResID)
{
	CWaitCursor wait;

	CBitmap bmp;
	if (!bmp.LoadBitmap(uiBmpResID))
	{
		return FALSE;
	}
	
	COleDataSource* pDataSrc = new COleDataSource;
	COleDataObject* pData = new COleDataObject;
	
	CBCGPMSOffice2007DemoCntrItem* pItem = NULL;
	
	TRY
	{
		WPD_CHARFORMAT cf = GetCharFormatSelection();

		STGMEDIUM stgm;
		stgm.hGlobal = bmp.GetSafeHandle();
		stgm.tymed = TYMED_GDI;
		stgm.pUnkForRelease = NULL;

		pDataSrc->CacheData (CF_BITMAP, &stgm);
		
		LPDATAOBJECT lpdata;

		if (FAILED (pDataSrc->m_xDataObject.QueryInterface (IID_IDataObject,
			(LPVOID FAR*) &lpdata)))
		{
			AfxThrowUserException();
		}
		
		pData->Attach (lpdata);
		
		CBCGPMSOffice2007DemoDoc* pDoc = GetDocument();
		ASSERT_VALID(pDoc);

		pItem = new CBCGPMSOffice2007DemoCntrItem (NULL, pDoc);
		ASSERT_VALID(pItem);

		if (!pItem->CreateStaticFromData (pData))
		{
			AfxThrowUserException();
		}
		
		pItem->m_uiCategoryID = uiBmpResID;
		InsertItem (pItem);

		pDoc->UpdateAllViews (this);

		SetCharFormat (cf);
		SyncFont ();
	}
	CATCH(CException, e)
	{
		if (pItem != NULL)
		{
			ASSERT_VALID(pItem);
			pItem->Delete ();
		}

		delete pData;
		delete pDataSrc;

		return FALSE;
	}
	END_CATCH

	delete pData;
	delete pDataSrc;

	CMainFrame* pMainFrame = ((CMainFrame*) GetTopLevelFrame ());
	ASSERT_VALID (pMainFrame);

	pMainFrame->ActivateRibbonContextCategory (uiBmpResID);

	return TRUE;
}
コード例 #23
0
ファイル: OleListCtrl.cpp プロジェクト: moodboom/Reusable
//-------------------------------------------------------------------//
// 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 );

}
コード例 #24
0
/***
	拷贝列表到剪贴板
*/
void CReportListCtrl::Copy( )
{
	// Write to shared file (REMEBER: CF_TEXT is ANSI, not UNICODE, so we need to convert)
	CSharedFile sf(GMEM_MOVEABLE|GMEM_DDESHARE|GMEM_ZEROINIT);

	// Get a tab delimited string to copy to cache
	CString str;

	// Column
	CHeaderCtrl	* pHeader	=	GetHeaderCtrl();
	int	nColCount	=	pHeader ? pHeader->GetItemCount() : 0 ;

	str.Empty();
	char buffer[256];
	LVCOLUMN	column;
	memset( &column, 0, sizeof( column ) );
	column.mask	=	LVCF_TEXT;
	column.pszText	=	buffer;
	column.cchTextMax	=	255;
	int	nColumn	=	0;
	while( GetColumn( nColumn++, &column ) )
	{
		str	+=	buffer;
		str	+=	_T("\t");
	}
	str	+=	_T("\r\n");

	sf.Write(T2A(str.GetBuffer(1)), str.GetLength());
	str.ReleaseBuffer();

	// Data
	for( int nRow = 0; nRow <GetItemCount(); nRow ++ )
	{
		str.Empty();
		for( int nCol = 0; nCol <nColCount; nCol ++ )
		{
			CString	strTemp	=	GetItemText( nRow, nCol );
			str	+=	(strTemp.IsEmpty() ? _T(" ") : strTemp );
			if( nCol != nColCount-1 )
				str	+=	_T("\t");
		}
		if( nRow != GetItemCount()-1 )
			str += _T("\r\n");
		sf.Write(T2A(str.GetBuffer(1)), str.GetLength());
		str.ReleaseBuffer();
	}
	char c = '\0';
	sf.Write(&c, 1);

	DWORD dwLen = (DWORD)sf.GetLength();
	HGLOBAL hMem = sf.Detach();
	if (!hMem) 
		return;

	hMem = ::GlobalReAlloc(hMem, dwLen, GMEM_MOVEABLE|GMEM_DDESHARE|GMEM_ZEROINIT);
	if (!hMem) 
		return;

	// Cache data
	COleDataSource* pSource = new COleDataSource();
	pSource->CacheGlobalData(CF_TEXT, hMem);
	pSource->SetClipboard();
}
コード例 #25
0
ファイル: FunctionBlockTree.cpp プロジェクト: pdrezet/brix
void FunctionBlockTree::OnTvnBegindrag(NMHDR *pNMHDR, LRESULT *pResult)
{

	INXString csIconName = "";
	INXString csBlockName = "";

	//	if ( GetChildItem(m_hItemLeftClicked)== NULL) {
//			SetItemState( m_hItemLeftClicked, TVIS_SELECTED, TVIS_SELECTED );
	//	}

	if( !leafIsSelected() )
		// If he hasn't selected something draggable, don't let him carry 
		// on wasting his time.
		return;
	else{

	for (int i=0; i<m_iL2MenuSize; i++) {
		SetItemState( secondlev[i], !TVIS_SELECTED, TVIS_SELECTED );
	}

	// next check if a level3 item is selected
	for (int i=0; i<m_iL3MenuSize; i++) {
		SetItemState( thirdlev[i], !TVIS_SELECTED, TVIS_SELECTED );
	}
	// next check if a level3 item is selected
	for (int i=0; i<m_iL4MenuSize; i++) {
		SetItemState( forthlev[i], !TVIS_SELECTED, TVIS_SELECTED );
	}
	
	//if(m_hPrevItemClicked)
	//	SetItemState( m_hPrevItemClicked, !TVIS_SELECTED, TVIS_SELECTED );


	if(m_hItemClicked)
		SetItemState( m_hItemClicked, TVIS_SELECTED, TVIS_SELECTED );

		for (int i=0; i<m_iL2MenuSize; i++) {
			if (m_hItemClicked==secondlev[i]) {
				csIconName = m_csaL2IconName.GetAt(i);
				csBlockName = m_csaL2MenuName.GetAt(i);
			}
		}

		// next check if a level3 item is selected
		for (int i=0; i<m_iL3MenuSize; i++) {
			if (m_hItemClicked==thirdlev[i]) {
				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() )
}
コード例 #26
0
LRESULT CSQLTableWnd::OnLButtonDown(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
	POINT point;
	point.x = (short)LOWORD(lParam);
	point.y = (short)HIWORD(lParam);

	if (!(wParam & MK_SHIFT))
	{
		for (int i = 0; i < m_columns.GetSize(); i++)
		{
			m_columns[i]->m_bSelected = false;
		}
	}

	long index = point.y/16;

	if (index >= 0 && index < m_table->Columns->Count)
	{
		m_columns[index]->m_bSelected = true;

		Invalidate();
		UpdateWindow();

		CComQIPtr<ILDOMDocument> document;
		document.CoCreateInstance(CLSID_LDOMDocument);

		VARIANT_BOOL success;
		document->loadXML(L"<columns/>", &success);

		CComQIPtr<ILDOMElement> documentElement;
		document->get_documentElement(&documentElement);

		documentElement->setAttribute(L"fromtable", m_table->Name);

		for (long i = 0; i < m_columns.GetSize(); i++)
		{
			if (m_columns[i]->m_bSelected)
			{
				CComQIPtr<ILDOMElement> element;
				document->createElement(L"column", &element);
				element->setAttribute(L"name", m_table->Columns->Item[_variant_t(index)]->Name);
				documentElement->appendChild(element, NULL);
			}
		}

		BSTR text;
		document->saveXML(NULL, &text);
		int len = SysStringLen(text);

		HGLOBAL hData = GlobalAlloc(GMEM_MOVEABLE, (len+1)*2);

		if (hData)
		{
			WCHAR* p = (WCHAR*)GlobalLock(hData);
			CopyMemory(p, text, (len+1)*2);
			GlobalUnlock(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_UNICODETEXT;//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
		}

		SysFreeString(text);
	}
	else
	{
		Invalidate();
	}

	return 0;
}
コード例 #27
0
void CMusikSourcesCtrl::DoDrag( CMusikPropTreeItem* pItem )
{
    if ( !pItem )
        return;

    COleDataSource datasrc;
    HGLOBAL        hgDrop;
    DROPFILES*     pDrop;
    CStringList    lsDraggedFiles;
    POSITION       pos;
    CString        sFile;
    UINT           uBuffSize = 0;
    TCHAR*         pszBuff;
    FORMATETC      etc = { CF_HDROP, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL };

    // get a list of filenames with the currently
    // selected items...
    CStdStringArray files;

    int nMode = pItem->GetPlaylistType();

    // standard playlist dragged
    if ( nMode == MUSIK_PLAYLIST_TYPE_STANDARD )
        m_Library->GetStdPlaylistFns( pItem->GetPlaylistID(), files, false );

    // now playing dragged..
    else if ( nMode == MUSIK_SOURCES_TYPE_NOWPLAYING )
    {
        if ( m_Player->GetPlaylist() )
        {
            m_Library->BeginTransaction();
            for ( size_t i = 0; i < m_Player->GetPlaylist()->GetCount(); i++ )
                files.push_back( m_Player->GetPlaylist()->GetField( i, MUSIK_LIBRARY_TYPE_FILENAME ) );
            m_Library->EndTransaction();
        }
    }

    // library playlist dragged
    else if ( nMode == MUSIK_SOURCES_TYPE_LIBRARY )
    {
        CMainFrame* pMain = (CMainFrame*)m_Parent;
        if ( pMain->m_LibPlaylist )
        {
            m_Library->BeginTransaction();
            for ( size_t i = 0; i < pMain->m_LibPlaylist->GetCount(); i++ )
                files.push_back( pMain->m_LibPlaylist->GetField( i, MUSIK_LIBRARY_TYPE_FILENAME ) );
            m_Library->EndTransaction();
        }
    }

    else if ( nMode == MUSIK_PLAYLIST_TYPE_DYNAMIC )
        MessageBox( "This operation is not supported yet.", "Musik", MB_ICONINFORMATION | MB_OK );


    if ( !files.size() )
        return;

    // CStringList containing files
    for ( size_t i = 0; i < files.size(); i++ )
    {
        lsDraggedFiles.AddTail( files.at( i ) );
        uBuffSize += files.at( i ).GetLength() + 1;
    }

    files.clear();

    // Add 1 extra for the final null char, and the size of the DROPFILES struct.
    uBuffSize = sizeof(DROPFILES) + sizeof(TCHAR) * (uBuffSize + 1);

    // Allocate memory from the heap for the DROPFILES struct.
    hgDrop = GlobalAlloc ( GHND | GMEM_SHARE, uBuffSize );

    if ( !hgDrop )
        return;

    pDrop = (DROPFILES*) GlobalLock ( hgDrop );

    if ( !pDrop )
    {
        GlobalFree ( hgDrop );
        return;
    }

    // Fill in the DROPFILES struct.
    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;
    }
}
コード例 #28
0
ファイル: ddmgr.cpp プロジェクト: aolko/construct
///////////////////////////////////////////////////
//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;
        }

        return TRUE;
    }   //catch

    CATCH_ALL(ce)
    {
        return FALSE;
    }
    END_CATCH_ALL
}