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; }
void CLeftView::OnEditPaste() { // CG: このブロックはクリップボード アシスタント コンポーネントによって追加されました { if (OpenClipboard()) { HANDLE hData = ::GetClipboardData(m_nClipboardFormat); if (hData != NULL) { CSharedFile memFile; memFile.SetHandle(hData,FALSE); CArchive ar(&memFile, CArchive::load); // データをドキュメントへシリアライズ DoCutCopyPaste(ar, FALSE); ar.Close(); memFile.Detach(); } else AfxMessageBox(CG_IDS_CANNOT_GET_CLIPBOARD_DATA); CloseClipboard(); } else AfxMessageBox(CG_IDS_CANNOT_OPEN_CLIPBOARD); } }
void CRectItem::GetNativeClipboardData(COleDataSource* pDataSource) { ASSERT_VALID(this); ASSERT_VALID(GetDocument()); // Create a shared file and associate a CArchive with it CSharedFile file; CArchive ar(&file, CArchive::store); // Serialize selected objects to the archive Serialize(ar); ar.Close(); pDataSource->CacheGlobalData(CMainDoc::m_cfPrivate, file.Detach()); }
void CLeftView::OnEditCut() { // CG: このブロックはクリップボード アシスタント コンポーネントによって追加されました { CSharedFile memFile; CArchive ar(&memFile, CArchive::store|CArchive::bNoFlushOnDelete); // シリアライズ データをアーカイブ オブジェクトへ DoCutCopyPaste(ar, TRUE); ar.Flush(); HGLOBAL hData = memFile.Detach(); if (OpenClipboard()) { ::SetClipboardData(m_nClipboardFormat, hData); CloseClipboard(); } else AfxMessageBox(CG_IDS_CANNOT_OPEN_CLIPBOARD); } }
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); }
//-------------------------------------------------------------------// // ArchiveAndRenderClipFormats() // //-------------------------------------------------------------------// // This routine takes the drag data, provided within the members of // this object by the object that owns this one, creates a memory // file and archive to process the data, and renders the data to the // clipboard using the supplied data source. The data will then // be available for drop targets to extract it. // The clipboard formats associated with the data include the // CF_OLE_DRAG_DATA type, which identifies the data as a // OleDragData object. The extraction always uses the // CF_OLE_DRAG_DATA type. //-------------------------------------------------------------------// void OleListCtrl::ArchiveAndRenderClipFormats( COleDataSource* pSource ) { // Prepare to archive the data. // Create a shared file and associate a CArchive with it CSharedFile DataMemFile; // TO DO // BoundsChecker is telling us, the first time we // hit this code and close the archive, that the // flags are illegal. What flags is it referring to? // The store flag here? Research. CArchive DataArchive( &DataMemFile, CArchive::store ); // Archive the count. int nCount = Items.GetSize(); DataArchive.Write( &nCount, sizeof( nCount ) ); // Loop through the items array and archive. int i; OleDragItem* pItem; for ( i = 0; i < nCount; i++ ) { pItem = &( Items[i] ); // Write the next item. // This MUST MATCH the order in the read function. // First, write the column names. DataArchive << pItem->m_strName; // Set the item's checked state. DataArchive << (BYTE)pItem->m_bChecked; // Now dump any data that is attached via the lParam. // This is a virtual function that is overridden in derived // classes so that we dump the actual contents of the data // pointed to by the lParam, if any. WriteLParam( &DataArchive, pItem->m_lParam ); } // We need to close the archive before caching the data. DataArchive.Close(); // We now render a clip format that contains the entire // drag data array. This format is common to all classes // that use OleDragData. // CLIPFORMAT ClipFormat = CF_OLE_DRAG_DATA; CLIPFORMAT ClipFormat = RegisterClipboardFormat( cszOleDragData ); // This immediately renders the data. // DelayRenderData is an alternative that delays rendering of the // data until needed. pSource->CacheGlobalData( ClipFormat, DataMemFile.Detach() ); // Note: Don't free the global allocation, that will be done by the // data source. // TO DO // TEXT CLIPFORMAT CF_TEXT // Clear the items array, now that we have archived it. Items.RemoveAll(); }
void CSimpleReport::Paste() { if (IsVirtualMode()) return; CWaitCursor _WC; CLIPFORMAT uCF_Records = (CLIPFORMAT)::RegisterClipboardFormat(XTPREPORTCTRL_CF_RECORDS); CXTPReportRecords arRecords; BOOL bTryPasteFromText = TRUE; // Retrieve text from the clipboard if (!OpenClipboard()) return; if (::IsClipboardFormatAvailable(uCF_Records)) { HGLOBAL hPasteData = ::GetClipboardData(uCF_Records); if (hPasteData) { bTryPasteFromText = FALSE; const int cErrTextSize = 1024; TCHAR szErrText[cErrTextSize + 1]; CSharedFile fileSahred; fileSahred.SetHandle(hPasteData, FALSE); CArchive ar(&fileSahred, CArchive::load); try { CXTPPropExchangeArchive px(ar); BOOL bread = FALSE; #if _XTPLIB_VERSION_PREFIX == 1502 bread = _ReadRecordsFromData(&px, arRecords); #else bread = _ReadRecodsFromData(&px, arRecords); #endif if (!bread) { arRecords.RemoveAll(); } } catch(CArchiveException* pE) { if (pE->GetErrorMessage(szErrText, cErrTextSize)) { TRACE(_T("EXCEPTION: CXTPReportControl::Paste() - %s\n"), szErrText); } pE->Delete(); } catch(CFileException* pE) { if (pE->GetErrorMessage(szErrText, cErrTextSize)) { TRACE(_T("EXCEPTION: CXTPReportControl::Paste() - %s\n"), szErrText); } pE->Delete(); } catch(...) { TRACE(_T("EXCEPTION: CXTPReportControl::Paste() - Unhandled Exception!\n")); } //********* ar.Close(); // detach from file fileSahred.Detach(); //detach from data ::GlobalUnlock(hPasteData); // unlock data } } UINT uCF_TText = sizeof(TCHAR) == 2 ? CF_UNICODETEXT : CF_TEXT; if (bTryPasteFromText && ::IsClipboardFormatAvailable(uCF_TText)) { // Try to get text data from the clipboard HGLOBAL hglbPaste = ::GetClipboardData(uCF_TText); // Import Text data into the control if (hglbPaste != NULL) { TCHAR* lpszClipboard = (TCHAR*)GlobalLock(hglbPaste); BOOL bRead = FALSE; #if _XTPLIB_VERSION_PREFIX == 1502 bRead = _ReadRecordsFromText(lpszClipboard, arRecords); #else bRead = _ReadRecodsFromText(lpszClipboard, arRecords); #endif if (!bRead) { arRecords.RemoveAll(); } ::GlobalUnlock(hglbPaste); } } ::CloseClipboard(); ////////////////////////////////////////////////////////////////////////// CUpdateContext updateContext(this); // Add and Populate records CXTPReportRow* pRow = GetFocusedRow(); if (pRow == NULL) return; int n = pRow->GetRecord()->GetIndex(); int nRecordsCount = arRecords.GetCount(); if (nRecordsCount > 0) { for (int i = nRecordsCount - 1; i >= 0; i--) { CXTPReportRecord* pRecord = arRecords.GetAt(i); if (pRecord) { CMDTARGET_ADDREF(pRecord); if (m_bAdd) GetRecords()->Add(arRecords.GetAt(i)); else GetRecords()->InsertAt(n, arRecords.GetAt(i)); } } Populate(); _SelectRows(&arRecords); } m_bAdd = false; }