将文件复制到剪贴板上
当前位置:以往代写 > C/C++ 教程 >将文件复制到剪贴板上
2019-06-13

将文件复制到剪贴板上

将文件复制到剪贴板上

bool CopyToClipboard(AnsiString file);
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
     : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
   CopyToClipboard("C:\\scandisk.log");
}
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_DDESHARE|GMEM_ZEROINIT,
     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;
}

    关键字:

在线提交作业