开发学院软件开发C++ 将文件copy到剪贴板上 阅读

将文件copy到剪贴板上

 2008-03-08 12:44:43 来源:WEB开发网   
核心提示:bool CopyToClipboard(AnsiString file);//---__fastcall TForm1::TForm1(TComponent* Owner): TForm(Owner){}//---void __fastcall TForm1::Button1Click(TObject *Sender

  bool CopyToClipboard(AnsiString file);
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
    : TForm(Owner)
{
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button1Click(TObject *Sender)
{
  CopyToClipboard("C:\\scandisk.log");
}
//---------------------------------------------------------------------------
//收集整理:http://www.ccrun.com (C++ Builder 研究)
//---------------------------------------------------------------------------
bool CopyToClipboard(AnsiString file)
{
  int nLen;
  char* Data;
  HANDLE hMem;

  if (file.IsEmpty()) return false;

  nLen = 20 + file.Length() + 2;
  hMem = GlobalAlloc(GMEM_MOVEABLE
    GMEM_DDESHAREGMEM_ZEROIN99v,
    nLen);
  if (hMem==NULL) return false;
  Data = (char*)GlobalLock(hMem);
  *(DWord*)Data = 20;
  strcpy(Data+20, file.c_str());
  GlobalUnlock(hMem);
  if (OpenClipboard(NULL)) {
    EmptyClipboard(); 
    if (SetClipboardData(
      CF_HDROP,hMem)!=0)
      hMem = NULL;
    CloseClipboard();
  }
  if (hMem) GlobalFree(hMem);

  return hMem ? false : true;
}

Tags:文件 copy 剪贴板

编辑录入:爽爽 [复制链接] [打 印]
[]
  • 好
  • 好的评价 如果觉得好,就请您
      0%(0)
  • 差
  • 差的评价 如果觉得差,就请您
      0%(0)
赞助商链接