CWnd::OpenClipboard

Ouvre le presse-papiers.

BOOL OpenClipboard( );

Valeur de retour

Une valeur différente de zéro si le presse-papiers est ouvert via CWnd, ou 0 si une application ou une autre fenêtre a ouvert le presse-papiers.

Notes

D'autres applications ne pourront pas modifier le presse-papiers jusqu'à ce que la fonction Windows de CloseClipboard soit appelée.

L'objet actuel d' CWnd n'ira pas bien au propriétaire du presse-papiers jusqu'à ce que la fonction Windows d' EmptyClipboard soit appelée.

Exemple

//handler for Edit | Copy menu
void CMdiView::OnEditCopy()
{
   if (!OpenClipboard())
   {
      AfxMessageBox(_T("Cannot open the Clipboard"));
      return;
   }
   // Remove the current Clipboard contents  
   if(!EmptyClipboard())
   {
      AfxMessageBox(_T("Cannot empty the Clipboard"));
      return;  
   }

   // Get the currently selected data, hData handle to 
   // global memory of data
   CString str;
   m_Edit.GetWindowText(str);
   size_t cbStr = (str.GetLength() + 1) * sizeof(TCHAR);
   HGLOBAL hData = GlobalAlloc(GMEM_MOVEABLE, cbStr);
   memcpy_s(GlobalLock(hData), cbStr, str.LockBuffer(), cbStr);
   GlobalUnlock(hData);
   str.UnlockBuffer();

   // For the appropriate data formats...
   UINT uiFormat = (sizeof(TCHAR) == sizeof(WCHAR)) ? CF_UNICODETEXT : CF_TEXT;
   if (::SetClipboardData(uiFormat, hData) == NULL)  
   {
      AfxMessageBox(_T("Unable to set Clipboard data"));    
      CloseClipboard();
      return;  
   }  

   CloseClipboard();
}

Configuration requise

Header: afxwin.h

Voir aussi

Référence

CWnd, classe

Graphique de la hiérarchie

CloseClipboard

EmptyClipboard

OpenClipboard