Couleurs en C

sebast105 Messages postés 37 Date d'inscription mercredi 28 janvier 2004 Statut Membre Dernière intervention 18 avril 2005 - 9 avril 2005 à 14:46
julienbj Messages postés 452 Date d'inscription jeudi 4 décembre 2003 Statut Membre Dernière intervention 19 décembre 2008 - 17 avril 2005 à 14:44
Bonjour,



Je voudrais savoir quelle librairie existe afin de mettre du texte de différentes couleur en C.



Merci d'avance.



Cordialement Sébastien.

11 réponses

yoyo269 Messages postés 1403 Date d'inscription lundi 23 février 2004 Statut Membre Dernière intervention 11 janvier 2009 2
9 avril 2005 à 15:11
Précise en quel mode tu programmes, si c'est du mode console ou bien du mode Win32 par exemple.

YOYO, @+.
YOYO
0
sebast105 Messages postés 37 Date d'inscription mercredi 28 janvier 2004 Statut Membre Dernière intervention 18 avril 2005
9 avril 2005 à 15:36
Désolé, c en mode console

Sébastien
0
yoyo269 Messages postés 1403 Date d'inscription lundi 23 février 2004 Statut Membre Dernière intervention 11 janvier 2009 2
9 avril 2005 à 18:03
Dans ce cas je peux pas t'aider, désolé.
Bon courage.

YOYO, @+.
YOYO
0
Gendal67 Messages postés 627 Date d'inscription mercredi 16 juin 2004 Statut Membre Dernière intervention 24 juillet 2011 2
9 avril 2005 à 21:24
yoyo269> Pk si cela avait été du Win32, tu connaissais une lib ? moi perso, çà part changer la couleur du texte dans une dialog en traitant le message WM_COLORSTATIC etc je ne vois pas comment faire d'autre ;)

Gendal67, Dev-C++ 4.9.9.1, J'adore cppfrance!! :-))
0

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

Posez votre question
yoyo269 Messages postés 1403 Date d'inscription lundi 23 février 2004 Statut Membre Dernière intervention 11 janvier 2009 2
9 avril 2005 à 21:46
Ben oui justement ça urait été un truc dans le genre en Win32.
Ou alors la couleur dans un RichEdit.

YOYO, @+.
YOYO
0
Gendal67 Messages postés 627 Date d'inscription mercredi 16 juin 2004 Statut Membre Dernière intervention 24 juillet 2011 2
9 avril 2005 à 22:28
Ou alors la couleur dans un RichEdit. <<<< ouhla steuplé dis moi comment tu fais!!!! :)))

