一些操作粘贴板的代码

一些操作粘贴板的代码

 

1.CBitmap位图拷贝到粘贴板里面.

 

OpenClipboard();    // 打开粘贴板
EmptyClipboard();   //清空粘贴板
SetClipboardData(CF_BITMAP, bitmap.GetSafeHandle()); 
CloseClipboard();   //关闭粘贴板

 

2.CString字符串拷贝到位图

BOOL CopyStringToClipboard(HWND hWnd, CString str)
{
 USES_CONVERSION;
 // 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

 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 FALSE;

 hMem = ::GlobalReAlloc(hMem, dwLen, GMEM_MOVEABLE | GMEM_DDESHARE | GMEM_ZEROINIT);
 if (!hMem)
  return FALSE;

 // Cache data
 COleDataSource* pSource = new COleDataSource();
 pSource->CacheGlobalData(CF_TEXT, hMem);

 pSource->SetClipboard();

 return TRUE;
}

 

CopyStringToClipboard(NULL,str);

你可能感兴趣的:(c,cache,String,File,null)