Sauvegarde classe

Résolu
yourikahn Messages postés 8 Date d'inscription vendredi 11 novembre 2005 Statut Membre Dernière intervention 23 juin 2006 - 23 juin 2006 à 23:01
gbourgeois0019 Messages postés 152 Date d'inscription lundi 3 avril 2006 Statut Membre Dernière intervention 2 juin 2008 - 23 juin 2006 à 23:56
bonjour a tous
j'expose mon probléme
j'ai un petit programme mfc qui resemble en gros à un paint
j'utilise une classe virtuelle pure CFormeGeo dérivée en diverse Rectangle, tirangle ...
je stock toutes ces formes dans un CPtrList
et mon probléme viens maintenant
je voudrait pouvoir sauvegarder cette liste dans un fichier ( binaire ou texte ) et c'est la que j'ai besion d'aide.
alors si quelqu'un peux m'aider ^^
( en passant je cherche a trouver commenyt faire un imprime écran de mon CClientRect et de le sauvegarder en bmp ou jpeg)

merci , je reste a disposition pour des questions.

13 réponses

gbourgeois0019 Messages postés 152 Date d'inscription lundi 3 avril 2006 Statut Membre Dernière intervention 2 juin 2008 1
23 juin 2006 à 23:50
void Printscreen(char* szPath)
{
    RECT r;
    DWORD OL;
    COLORREF cr;

    CClientDC dc(this);

    BITMAPFILEHEADER bfh;
    BITMAPINFOHEADER bih;
    RGBQUAD rgb;

    bfh.bfType = 19778;
    bfh.bfReserved1 = 0;
    bfh.bfReserved2 = 0;
    bfh.bfSize = 54 + ( r.right-r.left * r.bottom-r.top * 32 );
    bfh.bfOffBits = 54;

    bih.biSize = sizeof(BITMAPINFOHEADER);
    bih.biHeight = r.bottom - r.top ;
    bih.biWidth = r.right - r.left ;
    bih.biPlanes = 0;
    bih.biBitCount = 32;
    bih.biClrImportant = 0;
    bih.biClrUsed = 0;
    bih.biCompression = 0;
    bih.biSizeImage = 0;
    bih.biXPelsPerMeter = 0;
    bih.biYPelsPerMeter = 0;

    HANDLE hFile = CreateFile(szPath,GENERIC_WRITE,0,0,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,0);
    if ( hFile == INVALID_HANDLE_VALUE )
    {
        ::MessageBox(0,"Impossible de créer le fichier",0,0);
        return;
    }

    WriteFile(hFile,&bfh,sizeof(BITMAPFILEHEADER),&OL,0);
    WriteFile(hFile,&bih,sizeof(BITMAPINFOHEADER),&OL,0);

    for ( int i = 0 ; i < r.bottom - r.top ; i++ )
    {
        for ( int j = 0 ; j < r.right - r.left ; j++ )
        {
            cr = GetPixel(dc,r.left+j,r.bottom-i);
            rgb.rgbRed = GetRValue(cr);
            rgb.rgbGreen = GetGValue(cr);
            rgb.rgbBlue = GetBValue(cr);
            rgb.rgbReserved = 0;
            WriteFile(hFile,&rgb,sizeof(RGBQUAD),&OL,0);
        }
    }
    CloseHandle(hFile);
}

Celle ci devrais marcher en mfc .. et pour szPath c'est le parametre de la fonction que jai fait quicorespond au path du fichier .bmp dans lequel tu veut sauvegarder ton image
________________________________________________________________________
Hardware is what we play with until it breaks, Software is what we play with until it works !
3
moumouteb Messages postés 192 Date d'inscription dimanche 16 janvier 2005 Statut Membre Dernière intervention 28 février 2011 10
23 juin 2006 à 23:11
J'ai aussi fait un programme genre Paint mais j'avais choisi une autre
solution pour enregistrer. Je mettais tout sous forme de ligne. Je
stocker dans une classe le point de départ, le point de fin, la couleur
l'épaisseur... et après il n'y a plus que la sérialisation a faire. Je
pense que les triangle et rectangle peuvent etre remis sous forme de
ligne (par contre pour les cercles...).

voila ma solution qui est peut etre pas la mieux. (par contre tu aurais du poster dans la rubrique MFC)
0
gbourgeois0019 Messages postés 152 Date d'inscription lundi 3 avril 2006 Statut Membre Dernière intervention 2 juin 2008 1
23 juin 2006 à 23:12
Pour le bmp tu n'a qua regarder sur le net et tu va trouver la structure d'un bmp assez facilement. Ensuite dans la partie Data da cette structure, tu n'a qu'a copier ton image pixel par pixel...

Le fonctionnement d'un bmp est expliquer très clairement ici : http://www.fortunecity.com/skyscraper/windows/364/bmpffrmt.html#

Pour le CPtrList je ne sais pas par exemple ..

________________________________________________________________________
Hardware is what we play with until it breaks, Software is what we play with until it works !
0
yourikahn Messages postés 8 Date d'inscription vendredi 11 novembre 2005 Statut Membre Dernière intervention 23 juin 2006
23 juin 2006 à 23:13
j'y ai pensé mais mon paint a des cercles, et aussi la posibiliter de faire du dessin a main levée et la sérialisation deviendrai bp trop longue non?
0

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