Gendal67, Dev-C++ 4.9.9.1, J'adore cppfrance!! :-))
0
yoyo269 Messages postés 1403 Date d'inscription lundi 23 février 2004 Statut Membre Dernière intervention 11 janvier 2009 2
9 avril 2005 à 22:43
Voilà une fonction que j'ai faite se servant notamment de la couleur.
Si tu as besoin de précisions, je suis là.
/*Ajoute du texte à une RichEdit avec une police définie*/
void AjouteTexte(HWND Handle, char * Texte, char * Pseudo, char * Police, COLORREF Couleur, int Style, char * Type)
{
CHARFORMAT2 Format;
CHARRANGE Selection;
static char Chaine[TAILLEBUFFER + ZERO_FIN];
if (!strcmp(Type, "Texte"))
{
ZeroMemory(&Format, sizeof(CHARFORMAT2));
Format.cbSize = sizeof(CHARFORMAT2);
Format.dwMask = CFM_BOLD | CFM_COLOR | CFM_FACE | CFM_ITALIC | CFM_SIZE | CFM_UNDERLINE;
Format.dwEffects = 0;
Format.yHeight = 170;
Format.yOffset = 0;
Format.crTextColor = RGB(0, 0, 0);
Format.bCharSet = ANSI_CHARSET;
Format.bPitchAndFamily = DEFAULT_PITCH;
sprintf(Format.szFaceName, "%s", "MS Sans Serif");
Selection.cpMin = strlen(PrendreTexte(Handle));
Selection.cpMax = strlen(PrendreTexte(Handle));
sprintf(Chaine, "%s%s", Pseudo, " dit :\r\n ");
SendMessage(Handle, EM_EXSETSEL, 0, (LPARAM) &Selection);
SendMessage(Handle, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM) &Format);
SendMessage(Handle, EM_REPLACESEL, 0, (LPARAM)(LPCTSTR) Chaine);
ZeroMemory(&Format, sizeof(CHARFORMAT2));
Format.cbSize = sizeof(CHARFORMAT2);
Format.dwMask = CFM_BOLD | CFM_COLOR | CFM_FACE | CFM_ITALIC | CFM_SIZE | CFM_UNDERLINE;
Format.dwEffects = Style;
Format.yHeight = 170;
Format.yOffset = 0;
Format.crTextColor = Couleur;
Format.bCharSet = ANSI_CHARSET;
Format.bPitchAndFamily = DEFAULT_PITCH;
sprintf(Format.szFaceName, "%s", Police);
Selection.cpMin = strlen(PrendreTexte(Handle));
Selection.cpMax = strlen(PrendreTexte(Handle));
sprintf(Chaine, "%s%s", Texte, "\r\n");
SendMessage(Handle, EM_EXSETSEL, 0, (LPARAM) &Selection);
SendMessage(Handle, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM) &Format);
SendMessage(Handle, EM_REPLACESEL, 0, (LPARAM)(LPCTSTR) Chaine);
SendMessage(Handle, WM_VSCROLL, SB_BOTTOM, 0);
}
if (!strcmp(Type, "Message"))
{
ZeroMemory(&Format, sizeof(CHARFORMAT2));
Format.cbSize = sizeof(CHARFORMAT2);
Format.dwMask = CFM_BOLD | CFM_COLOR | CFM_FACE | CFM_ITALIC | CFM_SIZE | CFM_UNDERLINE;
Format.dwEffects = Style;
Format.yHeight = 170;
Format.yOffset = 0;
Format.crTextColor = Couleur;
Format.bCharSet = ANSI_CHARSET;
Format.bPitchAndFamily = DEFAULT_PITCH;
sprintf(Format.szFaceName, "%s", "MS Sans Serif");
Selection.cpMin = strlen(PrendreTexte(Handle));
Selection.cpMax = strlen(PrendreTexte(Handle));
sprintf(Chaine, "%s%s%s", ">>> ", Texte, " <<<\r\n");
SendMessage(Handle, EM_EXSETSEL, 0, (LPARAM) &Selection);
SendMessage(Handle, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM) &Format);
SendMessage(Handle, EM_REPLACESEL, 0, (LPARAM)(LPCTSTR) Chaine);
SendMessage(Handle, WM_VSCROLL, SB_BOTTOM, 0);
}
if (!strcmp(Type, "Envoi"))
{
ZeroMemory(&Format, sizeof(CHARFORMAT2));
Format.cbSize = sizeof(CHARFORMAT2);
Format.dwMask = CFM_BOLD | CFM_COLOR | CFM_FACE | CFM_ITALIC | CFM_SIZE | CFM_UNDERLINE;
Format.dwEffects = Style;
Format.yHeight = 170;
Format.yOffset = 0;
Format.crTextColor = Couleur;
Format.bCharSet = ANSI_CHARSET;
Format.bPitchAndFamily = DEFAULT_PITCH;
sprintf(Format.szFaceName, "%s", Police);
SendMessage(Handle, EM_SETCHARFORMAT, SCF_ALL, (LPARAM) &Format);
}
if (!strcmp(Type,"Ajout"))
{
ZeroMemory(&Format, sizeof(CHARFORMAT2));
Format.cbSize = sizeof(CHARFORMAT2);
Format.dwMask = CFM_BOLD | CFM_COLOR | CFM_FACE | CFM_ITALIC | CFM_SIZE | CFM_UNDERLINE;
Format.dwEffects = Style;
Format.yHeight = 170;
Format.yOffset = 0;
Format.crTextColor = Couleur;
Format.bCharSet = ANSI_CHARSET;
Format.bPitchAndFamily = DEFAULT_PITCH;
sprintf(Format.szFaceName, "%s", Police);
Selection.cpMin = strlen(PrendreTexte(Handle));
Selection.cpMax = strlen(PrendreTexte(Handle));
SendMessage(Handle, EM_EXSETSEL, 0, (LPARAM) &Selection);
SendMessage(Handle, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM) &Format);
SendMessage(Handle, EM_REPLACESEL, 0, (LPARAM)(LPCTSTR) Texte);
SendMessage(Handle, WM_VSCROLL, SB_BOTTOM, 0);
}
}

YOYO, @+.
YOYO
0
sebast105 Messages postés 37 Date d'inscription mercredi 28 janvier 2004 Statut Membre Dernière intervention 18 avril 2005
10 avril 2005 à 11:31
Merci pour ta réponse, mais il n'y a pas plus simple pour mettre un texte en couleur depuis un programme en mode console en C ?

SEB
0
yoyo269 Messages postés 1403 Date d'inscription lundi 23 février 2004 Statut Membre Dernière intervention 11 janvier 2009 2
10 avril 2005 à 11:34
Désolé seb mais ma réponse était pour Gendal67.
Donc pour du Win32.
Je suppose que tu as déjà cherché des codes sur le site ?

YOYO, @+.
YOYO
0
julienbj Messages postés 452 Date d'inscription jeudi 4 décembre 2003 Statut Membre Dernière intervention 19 décembre 2008 15
17 avril 2005 à 14:40
void ecrireCar(int couleur, char caractere)

{

HANDLE HCmd = GetStdHandle(STD_OUTPUT_HANDLE);



GetConsoleScreenBufferInfo(HCmd, &csbiInfo); //sauvegarde attributs du cmd

SetConsoleTextAttribute(HCmd, (short) (couleur | FOREGROUND_INTENSITY));

printf("%c", caractere);

SetConsoleTextAttribute(HCmd, csbiInfo.wAttributes); // restauration attributs du cmd

}

Vive le C
Tchao
[mailto:julienbj@hotmail.com Savon]
0
julienbj Messages postés 452 Date d'inscription jeudi 4 décembre 2003 Statut Membre Dernière intervention 19 décembre 2008 15
17 avril 2005 à 14:44
Oublier de préciser!

Pour les différentes couleurs possiblesvoir dans MSDN SetConsoleTextAttribute!

Vive le C
Tchao
[mailto:julienbj@hotmail.com Savon]
0
Rejoignez-nous