bonjour à tous;
je programme sous visual C++ et la vue de mon projet herite de CrichEditView.
j'ai envi d'afficher un texte dans la vue et qu'en fonction d'un booleen dans la classe CDoc une partie du texte dans ma vue change de couleur.
quand j'essaye dans la methode Oninitialupdate, ça marche niklel au lancement du programme, le code est le suivant:
le probleme avec cette methode est que ça se produit qu'une seule fois, au lancement du programme. alors j'ai essayé de mettre ce code dans le OnDraw()
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 void CRichView::OnInitialUpdate() { CRichEditView::OnInitialUpdate(); CRichEditCtrl& theCtrl=GetRichEditCtrl(); CString str="kamano" ; ; theCtrl.SetWindowText(str); theCtrl.SetSel(0,4);//select hello as the word to be formatted with different color CHARFORMAT cf; cf.cbSize = sizeof(CHARFORMAT); cf.dwMask = CFM_COLOR ; cf.crTextColor = RGB(255,0,0); //cf.bCharSet="hmfcjhcccccgh" ; cf.dwEffects = 0;//we do not want CFE_AUTOCOLOR , since this will choose GetSysColor value. theCtrl.SetWordCharFormat(cf); theCtrl.SetSel(0,0);//now, deselect text // Définir les marges d'impression (720 twips = 1/2 pouce) SetMargins(CRect(720, 720, 720, 720)); }
mais ce code ne marche pas !
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 void Cessai2View::OnPaint() { CPaintDC dc(this); // device context for painting // TODO : ajoutez ici le code de votre gestionnaire de messages // N'appelez pas CRichEditView::OnPaint() pour la peinture des messages Cessai2Doc* pDoc = GetDocument(); ASSERT_VALID(pDoc); if (!pDoc) return; CString str="jetestemonprogramme "; dc.TextOut(0,0,str) ; if(pDoc->m_ouvertdoc1==true) { CRichEditCtrl& theCtrl=GetRichEditCtrl(); GetWindowText(str) ; theCtrl.SetSel(0,4);//select hello as the word to be formatted with different color CHARFORMAT cf; cf.cbSize = sizeof(CHARFORMAT); cf.dwMask = CFM_COLOR ; cf.crTextColor = RGB(255,0,0); //cf.bCharSet="hmfcjhcccccgh" ; cf.dwEffects = 0;//we do not want CFE_AUTOCOLOR , since this will choose GetSysColor value. theCtrl.SetWordCharFormat(cf); theCtrl.SetSel(0,0);//now, deselect text // Définir les marges d'impression (720 twips = 1/2 pouce) SetMargins(CRect(720, 720, 720, 720)); } }
quelqu'un pourrait m'aider ? merci
Partager