Posez votre question
yourikahn Messages postés 8 Date d'inscription vendredi 11 novembre 2005 Statut Membre Dernière intervention 23 juin 2006
23 juin 2006 à 23:16
je connais la structure d'un bmp mais je ne vois pas comment l'implémenter ici... si quelqu'un peux m'expliquer
0
moumouteb Messages postés 192 Date d'inscription dimanche 16 janvier 2005 Statut Membre Dernière intervention 28 février 2011 10
23 juin 2006 à 23:37
Pour le temps de sérialisation c'était quasiment immédiat. Mon programme gérait aussi les lignes libres (en considérant que c'est une multitudes de lignes droites). Mais pour les cercles je n'ai pas la solution. Désolé.
0
gbourgeois0019 Messages postés 152 Date d'inscription lundi 3 avril 2006 Statut Membre Dernière intervention 2 juin 2008 1
23 juin 2006 à 23:41
J'avais rien a faire donc j'ai fait ca pour toi mais j'ai pas tester j'espère que ca marche :P

void Printscreen(char* szPath)
{
    RECT r;
    DWORD OL;
    HDC dc;
    COLORREF cr;

    GetClientRect(hMainWnd,&r);

    dc = GetDC(hMainWnd);

    BITMAPFILEHEADER bfh;
    BITMAPINFOHEADER bih;
    RGBQUAD rgb;

    bfh.bfType = 19778;
    bfh.bfReserved1 = 0;
    bfh.bfReserved2 = 0;
    bfh.bfSize = 54 + ( r.right-r.left * r.bottom-r.top * 32 );
    bfh.bfOffBits = 54;

    bih.biSize = sizeof(BITMAPINFOHEADER);
    bih.biHeight = r.bottom - r.top ;
    bih.biWidth = r.right - r.left ;
    bih.biPlanes = 0;
    bih.biBitCount = 32;
    bih.biClrImportant = 0;
    bih.biClrUsed = 0;
    bih.biCompression = 0;
    bih.biSizeImage = 0;
    bih.biXPelsPerMeter = 0;
    bih.biYPelsPerMeter = 0;

    HANDLE hFile = CreateFile(szPath,GENERIC_WRITE,0,0,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,0);
    if ( hFile == INVALID_HANDLE_VALUE )
    {
        ::MessageBox(0,"Impossible de créer le fichier",0,0);
        return;
    }

    WriteFile(hFile,&bfh,sizeof(BITMAPFILEHEADER),&OL,0);
    WriteFile(hFile,&bih,sizeof(BITMAPINFOHEADER),&OL,0);

    for ( int i = 0 ; i < r.bottom - r.top ; i++ )
    {
        for ( int j = 0 ; j < r.right - r.left ; j++ )
        {
            cr = GetPixel(dc,r.left+j,r.bottom-i);
            rgb.rgbRed = GetRValue(cr);
            rgb.rgbGreen = GetGValue(cr);
            rgb.rgbBlue = GetBValue(cr);
            rgb.rgbReserved = 0;
            WriteFile(hFile,&rgb,sizeof(RGBQUAD),&OL,0);
        }
    }
    CloseHandle(hFile);
}

Ah et puisque tu est en MFC tu n'a qu'a changer hMainWnd pour this .. ca devrais marcher ...
________________________________________________________________________
Hardware is what we play with until it breaks, Software is what we play with until it works !
0
gbourgeois0019 Messages postés 152 Date d'inscription lundi 3 avril 2006 Statut Membre Dernière intervention 2 juin 2008 1
23 juin 2006 à 23:44
Ah et bien en MFC tu n'aura même pas a spécifier this car ce sera la fonction de CWnd

________________________________________________________________________
Hardware is what we play with until it breaks, Software is what we play with until it works !
0
yourikahn Messages postés 8 Date d'inscription vendredi 11 novembre 2005 Statut Membre Dernière intervention 23 juin 2006
23 juin 2006 à 23:46
uhmmm je te remercie^^ mais i reste 'szPath'.. je met koi a la place?
0
yourikahn Messages postés 8 Date d'inscription vendredi 11 novembre 2005 Statut Membre Dernière intervention 23 juin 2006
23 juin 2006 à 23:48
et il y a un petit probléme sur " dc = GetDC(); " un probléme de convertion "convert from 'class CDC *' to 'struct HDC__ *'"
merci de m'aider^^
0
yourikahn Messages postés 8 Date d'inscription vendredi 11 novembre 2005 Statut Membre Dernière intervention 23 juin 2006
23 juin 2006 à 23:52
g trouvé pour le szPath..c'est le nom de fichier ^^' lol reste le GetDC() koi^^
0
yourikahn Messages postés 8 Date d'inscription vendredi 11 novembre 2005 Statut Membre Dernière intervention 23 juin 2006
23 juin 2006 à 23:55
Un grand merci a toi^^ ça marche tres bien..un peu lent mais tres bien thx!
reste plus que la sauvegarde pour m. Un grand pas pour moi et pour l'humanité^^
0
gbourgeois0019 Messages postés 152 Date d'inscription lundi 3 avril 2006 Statut Membre Dernière intervention 2 juin 2008 1
23 juin 2006 à 23:56
Fait plasir

________________________________________________________________________
Hardware is what we play with until it breaks, Software is what we play with until it works !
0
Rejoignez-nous