RichEdit

Résolu
ncoder Messages postés 244 Date d'inscription vendredi 6 mai 2005 Statut Membre Dernière intervention 6 avril 2008 - 23 mars 2006 à 18:35
ncoder Messages postés 244 Date d'inscription vendredi 6 mai 2005 Statut Membre Dernière intervention 6 avril 2008 - 27 mars 2006 à 09:31
Bonjour à tous,

Dans un de mes programmes, j'ai un RichEdit.
J'y ajoute du texte auquel je mets la couleur que je veux.
Le seul problème est que dès que je change la police de caractère de ce RichEdit, les couleurs ne s'affichent plus !!!

Voici le code :

// chargement du contrôle richedit
HINSTANCE Dll = LoadLibrary("RICHED32.DLL");

Log = CreateWindowEx(WS_EX_OVERLAPPEDWINDOW, RICHEDIT_CLASS, "", WS_CHILD|ES_READONLY|ES_WANTRETURN|
WS_VISIBLE|ES_MULTILINE|WS_VSCROLL|ES_AUTOVSCROLL|ES_WANTRETURN,
15, 255, 465, 200, hwnd, (HMENU)10, hThisInstance, NULL);

SendMessage(Log, WM_SETFONT, (WPARAM) Police, MAKELPARAM(TRUE, 0)); ==> sans cette ligne, les couleurs s'affichent sans pb.

Merci de votre aide

8 réponses

cs_Sparow Messages postés 5 Date d'inscription vendredi 3 novembre 2000 Statut Membre Dernière intervention 30 mars 2006
24 mars 2006 à 23:00
Oui, Max12 a raison, il ne faut pas utiliser WM_SETFONT mais envoyer le fond (avec la couleur) depuis une sructure CHARFORMAT2...

CHARFORMAT2 Format;

memset(&Format, 0, sizeof(CHARFORMAT2));
Format.cbSize = sizeof(CHARFORMAT2);
Format.dwMask = CFM_BOLD | CFM_COLOR | CFM_FACE | CFM_ITALIC | CFM_SIZE |CFM_UNDERLINE;
Format.dwEffects = 0; // style (gras/italique/souligné
// CFM_BOLD/CFM_ITALIC/CMF_UNDERLINE
Format.crTextColor RGB(255, 0, 0); // la couleur du texte : 255, 0, 0> rouge
Format.yHeight = 180; // la hauteur du texte
Format.yOffset = 0;
Format.bCharSet = ANSI_CHARSET;
Format.bPitchAndFamily = DEFAULT_PITCH;
strcpy(Format.szFaceName, "Arial"); // où "Arial" est la police à utiliser
SendMessage(hwnd/*HWND du richedit*/, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM) &Format); // Envoie la police (Format) au richedit
3
cs_Sparow Messages postés 5 Date d'inscription vendredi 3 novembre 2000 Statut Membre Dernière intervention 30 mars 2006
26 mars 2006 à 18:56
Crée un CHARFORMAT2 comme expliqué dans mon dernier message et envoie le a cette fonction :


bool add_text(const HWND &hwnd/*Le HWND de ton RichEdit*/, string new_txt/*le texte à ajouter*/, CHARFORMAT2 Format/le CHARFORMAT2 créé plus haut^^*/)
{
#ifdef WIN32
SendMessage(hwnd, EM_SETSEL, (WPARAM)length, (LPARAM)length); // crée un point d'insertion

#else
SendMessage(hwnd, EM_SETSEL, 0, MAKELONG(length, length));

#endif

SendMessage(hwnd, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM) &Format);
SendMessage(hwnd, EM_REPLACESEL, 0, (LPARAM)(LPCTSTR)new_txt.c_str());
//SendMessage(hwnd, WM_VSCROLL, SB_BOTTOM, 0); // fait descendre automatiquement le scroll de ta RicheEdit
return 0;
}
3
cs_max12 Messages postés 1491 Date d'inscription dimanche 19 novembre 2000 Statut Modérateur Dernière intervention 7 juillet 2014
23 mars 2006 à 18:48
Je ne suis pas sûr, mais je crois que faire SETFONT c'est mal sur un RichEdit car il va faire comme si c'était un éditbox et effacer toutes mises en formes. Il faut utiliser un autre message (mais je ne le connais pas) regarde dans le CHARFORMAT2 te servant à mettre la couleur.

A+

http://vbaddons.free.fr
MSN : x_men_40(
0
ncoder Messages postés 244 Date d'inscription vendredi 6 mai 2005 Statut Membre Dernière intervention 6 avril 2008 1
25 mars 2006 à 19:10
Merci à vous deux je vais essayer le code !

A+
0

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

Posez votre question
ncoder Messages postés 244 Date d'inscription vendredi 6 mai 2005 Statut Membre Dernière intervention 6 avril 2008 1
26 mars 2006 à 18:06
Non ça marche pas !!

Que puis-je faire svp ?

Merci
0
cs_Sparow Messages postés 5 Date d'inscription vendredi 3 novembre 2000 Statut Membre Dernière intervention 30 mars 2006
27 mars 2006 à 02:40
Il faut aussi que tu utilises "InitCommonControls()" avt de charger "RICHED32.DLL":


InitCommonControls()

(aucun argument)

défini dans "commctrl.h"


Ca marche, j'ai tapé cette fonction (add_text() ^^) pour ajouter du texte dans un richedit multicolore d'un de mes programmes (chat)
Après, si ça va tjrs pas, balance du code :d

A+
0
ncoder Messages postés 244 Date d'inscription vendredi 6 mai 2005 Statut Membre Dernière intervention 6 avril 2008 1
27 mars 2006 à 09:26
Merci je regarde tout ça
0
ncoder Messages postés 244 Date d'inscription vendredi 6 mai 2005 Statut Membre Dernière intervention 6 avril 2008 1
27 mars 2006 à 09:31
J'ai traduit ta fonction en C, pas de problèmes, tout marche !

Merci beaucoup de ton aide !

A+
0
Rejoignez-nous