1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
| void CMainWindow::OnPaint()
{
CBitmap *OldBitmap;
CBitmap *Bitmap;
CPaintDC dc(this);
CDC *dcMem;
dcMem = new CDC();
dcMem->CreateCompatibleDC(&dc);
CBitmap * pOldBitmap=(CBitmap*) dcMem->SelectObject(m_bmpBitmap);
dc.SetStretchBltMode(HALFTONE); // ou COLORONCOLOR
dc.StretchBlt(0,0,1280,1024,dcMem,0,0,1280,1024,SRCCOPY);
}
void CMainWindow::OnFichierOuvrir()
{
// TODO: Add your command handler code here
OuvrirImage=TRUE;
//this->Invalidate(false);
// Crée un filtre pour la boite de dialogue Ouverture
static char BASED_CODE szFilter[]="Fichiers Bitmap (*.bmp)|*.bmp||";
//Cree la boite de dialogue Ouverture
CFileDialog m_ldFile(TRUE, ".bmp", m_sBitmap, OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT, szFilter);
// Affiche la boite de dialogue Ouverture et capture le résultat
if(m_ldFile.DoModal()==IDOK)
{
// Recupère le nom de fichier sélectionner
m_sBitmap=m_ldFile.GetPathName();
//Charge le fichier Bitmap
HBITMAP hBitmap=(HBITMAP)::LoadImage(AfxGetInstanceHandle(), m_sBitmap, IMAGE_BITMAP, 0,0, LR_LOADFROMFILE|LR_CREATEDIBSECTION);
//AVons nous un handle valide pour l'image chargé
if(hBitmap)
{
//Supprime le bitmap courant
if(m_bmpBitmap.DeleteObject())
{
m_bmpBitmap.Detach();}
m_bmpBitmap.Attach(hBitmap);
}
}
} |
Partager