IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

MFC Discussion :

inserer une image BMP dans un fichier rtf


Sujet :

MFC

  1. #1
    Membre régulier
    Avatar de Alice9
    Profil pro
    Inscrit en
    Mai 2004
    Messages
    124
    Détails du profil
    Informations personnelles :
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations forums :
    Inscription : Mai 2004
    Messages : 124
    Points : 85
    Points
    85
    Par défaut inserer une image BMP dans un fichier rtf
    Bonjour,

    Je cherche à intégrer une image BMP dans un fichier rtf.

    En faît j'ai déjà repéré l'entête d'un fichier bmp en rtf :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    {\\object\\objemb{\\*\\objclass Paint.Picture}\\objw19197\\objh15358{\\*\\objdata
    ainsi que la fin de l'image :

    Je récupère le bmp avec un :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
     
    HBITMAP hBitmap = (HBITMAP) LoadImage( 0, 
    pathBmp, 
    IMAGE_BITMAP, 
    0,0, 
    LR_LOADFROMFILE );
    Ce qui me pose problème c'est comment récupérer le contenu du bmp pour pouvoir le retranscrire dans un fichier rtf.
    Je pensai le recopier par mémorisation ligne par ligne et retranscription via fprintf(buffer,file)

    Si vous pouviez me donner des pistes ce serait vraiment sympa.

    Merci

    Alice
    Alice

    A coeur vaillant, rien d'impossible !

  2. #2
    Rédacteur
    Avatar de farscape
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Novembre 2003
    Messages
    9 055
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Alpes Maritimes (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Novembre 2003
    Messages : 9 055
    Points : 17 323
    Points
    17 323
    Par défaut
    salut,
    tu devrais regarder cet article sur codeguru:
    http://www.codeguru.com/Cpp/controls/richedit/article.php/c5383/

  3. #3
    Membre régulier
    Avatar de Alice9
    Profil pro
    Inscrit en
    Mai 2004
    Messages
    124
    Détails du profil
    Informations personnelles :
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations forums :
    Inscription : Mai 2004
    Messages : 124
    Points : 85
    Points
    85
    Par défaut re Bmp dans un RTF
    Attention,

    je n'ai jamais dis que je travaillai avec des RichEdit Control.

    Je travaille avec une interface boîte de dialogue donc pas accès à tout ce qui est traitement de texte/images comme dans wordPad.

    deplus je n'ai jamais prétendu que je travaillai comme lui.

    En faîte cela apparait comme invisible pour l'utilisateur.

    Seulement j'ai un fichier rtf que je sais manipuler et une image bmp que je souhaite intégrer dans ce fichier !

    Donc ma question est comment peut on lire une image BMP.

    Je pensais l'ouvrir avec un fopen puis lire l'entête et récupérer les données. Mais cela me fait n'importe quoi.

    Mais quand même merci pour cette réponse.

    Alice
    Alice

    A coeur vaillant, rien d'impossible !

  4. #4
    Rédacteur
    Avatar de farscape
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Novembre 2003
    Messages
    9 055
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Alpes Maritimes (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Novembre 2003
    Messages : 9 055
    Points : 17 323
    Points
    17 323
    Par défaut
    bonsoir,
    le richedit travaille avec des fichiers au format rtf....

  5. #5
    Membre régulier
    Avatar de Alice9
    Profil pro
    Inscrit en
    Mai 2004
    Messages
    124
    Détails du profil
    Informations personnelles :
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations forums :
    Inscription : Mai 2004
    Messages : 124
    Points : 85
    Points
    85
    Par défaut re rtf et BMP
    Bonjour,

    Tout d'abord, j'ai saisi comment insérer la bitmap mais mon plus gros soucis est pour la création du cRichEditCtrl.
    Comment peux tu créer un CRichEditCtrl et lui mettre un fichier précis sans créer une interface visible par l'utilisateur ?
    Bien que j'ai étudié sa class members je n'ai pas du tout trouvé une fonction le permettant. En regardant le code guru que tu m'as transmis, j'ai vu qu'ils utilisaient Hors je ne souhaite pas passer par la "p'tite boîte" de parcours de fichier vu que je connais exactement le chemin du fichier à modifier

    merci de ta patience

    Alice
    Alice

    A coeur vaillant, rien d'impossible !

  6. #6
    Rédacteur
    Avatar de farscape
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Novembre 2003
    Messages
    9 055
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Alpes Maritimes (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Novembre 2003
    Messages : 9 055
    Points : 17 323
    Points
    17 323
    Par défaut
    re,
    essaye ça
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
     
    class CAboutDlg : public CDialog
    {
    public:
    	CAboutDlg();
    	static DWORD CALLBACK RichEditStreamInCallback(DWORD dwCookie,LPBYTE pbBuff, LONG cb, LONG FAR *pcb); 
    	static DWORD CALLBACK CAboutDlg::RichEditStreamOutCallback(DWORD dwCookie, 
    								  LPBYTE pbBuff, LONG cb, LONG FAR *pcb);
     
     
    	bool	m_bNewFile;
    	CString m_strRtfFileName;
    	HANDLE  m_hFile;
    //...............
    };
    // .cpp
    DWORD CALLBACK CAboutDlg::RichEditStreamOutCallback(DWORD dwCookie, 
    								  LPBYTE pbBuff, LONG cb, LONG FAR *pcb)
     
    {
    	CAboutDlg* pDlg = reinterpret_cast<CAboutDlg*>(dwCookie); 
     
    	if(pDlg->m_bNewFile)
    	{
    		pDlg->m_bNewFile=false;
    		pDlg->m_hFile = CreateFile(pDlg->m_strRtfFileName,
    			GENERIC_WRITE,FILE_SHARE_WRITE,NULL,OPEN_EXISTING,0,NULL);
    		if(pDlg->m_hFile == INVALID_HANDLE_VALUE)
    		{
    			pDlg->m_hFile = CreateFile(pDlg->m_strRtfFileName,
    				GENERIC_WRITE,FILE_SHARE_WRITE,NULL,CREATE_ALWAYS,0,NULL);
    		}
    	}
    	if(pDlg->m_hFile == INVALID_HANDLE_VALUE)	return 1;
     
       DWORD bytesWritten;
       WriteFile(pDlg->m_hFile,pbBuff,cb,&bytesWritten,NULL);
     
        *pcb = bytesWritten;
    	if(bytesWritten != (DWORD)cb || bytesWritten == 0)
    	{
    	   if(pDlg->m_hFile != INVALID_HANDLE_VALUE)
    	   {
    			CloseHandle(pDlg->m_hFile);
    			pDlg->m_bNewFile=true;	
    		}
    	}
       return 0;
    }
    // ----------------------------------------------------------------------------
    DWORD CALLBACK CAboutDlg::RichEditStreamInCallback(DWORD dwCookie, 
    								  LPBYTE pbBuff, LONG cb, LONG FAR *pcb)
    {
    	CAboutDlg* pDlg = reinterpret_cast<CAboutDlg*>(dwCookie); 
     
    	if(pDlg->m_bNewFile)
    	{
    		pDlg->m_bNewFile=false;
    		pDlg->m_hFile = CreateFile(pDlg->m_strRtfFileName,
    			GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_EXISTING,0,NULL);
    	}
    	if(pDlg->m_hFile == INVALID_HANDLE_VALUE)
    		return 1;
     
    	//read some data	
    	DWORD bytesRead;
    	int rt = ReadFile(pDlg->m_hFile,pbBuff,cb,&bytesRead,NULL);
    	if(rt == FALSE)
    		return 1;
     
    	*pcb = bytesRead;
    	if(bytesRead != (DWORD)cb || bytesRead == 0)
    	{
    		if(pDlg->m_hFile != INVALID_HANDLE_VALUE)
    		{
    			CloseHandle(pDlg->m_hFile);
    			pDlg->m_bNewFile=true;
    		}
    	}
    	return 0;
    }
    BOOL CAboutDlg::OnInitDialog() 
    {
    	CDialog::OnInitDialog();
     
    	m_strRtfFileName="c:\\initial.rtf";
    	m_bNewFile=true;
    	m_hFile=INVALID_HANDLE_VALUE;
     
    	// TODO: Add extra initialization here
    	CRichEditCtrl* pRichEditCtrl = new CRichEditCtrl;
    	pRichEditCtrl->Create(WS_CHILD|WS_BORDER|ES_MULTILINE,CRect(10,10,100,200),this,1);
    	EDITSTREAM es;
     
    	es.dwCookie =(DWORD_PTR )this;
        es.dwError = 0; 
        es.pfnCallback = (EDITSTREAMCALLBACK)RichEditStreamInCallback;
    	pRichEditCtrl->StreamIn(SF_RTF,es);
     
    	// traitement ici 
    	//
    	//
    	m_strRtfFileName="c:\\other.rtf";
    	es.dwCookie =(DWORD_PTR )this;
        es.dwError = 0; 
        es.pfnCallback = (EDITSTREAMCALLBACK)RichEditStreamOutCallback;
    	pRichEditCtrl->StreamOut(SF_RTF,es);
     
    	pRichEditCtrl->DestroyWindow();
    	delete pRichEditCtrl;
     
    	return TRUE;  // return TRUE unless you set the focus to a control
    	              // EXCEPTION: OCX Property Pages should return FALSE
    }

  7. #7
    Membre régulier
    Avatar de Alice9
    Profil pro
    Inscrit en
    Mai 2004
    Messages
    124
    Détails du profil
    Informations personnelles :
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations forums :
    Inscription : Mai 2004
    Messages : 124
    Points : 85
    Points
    85
    Par défaut encore une petite mise au point
    désolée ...

    encor une question : ton DWORD_PTR ce ne serait pas un #define DWORD_PTR DWORD ??




    Alice
    Alice

    A coeur vaillant, rien d'impossible !

  8. #8
    Rédacteur
    Avatar de farscape
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Novembre 2003
    Messages
    9 055
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Alpes Maritimes (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Novembre 2003
    Messages : 9 055
    Points : 17 323
    Points
    17 323
    Par défaut
    yes

  9. #9
    Membre régulier
    Avatar de Alice9
    Profil pro
    Inscrit en
    Mai 2004
    Messages
    124
    Détails du profil
    Informations personnelles :
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations forums :
    Inscription : Mai 2004
    Messages : 124
    Points : 85
    Points
    85
    Par défaut
    t un As !

    ça marche terrible. Youpi !!!

    Mais une fois que tout est finie, il faut absolumment fermer l'application pour pouvoir ouvrir le fichier amélioré.
    Il n'y aurait pas encore un lien sur ce fichier qu'il faudrait détruire avant de deleter le CRichEditCtrl ?

    Encore merci,

    Alice
    Alice

    A coeur vaillant, rien d'impossible !

  10. #10
    Membre régulier
    Avatar de Alice9
    Profil pro
    Inscrit en
    Mai 2004
    Messages
    124
    Détails du profil
    Informations personnelles :
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations forums :
    Inscription : Mai 2004
    Messages : 124
    Points : 85
    Points
    85
    Par défaut
    Encore deux trois choses que je ne comprends pas bien

    Comment placer la current location du IRichEditOle à la fin du fichier ?
    Pourquoi écrase t il le contenu du fichier lorsqu'il insère une image ?


    Alice
    Alice

    A coeur vaillant, rien d'impossible !

  11. #11
    Membre régulier
    Avatar de Alice9
    Profil pro
    Inscrit en
    Mai 2004
    Messages
    124
    Détails du profil
    Informations personnelles :
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations forums :
    Inscription : Mai 2004
    Messages : 124
    Points : 85
    Points
    85
    Par défaut résolution 1 question / 3
    En réponse à ma question :
    Mais une fois que tout est finie, il faut absolument fermer l'application pour pouvoir ouvrir le fichier amélioré. Il n'y aurait pas encore un lien sur ce fichier qu'il faudrait détruire avant de deleter le CRichEditCtrl ?
    il faut placer une mise au point d'un pointeur avant la fin du callback RichEditStreamOutCallback :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
     
    DWORD CALLBACK CAboutDlg::RichEditStreamOutCallback(DWORD dwCookie, 
                              LPBYTE pbBuff, LONG cb, LONG FAR *pcb) 
     
    { 
       CAboutDlg* pDlg = reinterpret_cast<CAboutDlg*>(dwCookie); 
     
       if(pDlg->m_bNewFile) 
       { 
          pDlg->m_bNewFile=false; 
          pDlg->m_hFile = CreateFile(pDlg->m_strRtfFileName, 
             GENERIC_WRITE,FILE_SHARE_WRITE,NULL,OPEN_EXISTING,0,NULL); 
          if(pDlg->m_hFile == INVALID_HANDLE_VALUE) 
          { 
             pDlg->m_hFile = CreateFile(pDlg->m_strRtfFileName, 
                GENERIC_WRITE,FILE_SHARE_WRITE,NULL,CREATE_ALWAYS,0,NULL); 
          } 
       } 
       if(pDlg->m_hFile == INVALID_HANDLE_VALUE)   return 1; 
     
       DWORD bytesWritten; 
       WriteFile(pDlg->m_hFile,pbBuff,cb,&bytesWritten,NULL); 
     
        *pcb = bytesWritten; 
       if(bytesWritten != (DWORD)cb || bytesWritten == 0) 
       { 
          if(pDlg->m_hFile != INVALID_HANDLE_VALUE) 
          { 
             CloseHandle(pDlg->m_hFile); 
             pDlg->m_bNewFile=true;    
          } 
       }
    pDlg->m_hFile = NULL;


    Alice
    Alice

    A coeur vaillant, rien d'impossible !

  12. #12
    Membre régulier
    Avatar de Alice9
    Profil pro
    Inscrit en
    Mai 2004
    Messages
    124
    Détails du profil
    Informations personnelles :
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations forums :
    Inscription : Mai 2004
    Messages : 124
    Points : 85
    Points
    85
    Par défaut re 1/3
    désolée pour la réponse précédente.
    ça ne marche pas
    Alice

    A coeur vaillant, rien d'impossible !

  13. #13
    Rédacteur
    Avatar de farscape
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Novembre 2003
    Messages
    9 055
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Alpes Maritimes (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Novembre 2003
    Messages : 9 055
    Points : 17 323
    Points
    17 323
    Par défaut
    re,
    me suis peut etre planté sur le test de fin dans le cas de l'ecriture (j'ai fais ça vite ),
    et donc il doit manqué le CloseHandle à la fin.
    a verifier en debug trace.


  14. #14
    Membre régulier
    Avatar de Alice9
    Profil pro
    Inscrit en
    Mai 2004
    Messages
    124
    Détails du profil
    Informations personnelles :
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations forums :
    Inscription : Mai 2004
    Messages : 124
    Points : 85
    Points
    85
    Par défaut solution pour mauvaise feremture du fichier modifié
    re Hi !

    En faîte il ne manquait pas de closeHandle.

    C'était simplement une des conditions pour y arriver qui était mauvaise :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    if(bytesWritten != (DWORD)cb || bytesWritten == 0)
    au lieu de
    [code]if(bytesWritten != (DWORD)cb || bytesWritten != 0) [/code

    Hé oui, quand on écrit le fichier, on test si on a bien écrit et non l'inverse !


    pour ce qui est de ma deuxième question, je pense avoir compris :
    Pourquoi écrase t il le contenu du fichier lorsqu'il insère une image ?
    -> il créé un nouveau fichier et donc écrase le reste. Solution je créé un fichier ou j'intègre une image puis je fais un assemnlage de plusieurs fichiers.
    Alice

    A coeur vaillant, rien d'impossible !

  15. #15
    Membre régulier
    Avatar de Alice9
    Profil pro
    Inscrit en
    Mai 2004
    Messages
    124
    Détails du profil
    Informations personnelles :
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations forums :
    Inscription : Mai 2004
    Messages : 124
    Points : 85
    Points
    85
    Par défaut encore et toujours ....
    re re hi

    encore mille excuses pour toutes ces questions .....

    Mais maintenant quand le fichier se ferme via CloseHandle, l'image mémorisée dans le rtf se sauvegarde en faisant n'importe quoi.

    Donc : soit je ferme et j'ai n'importe quoi,
    soit je ne ferme pas et quand je sors de l'application il ferme l'application correctement et l'image est bien.

    dans les deux cas y a comme un soucis....


    Alice
    Alice

    A coeur vaillant, rien d'impossible !

  16. #16
    Rédacteur
    Avatar de farscape
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Novembre 2003
    Messages
    9 055
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Alpes Maritimes (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Novembre 2003
    Messages : 9 055
    Points : 17 323
    Points
    17 323
    Par défaut
    parceque le test n'etait pas si mauvais j'ai pas eu le temps de tester ,mais la fonction callback est appelée plusieurs fois par le richedit pour lire/ecrire par block ...
    donc si tu fermes au premier coup tu as une portion de fichier...
    d'ou ma gestion du boolean pDlg->m_bNewFile
    pour detecter la premiere fois...

  17. #17
    Rédacteur
    Avatar de farscape
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Novembre 2003
    Messages
    9 055
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Alpes Maritimes (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Novembre 2003
    Messages : 9 055
    Points : 17 323
    Points
    17 323
    Par défaut
    re,
    correction sur la partie ecriture:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
     
    DWORD CALLBACK CAboutDlg::RichEditStreamOutCallback(DWORD dwCookie,
                              LPBYTE pbBuff, LONG cb, LONG FAR *pcb)
     
    {
       CAboutDlg* pDlg = reinterpret_cast<CAboutDlg*>(dwCookie);
     
       if(pDlg->m_bNewFile)
       {
          pDlg->m_bNewFile=false;
          pDlg->m_hFile = CreateFile(pDlg->m_strRtfFileName,            GENERIC_WRITE,FILE_SHARE_WRITE,NULL,CREATE_ALWAYS,0,NULL);      
       }
       if(pDlg->m_hFile == INVALID_HANDLE_VALUE)   return 1;
     
       DWORD bytesWritten;
       WriteFile(pDlg->m_hFile,pbBuff,cb,&bytesWritten,NULL);
     
        *pcb = bytesWritten;
     
       return 0;
    } 
    BOOL CAboutDlg::OnInitDialog()
    {
       CDialog::OnInitDialog();
     
       m_strRtfFileName="c:\\initial.rtf";
       m_bNewFile=true;
       m_hFile=INVALID_HANDLE_VALUE;
     
       // TODO: Add extra initialization here
       CRichEditCtrl* pRichEditCtrl = new CRichEditCtrl;
        pRichEditCtrl->Create(WS_CHILD|WS_BORDER|ES_MULTILINE,CRect(10,10,100,200),this,1);
       EDITSTREAM es;
     
       es.dwCookie =(DWORD_PTR )this;
        es.dwError = 0;
        es.pfnCallback = (EDITSTREAMCALLBACK)RichEditStreamInCallback;
       pRichEditCtrl->StreamIn(SF_RTF,es);
     
       // traitement ici
       //
       //
       m_bNewFile=true;
       m_strRtfFileName="c:\\other.rtf";
       es.dwCookie =(DWORD_PTR )this;
       es.dwError = 0;
       es.pfnCallback = (EDITSTREAMCALLBACK)RichEditStreamOutCallback;
       pRichEditCtrl->StreamOut(SF_RTF,es);
       if(m_hFile != INVALID_HANDLE_VALUE)
       {
         CloseHandle(m_hFile);
         m_bNewFile=true;   
       }
       pRichEditCtrl->DestroyWindow();
       delete pRichEditCtrl;
     
       return TRUE;  // return TRUE unless you set the focus to a control
                     // EXCEPTION: OCX Property Pages should return FALSE
    }

  18. #18
    Membre régulier
    Avatar de Alice9
    Profil pro
    Inscrit en
    Mai 2004
    Messages
    124
    Détails du profil
    Informations personnelles :
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations forums :
    Inscription : Mai 2004
    Messages : 124
    Points : 85
    Points
    85
    Par défaut Bmp in rtf
    :trouve: Enfin ça marche.

    Pour que tout fonctionne correctement, j'ai placé la fermeture du fichier non pas dans le RichEditStreamOutCallback mais dans le InsertBmp, juste après avoir terminé le Stream Out et avant la destruction du RichEditCtrl.
    Là, le fichier contenant l'image s'enregistre correctement.

    Pour me mettre dans ce cas là, j'ai essayé de me remettre dans le cas ou c'est l'application qui ferme mon fichier et non le streamOut.
    J'en suis arrivé à la conclusion qu'il fallait appliquer le closeHandle à cet endroit et ne pas remettre le flag de nouveau fichier à true (pour éviter qu'il le vide).

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
     
    DWORD CALLBACK CG2mFanCowlDlg::RichEditStreamOutCallback(DWORD dwCookie, 
                              LPBYTE pbBuff, LONG cb, LONG FAR *pcb) 
     
    { 
       CG2mFanCowlDlg* pDlg = reinterpret_cast<CG2mFanCowlDlg*>(dwCookie); 
     
       if(pDlg->m_bNewFile) 
       { 
          pDlg->m_bNewFile=false; 
          pDlg->m_hFile = CreateFile(pDlg->m_strRtfFileName, 
             GENERIC_WRITE,FILE_SHARE_WRITE,NULL,OPEN_EXISTING,0,NULL); 
          if(pDlg->m_hFile == INVALID_HANDLE_VALUE) 
          { 
             pDlg->m_hFile = CreateFile(pDlg->m_strRtfFileName, 
                GENERIC_WRITE,FILE_SHARE_WRITE,NULL,CREATE_ALWAYS,0,NULL); 
          } 
       } 
       if(pDlg->m_hFile == INVALID_HANDLE_VALUE)   return 1; 
     
       DWORD bytesWritten; 
     
       int rt = WriteFile(pDlg->m_hFile,pbBuff,cb,&bytesWritten,NULL); 
       if (rt == 0)
    	   return -1;
     
        *pcb = bytesWritten; 
     
    	if (bytesWritten != (DWORD)cb || bytesWritten == 0)
    		return -1;
     
       return 0; 
    } 
    void CG2mFanCowlDlg::InsertBmp(char * path,char *pathBmp)
    {
    	HBITMAP hBitmap = (HBITMAP) LoadImage( NULL, 
    											pathBmp, 
    											IMAGE_BITMAP, 
    											0,0, 
    											LR_LOADFROMFILE ); 
    	m_strRtfFileName=path; 
    	m_bNewFile=true; 
    	m_hFile=INVALID_HANDLE_VALUE; 
     
    	CRichEditCtrl* pRichEditCtrl = new CRichEditCtrl; 
    	pRichEditCtrl->Create(WS_CHILD|WS_BORDER|ES_MULTILINE,CRect(10,10,100,200),this,1); 
    	EDITSTREAM es; 
    	es.dwCookie =(DWORD_PTR )this; 
        es.dwError = 0; 
        es.pfnCallback = (EDITSTREAMCALLBACK)RichEditStreamInCallback; 
    	pRichEditCtrl->StreamIn(SF_RTF,es); 
     
       // traitement ici 
    	if (hBitmap)
    		CImageDataObject::InsertBitmap(pRichEditCtrl->GetIRichEditOle(),hBitmap) ;
     
    	m_strRtfFileName=path; // enregistrement du fichier modifié
    	es.dwCookie =(DWORD_PTR )this; 
        es.dwError = 0; 
        es.pfnCallback = (EDITSTREAMCALLBACK)RichEditStreamOutCallback; 
    	pRichEditCtrl->StreamOut(SF_RTF,es);
     
    	if(m_hFile != INVALID_HANDLE_VALUE) 
    		CloseHandle(m_hFile) ;
     
    	pRichEditCtrl->DestroyWindow();
    	delete pRichEditCtrl; 
    	DeleteObject(hBitmap);
     
    }
    voilà c tout et c fini.
    "Farscape"

    Alice
    Alice

    A coeur vaillant, rien d'impossible !

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Mettre une image bmp dans un message box
    Par aadelfa dans le forum C++Builder
    Réponses: 7
    Dernier message: 06/02/2007, 14h45
  2. Inserer une image.jpg dans table
    Par loumanga dans le forum PostgreSQL
    Réponses: 7
    Dernier message: 30/01/2006, 14h14
  3. Insertion d'une image BMP dans un fichier RTF
    Par didinel dans le forum MFC
    Réponses: 8
    Dernier message: 18/08/2005, 09h24
  4. [TP] Insérer une image BMP
    Par maind5or dans le forum Turbo Pascal
    Réponses: 3
    Dernier message: 14/08/2005, 22h08
  5. [CR] Inserer une image à partir d'un fichier
    Par Gandalf24 dans le forum SAP Crystal Reports
    Réponses: 7
    Dernier message: 23/07/2003, 10h55

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo