posted by 쑥갓 2007.02.14 17:27

자주 까먹어서 포스팅

void CopyClipboard( IN const tstring strTemp )
{
 if( ::OpenClipboard( NULL ) )
 {
  ::EmptyClipboard();

  HGLOBAL hBlock = ::GlobalAlloc( GMEM_MOVEABLE, sizeof(TCHAR) * ( strTemp.size() + 1 ) );
  if( hBlock )
  {
   TCHAR *pwszText = (TCHAR*)::GlobalLock( hBlock );
   if( pwszText )
   {
    _tcscpy( pwszText, strTemp.c_str() );
    ::GlobalUnlock( hBlock );
   }
   ::SetClipboardData( CF_UNICODETEXT, hBlock );
  }
  ::CloseClipboard();
  // We must not free the object until CloseClipboard is called.
  if( hBlock )
   ::GlobalFree( hBlock );
 }
}

OUT const tstring GetClipboard()
{
 if( ::OpenClipboard( NULL ) )
 {
  if( ::IsClipboardFormatAvailable( CF_UNICODETEXT ) == TRUE )
  {
   HANDLE hMem;
   hMem = ::GetClipboardData( CF_UNICODETEXT );
   const tstring reStr = (LPCTSTR)GlobalLock((HGLOBAL)hMem );
   GlobalUnlock( (HGLOBAL)hMem );

   return reStr;
  }
  ::CloseClipboard();
 }

 return tstring();
}


티스토리 툴바