本文整理汇总了C++中COleDataSource::SetClipboard方法的典型用法代码示例。如果您正苦于以下问题:C++ COleDataSource::SetClipboard方法的具体用法?C++ COleDataSource::SetClipboard怎么用?C++ COleDataSource::SetClipboard使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类COleDataSource
的用法示例。
在下文中一共展示了COleDataSource::SetClipboard方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: OnEditCopy
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: Copy
//-------------------------------------------------------------------//
// 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();
}
示例3: SaveObject
void CEx27bView::OnEditCopy()
{
COleDataSource* pSource = SaveObject();
if(pSource) {
pSource->SetClipboard(); // OLE deletes data source
}
}
示例4: OnLibCopy
void CModuleWnd::OnLibCopy()
{
COleDataSource* pDataSource = PrepareDataSource();
ASSERT_VALID(pDataSource);
pDataSource->SetClipboard();
}
示例5: OnEditCopy
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
}
示例6: CopyToClipboard
void COleServerItem::CopyToClipboard(BOOL bIncludeLink)
{
ASSERT_VALID(this);
COleDataSource* pDataSource = OnGetClipboardData(bIncludeLink, NULL, NULL);
// put it on the clipboard
pDataSource->SetClipboard();
}
示例7: CopyToClipboard
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
}
示例8: OnCopyToClipboard
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);
}
}
示例9: Copy
/***
拷贝列表到剪贴板
*/
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();
}
示例10: 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;
//.........这里部分代码省略.........