Réponse acceptée !
Salut, merci pour de ton aide mais j ai trouver une solution un peut bourrin mais qui marche !!! .
Passe une bonne journée et surtout un bon week end !!!!
joh
Code:
.....
CString sBuffer;
int iformat ;
long iDeb = 0, iFin = 1, iFinN = 0, iNbCara = 0;
bool RetourChariot ;
iNbCara = m_ctrlREdit.GetTextLength( );
for( iDeb=0 ; iDeb<iNbCara ; iDeb++ )
{
m_ctrlREdit.SetSel(iDeb,iFin);
m_ctrlREdit.GetSelText((LPSTR) sBuffer.GetBuffer((iFin-iDeb)+1));
sBuffer.ReleaseBuffer ();
// Fonction testant le format de mes caractères
Gras();
Italique();
Souligner();
PoliceduText();
TailleduText();
// Teste si c'est un retour chariot.
if(sBuffer == "")
{
iFinN = iFin + 1 ;
m_ctrlREdit.SetSel(iDeb,iFinN);
m_ctrlREdit.GetSelText((LPSTR) sBuffer.GetBuffer((iFinN-iDeb)+1));
sBuffer.ReleaseBuffer ();
if(sBuffer.GetAt (0) == 13)
{
iFin++ ;
iDeb++ ;
RetourChariot = true ;
}
}
else
{
RetourChariot = false ;
// if(sBuffer == " ")
// MessageBox("C'est un espace","Caractère",MB_OK);
// else
if(sBuffer != " ")
{
if(iGras == 1 && iItalique == 1 && iSouligner == 1)
iformat = 0 ;
else
{
if(iGras == 1 && iItalique == 1)
iformat = 1 ;
else
{
if(iSouligner == 1 && iItalique == 1)
iformat = 2;
else
{
if(iSouligner == 1 && iGras == 1)
iformat = 3 ;
else
{
if(iGras == 1)
iformat = 4 ;
else if(iSouligner == 1)
iformat = 5 ;
else if(iItalique == 1)
iformat = 6 ;
else
iformat = 7 ;
}
}
}
}
}
}
LOGFONT lf ;
memset ( &lf, 0, sizeof(LOGFONT) ) ;
lf.lfHeight = lTaille ;
sprintf( lf.lfFaceName, "%s", sPolice.GetBuffer(0) ) ;
switch(iformat)
{
case 0: // Gras - Italique - Souligner.
lf.lfWeight = FW_BOLD ;
lf.lfItalic = true ;
lf.lfUnderline = true ;
break;
case 1: // Gras - Italique.
lf.lfWeight = FW_BOLD ;
lf.lfItalic = true ;
lf.lfUnderline = false ;
break;
case 2: // Italique - Souligner.
lf.lfWeight = FW_NORMAL ;
lf.lfItalic = true ;
lf.lfUnderline = true ;
break;
case 3: // Gras - Souligner.
lf.lfWeight = FW_BOLD ;
lf.lfItalic = false ;
lf.lfUnderline = true ;
break;
case 4: // Gras.
lf.lfWeight = FW_BOLD ;
lf.lfItalic = false ;
lf.lfUnderline = false ;
break;
case 5: // Souligner.
lf.lfWeight = FW_NORMAL ;
lf.lfItalic = false ;
lf.lfUnderline = true ;
break;
case 6: // Italique.
lf.lfWeight = FW_NORMAL ;
lf.lfItalic = true ;
lf.lfUnderline = false ;
break;
case 7: // Normal.
lf.lfWeight = FW_NORMAL ;
lf.lfItalic = false ;
lf.lfUnderline = false ;
break;
default :
break ;
}
dc.SelectObject(&pOldFont);
fonte.DeleteObject();
fonte.CreateFontIndirect(&lf);
pOldFont = dc.SelectObject(&fonte);
if( (iDeb >= 1) && (RetourChariot == false) )
{
r2.left = r2.left + lTaille + 1;
dc.DrawText(sBuffer, sBuffer.GetLength(), r2, DT_LEFT|DT_WORDBREAK);
}else if(ReChar == true)
{
r2.left = 0 ;
r2.top = r2.top + lTaille + 1 ;
dc.DrawText(sBuffer, sBuffer.GetLength(), r2, DT_LEFT|DT_WORDBREAK);
}else
dc.DrawText(sBuffer, sBuffer.GetLength(), r2, DT_LEFT|DT_WORDBREAK);
}
iFin ++ ;
}
////////////////////////////////////////////
// Test si le mot selectionné est en Gras .
void CMailing::Gras()
{
CHARFORMAT2 cfa ;
m_ctrlREdit.GetSelectionCharFormat(cfa);
int iFormat = cfa.dwEffects ;
if((iFormat == GRAS)||(iFormat == G_S)||(iFormat == G_I)||(iFormat == G_I_S))
iGras = 1;
else
iGras = 0;
}
////////////////////////////////////////////////
// Test si le mot selectionné est en Italique .
void CMailing::Italique()
{
CHARFORMAT2 cfa ;
m_ctrlREdit.GetSelectionCharFormat(cfa);
int iFormat = cfa.dwEffects ;
if((iFormat == ITA)||(iFormat == S_I)||(iFormat == G_I)||(iFormat == G_I_S))
iItalique = 1;
else
iItalique = 0;
}
//////////////////////////////////////////////
// Test si le mot selectionné est Souligner .
void CMailing::Souligner()
{
CHARFORMAT2 cfa ;
m_ctrlREdit.GetSelectionCharFormat(cfa);
int iFormat = cfa.dwEffects ;
if((iFormat == SOUL)||(iFormat == G_S)||(iFormat == S_I)||(iFormat == G_I_S))
iSouligner = 1;
else
iSouligner = 0;
}
//////////////////////////////////
// Récupérer la taille du Texte .
void CMailing::TailleduText()
{
CHARFORMAT2 cfa ;
m_ctrlREdit.GetSelectionCharFormat(cfa);
lTaille = cfa.yHeight;
}
/////////////////////////
// Récupérer la Police .
void CMailing::PoliceduText()
{
CHARFORMAT2 cfa ;
m_ctrlREdit.GetSelectionCharFormat(cfa);
sPolice = cfa.szFaceName ;
}