关于copy/paste和Dragdrop的问题 CF_ENHMETADATA

CSDN上的一个帖子,我好像没有遇到问题,楼主的代码我也没有仔细调

关于copy/paste和Dragdrop的问题。

楼主aqua_aqua(丁丁) 2002-10-29 16:07:58 在 VC/MFC / 基础类 提问

我在我的应用程序中增加了copy/paste和DragDrop功能,我把原来的window_Format   matefile改成了enhanced-format   metafile,这时我的程序可以和安全的向word中进行copy/paste,但不能dragdrop(拖放),在拖源方一切正常,当我在word是松开拖放键时,系统会提示我“内存不足”警告。我不明白为什么.  
   
  下面是我ServerItem类的部分代码。  
   
  //当对象调用CopyToClipboard和DoDragDrop时,OnGetClipboard被自动调用。  
  COleDataSource*   CSrvrItem::OnGetClipboardData(BOOL   bIncludeLink,  
  LPPOINT   pptOffset,   LPSIZE   pSize)  
  {  
  ASSERT_VALID(this);  
  COleDataSource*   pDataSource   =   new   COleDataSource;  
  TRY  
  {  
  GetNativeClipboardData(pDataSource);  
  GetEnhMetaFileToClip(pDataSource);//增加增强图元到数据对象。  
  GetClipboardData(pDataSource,   bIncludeLink,   pptOffset,   pSize);  
  //把即将复制到剪贴板中的所有数据(如果调用CopyToClipboard)填充指定的COleDataSource对象中  
  }  
  CATCH_ALL(e)  
  {  
  delete   pDataSource;  
  THROW_LAST();  
  }  
  END_CATCH_ALL  
  ASSERT_VALID(pDataSource);  
  return   pDataSource;  
  }  
   
  //被OnGetClipboardData所调用。  
  void   CSrvrItem::GetNativeClipboardData(COleDataSource   *pDataSource)  
  {  
  ASSERT_VALID(this);  
  ASSERT(CCvtGraphDoc::m_cfFirst   !=   NULL);  
   
  //   Create   a   shared   file   and   associate   a   CArchive   with   it  
  CSharedFile   file;  
  CArchive   ar(&file,CArchive::store);  
   
  //   Serialize   selected   objects   to   the   archive  
  dview.m_selection.Serialize(ar);  
  ar.Close();  
   
  //   put   on   local   format   instead   of   or   in   addation   to   COleDataSource  
  pDataSource->CacheGlobalData(CCvtGraphDoc::m_cfFirst,file.Detach());  
  }  
   
  //重载函数。  
  BOOL   CSrvrItem::OnRenderData(   LPFORMATETC   lpFormatEtc,   LPSTGMEDIUM   lpStgMedium   )  
  {  
  ASSERT_VALID(this);  
  ASSERT(AfxIsValidAddress(lpFormatEtc,   sizeof(FORMATETC),   FALSE));  
  ASSERT(AfxIsValidAddress(lpStgMedium,   sizeof(STGMEDIUM)));  
   
  //   default   implementation   does   not   support   extended   layout  
  if   (lpFormatEtc->lindex   !=   -1)  
  return   FALSE;  
   
  //   default   implementation   supports   both   types   of   metafiles  
  //去掉原先的Window_format   metafile支持。  
  //if   (lpFormatEtc->cfFormat   ==   CF_METAFILEPICT)  
  //   return   GetMetafileData(lpFormatEtc,   lpStgMedium);  
   
  return   FALSE;   //   cfFormat   not   supported  
  }  
   
  void   CSrvrItem::GetEnhMetaFileToClip(COleDataSource*   pDataSource)  
  {  
  //   Obtain   a   handle   to   a   reference   DC.  
   
  HDC   hdcRef   =   GetDC(gpView->m_hWnd);  
   
  //   Determine   the   picture   frame   dimensions.  
  //   iWidthMM   is   the   display   width   in   millimeters.  
  //   iHeightMM   is   the   display   height   in   millimeters.  
  //   iWidthPels   is   the   display   width   in   pixels.  
  //   iHeightPels   is   the   display   height   in   pixels.  
   
  int   iWidthMM   =   GetDeviceCaps(hdcRef,   HORZSIZE);  
  int   iHeightMM   =   GetDeviceCaps(hdcRef,   VERTSIZE);  
  int   iWidthPels   =   GetDeviceCaps(hdcRef,   HORZRES);  
  int   iHeightPels   =   GetDeviceCaps(hdcRef,   VERTRES);  
   
  //   Use   iWidthMM,   iWidthPels,   iHeightMM,   and   iHeightPels   to   determine   the   number   of   .01-millimeter   units   per   pixel   in   the   x   and   y   directions.  
   
  int   iMMPerPelX   =   (iWidthMM   *   100)/iWidthPels;  
  int   iMMPerPelY   =   (iHeightMM   *   100)/iHeightPels;  
   
  CClientDC   dc(gpView);  
  CRect   rcSelBox;  
  gpView->OnPrepareDC(&dc);  
  dview.CalcSelectedItemRect(&dc,rcSelBox);  
   
  //convert   from   the   word   coordinates   to   the   client   coordinates;  
  dview.DocToClient(rcSelBox,gpView);  
   
  CPoint   ptTopLeft   =   rcSelBox.TopLeft();  
   
  CSize   rSize   =   rcSelBox.Size();  
  AdjustSize(rSize);//适当调整包围盒大小。  
   
  //   Convert   client   coordinates   to   .01-mm   units.    
  rSize.cx   =   rSize.cx   *   iMMPerPelX;  
  rSize.cy   =   rSize.cy   *   iMMPerPelY;  
   
  ptTopLeft   =   CPoint   (0,0);  
  CRect   rcNew(ptTopLeft,rSize);  
   
  CClientDC   cdc(gpView);  
   
  CMetaFileDC   *   pMetaDC   =   new   CMetaFileDC();  
  BOOL   bRet   =   pMetaDC->CreateEnhanced(&cdc,NULL,rcNew,"whatever");  
  if(bRet   ==   FALSE)  
  {  
  TRACE("Create   Enhanced   metafile   failed!/n");  
  return;  
  }  
   
  //   create   attribute   DC   according   to   lpFormatEtc->ptd  
  HDC   hAttribDC   =   ::GetDC(gpView->GetSafeHwnd());  
  if   (hAttribDC   ==   NULL)  
  {  
  TRACE("Create   attribute   DC   failed!/n");  
  return;  
  }  
  pMetaDC->SetAttribDC(hAttribDC);  
   
  CSize   size;  
  this->OnDraw(pMetaDC);   //在增加图元中画。  
   
  pMetaDC->HIMETRICtoLP(&rSize);  
   
  pMetaDC->SetAttribDC(NULL);  
  ::DeleteDC(hAttribDC);    
   
  //close   meta   file   dc   and   prepare   for   clipboard;  
  HENHMETAFILE   hMF   =   pMetaDC->CloseEnhanced();  
   
  tagSTGMEDIUM   *   data   =   new   tagSTGMEDIUM;  
  data->tymed   =   TYMED_ENHMF;  
  data->hEnhMetaFile   =   hMF;  
  data->pUnkForRelease   =   NULL;  
   
  tagFORMATETC*   fec   =   new   tagFORMATETC;  
  fec->cfFormat   =   CF_ENHMETAFILE;  
  fec->dwAspect   =   DVASPECT_CONTENT;  
  fec->ptd   =   NULL;  
  fec->tymed   =   TYMED_ENHMF;  
  fec->lindex   =   -1;  
   
  pDataSource->CacheData(CF_ENHMETAFILE,   data,fec);  
  delete   pMetaDC;  
  }   
   

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,你可以使用以下代码来读取`/Analysis_B/20220326_JNILI/014_seqtk/new_name/new_list.csv`文件,过滤出每个样本的子集,并使用`Biostrings`包的`names()`函数重新命名序列。 ``` library(Biostrings) # 读取new_list.csv文件 new_list <- read.csv("/Analysis_B/20220326_JNILI/014_seqtk/new_name/new_list.csv", header = TRUE, stringsAsFactors = FALSE) # 遍历每个样本 for (sample in unique(new_list$Sample)) { # 过滤出当前样本的子集 subset <- new_list[new_list$Sample == sample, ] # 读取该样本的.fa文件 sequences <- read.fasta(paste0("/Analysis_B/20220326_JNILI/014_seqtk/002_subseq/", sample, ".fa")) # 将.fa文件中的序列名称修改为新名称 old_names <- subset$OldName new_names <- subset$NewName names(sequences) <- new_names[match(names(sequences), old_names)] # 保存修改后的.fa文件 write.fasta(sequences, file = paste0("/Analysis_B/20220326_JNILI/014_seqtk/002_subseq/", sample, "_new.fa")) } ``` 这里的`/Analysis_B/20220326_JNILI/014_seqtk/new_name/new_list.csv`文件中包含了三列数据:`Sample`、`OldName`和`NewName`。我们首先使用`read.csv()`函数读取该文件。然后,我们遍历`new_list.csv`文件中的每个样本,使用`unique()`函数获取样本列表。 在遍历每个样本时,我们使用`new_list`数据框的`Sample`列过滤出当前样本的子集,即`subset`。然后,我们使用`read.fasta()`函数读取该样本的.fa文件,得到一个`DNAStringSet`或`AAStringSet`对象`sequences`。接着,我们使用`names()`函数将`sequences`对象中的序列名称修改为`NewName`列中的名称。这里使用了`match()`函数来找到`OldName`列和`sequences`对象中的名称的对应关系。最后,我们使用`write.fasta()`函数将修改后的.fa文件保存下来。需要注意的是,我们在保存修改后的.fa文件时,文件名中加了一个`_new`的后缀,以区别于原始的.fa文件。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值