Copier une picture dans le presse papier

Résolu
Utilisateur anonyme - 4 oct. 2006 à 10:01
 Utilisateur anonyme - 4 oct. 2006 à 20:14
Bonjour,
je suis actuellement en C++ avec les MFC et GDI+. J'ai une picture qui contient une image, laquelle j'aimerais copier dans le presse papier pour pouvoir faire un simple CTRL+V sous Word et coller mon image. Et je n'y arrive pas car la MSDN c'est la jungle

Merci

7 réponses

Utilisateur anonyme
4 oct. 2006 à 20:14
void CEssaiDlg::OnCopier(CWnd *pWnd)
{
 // TODO: Add your control notification handler code here
 CBitmap bitmap;
 CClientDC dc(pWnd);
 CDC memDC;
 CRect rect;
 int m_nLargeurImage, m_nHauteurImage;
 m_nHauteurImage = RectAffichage.bottom-RectAffichage.top;
 m_nLargeurImage = RectAffichage.right-RectAffichage.left;
 memDC.CreateCompatibleDC(&dc);
 bitmap.CreateCompatibleBitmap(&dc, m_nLargeurImage, m_nHauteurImage);
 CBitmap* pOldBitmap = memDC.SelectObject(&bitmap);
 GetDlgItem (IDC_IMAGE) -> GetWindowRect(rect);
 ScreenToClient(&rect);
 memDC.BitBlt(0,0,rect.Width(), rect.Height(), &dc, rect.left, rect.top, SRCCOPY);
 m_cImageRect.OpenClipboard();
 EmptyClipboard();
 SetClipboardData(CF_BITMAP, bitmap.GetSafeHandle());
 CloseClipboard();
 memDC.SelectObject(pOldBitmap);
 bitmap.Detach();
}
3
niketou Messages postés 295 Date d'inscription dimanche 4 mai 2003 Statut Membre Dernière intervention 6 décembre 2010
4 oct. 2006 à 10:43
OpenClipboard();
HBITMAP myhBmp = myImage.Detach();
EmptyClipboard();
SetClipboardData(CF_BITMAP, myhBmp);
CloseClipboard();
0
Utilisateur anonyme
4 oct. 2006 à 11:16
hihi j'avais deja vu cette réponse avant, je ne sais pas si elle était déja de toi :p
Mais elle ne marche pas, en effet je ne sais pas coment déclarere le MyImage...
en sachant que moi j'ai :

void CEssaiDlg::ChargeImage(int m_nSelectedItem)
{
 //Nouvelle fonction utilisant la bibliothèque gdi+ 
 using namespace Gdiplus;
 CString sDossier;
 CString strPath;


 int m_nLargeurImageSource,m_nHauteurImageSource;
 //double m_fRapportImage;
 //double m_fAgrandissement;




 LPCWSTR pszWide;




 // Lecture du fichier image
 strPath=m_VectorImageNames[m_nSelectedItem];


 USES_CONVERSION;   
 pszWide= A2CW(strPath);    //utilisation des macro de conversion string vers const wchar*
 //Chargement de l'image
 Bitmap BitmapSource(pszWide);  //Chargement de l'image


 //Dimensions de l'image source
 m_nLargeurImageSource=BitmapSource.GetWidth();
 m_nHauteurImageSource=BitmapSource.GetHeight();


 AfficheImage(&BitmapSource);


}


 


void CEssaiDlg::AfficheImage(Bitmap *BitmapAffiche)
{
 //La variable m_bAfficheImage peut être utilisée pour autoriser l'affichage de l'image
 //Surface d'affichage
 CDC*  pDC= m_cImageRect.GetDC();
 //Définition de l'objet graphique
 CRect m_Rect;
 //m_cImageRect.GetWindowRect(&m_Rect);
 m_cImageRect.GetClientRect(&m_Rect);
 Graphics graphicAffiche(pDC->m_hDC);
 CBrush brush;
 brush.CreateSolidBrush(RGB(0,0,0));
 //fond noir
 pDC->FillRect(m_Rect,&brush);  //On a pris le getdc de m_cImageRect donc le pt 0,0 est le bord de m_cImageRect
 //image
 //graphics.DrawImage(image, ImageDesRectf, SrcRectf,UnitPixel,NULL);


  /*CDC* pDC=m_cImageRect.GetDC();
 HDC hDCImage=CreateCompatibleDC(*pDC);
 SelectObject(*hDCImage,BmpResu);
 BitBlt(pDC,m_RectImage.left,m_RectImage.top,m_RectImage.Width(),m_RectImage.Height(),hDCImage,0,0,SRCCOPY);


*/
 graphicAffiche.DrawImage(BitmapAffiche,m_Rect.left,m_Rect.top,m_Rect.Width(),m_Rect.Height()); 
}


 


void CEssaiDlg::OnCopier()
{
 // TODO: Add your control notification handler code here


}
0
niketou Messages postés 295 Date d'inscription dimanche 4 mai 2003 Statut Membre Dernière intervention 6 décembre 2010
4 oct. 2006 à 13:02
CImage myImage;
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
Utilisateur anonyme
4 oct. 2006 à 13:43
CImage n'exsite pas: 'CImage' : undeclared identifier
pourtant j'ai bien le using namespace Gdiplus;
0
niketou Messages postés 295 Date d'inscription dimanche 4 mai 2003 Statut Membre Dernière intervention 6 décembre 2010
4 oct. 2006 à 13:53
bool
CopyBitmapToClipBoard(CBitmap *pBitmap)
{
if(!AfxGetMainWnd()->OpenClipboard()) returnfalse;
if(!EmptyClipboard()) returnfalse;

bool bret=(SetClipboardData(CF_BITMAP, pBitmap->m_hObject)!=NULL);
bret=(CloseClipboard()==TRUE);
return bret;
}

CBitmap *pBmp=CopyWindowToBitmap(this,true);
CopyBitmapToClipBoard(pBmp);
0
Utilisateur anonyme
4 oct. 2006 à 14:35
:s
je fais quoi avec tes fonctions, je vais sur google.fr
developpez.com je les ai trouver, mais j'avais deja tester ca ne voulais pas marcher j'avais quelques erreurs et ton code faisait moins de lignes ^^
0
Rejoignez-nous