CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 12 of 12
  1. #1
    Join Date
    Aug 2011
    Posts
    69

    RichEdit Control not show text

    Hi,

    I'm triying to show a CString in RichEditControl with SetWindowsText, but when the dialog appear only show the container in white, but not show the text. What happen?

    This is the code of my function:

    Code:
    void CDlgDescriptivos::DescUnivariantesMostrar(void)
    {
    	CString aux;
    	CString cadena;
    	CTime fecha;
    	CString dato;
    	double *d;
    	int t,k=0,i;
    	CDatos* p = (CDatos*)Variables.GetAt (0);
    	
    	t = p->Tam ;
    	
    	
    	int Tam,tsin;
    	Tam = p->Tam;
    	tsin = p->Tam;
    	double total_acum=0;
    	int cont=0,cont2=0;
    
    	informe.Nombre = _T("DescUniv") + p->Nombre ;
    	informe.Descripcion = _T("Análisis Descriptivo Univariante de la variable ") + p->Nombre;
    	informe.nPerdidos = p->Tam -t ;
    	informe.nTamano = 22;
    	informe.VarsImplicadas = p->Nombre ;
    	fecha = CTime::GetCurrentTime ();
    	dato = fecha.Format ("%d/%m/%y");
    	informe.Fecha = dato;
    	dato = fecha.Format ("%H:%M");
    	informe.Hora = dato;
    	informe.Tipo = 900;
    	informe.Tam = 22;
    	informe.Datos = new CString [22];
    
    	if(p->Tipo==0 && p->Escala==0 )
    	{
    		d = QuitarAusentes (p->Datos , t, p->Ausente );
    	
    	
    		cadena.Format( _T("\n\n \t\tMEDIDAS DE POSICIÓN\n\n"));
    		informe.Datos [0] = cadena;
    		if (Moda (d, t)!= d[0])
    		{
    			cadena.Format(_T("\n\tModa no única: Min es %f"),d[0]);
    	
    			informe.Datos [1] = cadena;
    		}
    		else
    		{
    			cadena.Format(_T("\n\tModa:\t\t%f"),PRESICION, Moda (d, t));
    	
    			informe.Datos [1] = cadena;
    		}
    		cadena.Format (_T("\n\tMediana:\t\t%.*f"), PRESICION, Mediana (d, t));
    		informe.Datos [2] = cadena;
    		cadena.Format (_T("\n\tMedia:\t\t%.*f"), PRESICION, Media (d, t));
    		informe.Datos [3] = cadena;
    		cadena.Format (_T("\n\tMínimo:\t\t%.*f"), PRESICION, Minimo (d, t));
    		informe.Datos [4] = cadena;
    		cadena.Format (_T("\n\tMáximo:\t\t%.*f"), PRESICION, Maximo (d, t));
    		informe.Datos [5] = cadena;
    		cadena.Format (_T("\n\tCuartil1:\t\t%.*f"), PRESICION, Cuartil1(d, t));
    		informe.Datos [6] = cadena;
    		cadena.Format (_T("\n\tCuartil2:\t\t%.*f"), PRESICION, Cuartil2 (d, t));
    		informe.Datos [7] = cadena;
    		cadena.Format (_T("\n\tCuartil3:\t\t%.*f\n"), PRESICION, Cuartil3(d, t));
    		informe.Datos [8] = cadena;
    		cadena.Format( _T("\n\t\tMEDIDAS DE DISPERSIÓN\n\n"));
    		informe.Datos [9] = cadena;
    		cadena.Format (_T("\n\tRango:\t\t\t%.*f"), PRESICION, Rango (d, t));
    		informe.Datos [10] = cadena;
    		cadena.Format (_T("\n\tRango Intercuartílico:\t%.*f"), PRESICION, RInter (d, t));
    		informe.Datos [11] = cadena;
    		cadena.Format (_T("\n\tSemi Rango Intercuartílico:\t%.*f"), PRESICION, SRInter (d, t));
    		informe.Datos [12] = cadena;
    		cadena.Format (_T("\n\tVarianza:\t\t\t%.*f"), PRESICION, Varianza (d, t));
    		informe.Datos [13] = cadena;
    		cadena.Format (_T("\n\tCuasi Varianza:\t\t%.*f"), PRESICION, CVarianza (d, t));
    		informe.Datos [14] = cadena;
    		cadena.Format (_T("\n\tDesviación Típica:\t\t%.*f"), PRESICION, DesvTip (d, t));
    		informe.Datos [15] = cadena;
    		cadena.Format (_T("\n\tCuasi Desviación Típica:\t%.*f"), PRESICION, CDesvTip (d, t));
    		informe.Datos [16] = cadena;
    		cadena.Format (_T("\n\tCoeficiente de Variación:\t%.*f"), PRESICION, CoefVar (d, t));
    		informe.Datos [17] = cadena;
    		cadena.Format (_T("\n\tError Estándar:\t\t%.*f\n"), PRESICION, ErrorStandar (d, t));
    		informe.Datos [18] = cadena;
    		cadena.Format(_T("\n\t\tMEDIDAS DE ASIMETRÍA Y DEFORMACIÓN\n\n"));
    		informe.Datos [19] = cadena;
    		cadena.Format (_T("\n\tCoeficiente de Asimetría:\t%.*f"), PRESICION, CoefAsim (d, t));
    		informe.Datos [20] = cadena;
    		cadena.Format (_T("\n\tCoeficiente de Kurtosis:\t%.*f"), PRESICION, Kurtosis (d, t));
    		informe.Datos [21] = cadena;
    		
    	}
    	
    	
    	if(p->Tipo==0 && p->Escala==1 )
    	{
    	
    		d = QuitarAusentes (p->Datos , t, p->Ausente );
    	
    		cadena.Format(_T( "\n\n \t\tMEDIDAS DE POSICIÓN\n\n"));
    		informe.Datos [0] = cadena;
    		if (Moda (d, t)!= d[0])
    		{
    			cadena.Format(_T("\n\tModa no única: Min es %f"),d[0]);
    	
    			informe.Datos [1] = cadena;
    		}
    		else
    		{
    			cadena.Format(_T("\n\tModa:\t\t%f"),Moda(d,t));
    	
    			informe.Datos [1] = cadena;
    		}
    		cadena.Format (_T("\n\tMediana:\t\t%.*f"), PRESICION, Mediana (d, t));
    		informe.Datos [2] = cadena;
    	
    		cadena.Format (_T("\n\tCuartil1:\t\t%.*f"), PRESICION, Cuartil1(d, t));
    		informe.Datos [3] = cadena;
    		cadena.Format (_T("\n\tCuartil2:\t\t%.*f"), PRESICION, Cuartil2 (d, t));
    		informe.Datos [4] = cadena;
    		cadena.Format (_T("\n\tCuartil3:\t\t%.*f\n"), PRESICION, Cuartil3(d, t));
    		informe.Datos [5] = cadena;
    	}
    
    	if(p->Tipo==0 && p->Escala==2 )
    	{
    		d = QuitarAusentes (p->Datos , t, p->Ausente );	
    	
    	
    		cadena.Format(_T( "\n\n \t\tMEDIDAS DE POSICIÓN\n\n"));
    		informe.Datos [0] = cadena;
    
    		if (Moda (d, t)!= d[0])
    		{
    			cadena.Format(_T("\n\tModa no única: Min es %f"),d[0]);
    	
    			informe.Datos [1] = cadena;
    	
    		}
    		
    		else
    		{
    			cadena.Format(_T("\n\tModa:\t%f"),Moda(d,t));
    	
    			informe.Datos [1] = cadena;
    	
    		}
    	
    		
    	}
    	
    	else if(p->Tipo==1)
    	{
    		int rep=0,k;
    		int tamano=0;
    		CString *nuevo,cad;
    		double *vector;
    		vector= new double[t];
    		nuevo=new CString [t];
    	
    		for(i=0;i<t;i++)
    		{
    			nuevo[i]=p->Dat_Txt[i];
    		}
    
    		for(i=0;i<t;i++)
    		{
    		vector[i]=atoi(CT2CA(nuevo[i]));
    		}
    	
    	
    		//d = QuitarAusentes (vector , t, p->Ausente );	
    	
    		
    		cadena.Format( _T("\n\n \t\tMEDIDAS DE POSICI&#211;N\n\n"));
    		informe.Datos [0] = cadena;
    
    		if (Moda (vector, t)!= vector[0])
    		{
    			cadena.Format( _T("\n\tModa no &#250;nica: Min es %f"),vector[0]);
    	
    			informe.Datos [1] = cadena;
    	
    		}
    		else
    		{
    			cadena.Format( _T("\n\tModa:\t%f"),Moda(vector,t));
    	
    			informe.Datos [1] = cadena;
    	
    	
    		}
    		
    	}
    	
    	cadena=  _T("\n\t") + informe.Descripcion +  _T("\n\n");
    	cadena +=  _T("\tFecha creaci&#243;n:\t") + informe.Fecha +  _T("\n");
    	cadena +=  _T("\tHora creaci&#243;n:\t") + informe.Hora +  _T("\n");
    	aux.Format ( _T("%d"), informe.nTamano );
    	cadena +=  _T("\tTama&#241;o Muestra:\t") + aux+  _T("\n");
    	aux.Format ( _T("%d"), informe.nPerdidos );
    	cadena +=  _T("\tDatos Perdidos:\t") + aux +  _T("\n");
    	cadena +=  _T("\tVariable:\t\t") + informe.VarsImplicadas ;
    	k=0;
    		for (i=0;i<informe.nTamano;i++)
    		{
    		cadena +=  _T("\t") + informe.Datos[k];
    			k++;				
    		}
    		
      
       m_rich.SetWindowText (cadena);	
    	
    }
    Last edited by a343; August 29th, 2011 at 11:08 AM.

  2. #2
    Join Date
    Sep 2004
    Location
    Holland (land of the dope)
    Posts
    4,123

    Re: RichEdit Control not show text

    SetWindowText sets the text of a CWnd. A RichEditControl is much more and has its own functions to set the text. Check the help on a RichEditControl.

  3. #3
    Join Date
    Aug 2011
    Posts
    69

    Re: RichEdit Control not show text

    Quote Originally Posted by Skizmo View Post
    SetWindowText sets the text of a CWnd. A RichEditControl is much more and has its own functions to set the text. Check the help on a RichEditControl.
    Could you give me any web, plz? Do you know which is the function to show the text?

  4. #4
    Join Date
    Sep 2004
    Location
    Holland (land of the dope)
    Posts
    4,123

    Re: RichEdit Control not show text


  5. #5
    Join Date
    Aug 2011
    Posts
    69

    Re: RichEdit Control not show text

    I'm sorry, I'm so silly, but I've looked all day and I didn't find the function to show the text in richEdit control 2.0. Please, Could you give the name or the web?
    I'm learning to program in visual c++

  6. #6
    Join Date
    May 2006
    Location
    Dresden, Germany
    Posts
    458

    Re: RichEdit Control not show text

    Hi,

    Quote Originally Posted by a343 View Post
    I'm sorry, I'm so silly, but I've looked all day and I didn't find the function to show the text in richEdit control 2.0. Please, Could you give the name or the web?
    I'm learning to program in visual c++
    "Learning to program in visual c++" is much harder then learning how to use a web search engine (just like google like Skizmo proposed).

    Why should we google that for you? In Post #2 Skizmo provided you the right idea and suggested to google for the details. Please be so kind and google that by your own. It seems to me that you don't want to "learn to program in visual c++" : What you want to do is : Getting finished working code from CodeGuru ...

  7. #7
    Join Date
    Aug 2011
    Posts
    69

    Re: RichEdit Control not show text

    I'm sorry but if I posted here were becouse I looked in google and I didnt understood and I didnt find the function.
    I just looked for someone that he can say to me the name or something like that. But dont worry, I look for more or I will ask another person.
    Thank you.

  8. #8
    Join Date
    Apr 2009
    Posts
    598

    Re: RichEdit Control not show text

    Please, use [code] and [/code] tags around your lines of code. They will show nicely like this:
    Code:
    m_rich.SetWindowText (cadena);
    Where does m_rich come from?

    Anyway, I have used successfully Rich Edit Controls but I have done it in C, not in C++. I show you what I do when I want to insert a character:
    Code:
    /* =================================================================
       Write a character in the RTF control
       ================================================================= */
    int RTFEDIT_putc(char c, COLORREF col, int h, int x)
    {
       CHARFORMAT cf; char buf[2]; // HDC hdc;
    
       Edit_Enable(hRTF, FALSE);
    
       ZeroMemory(&cf, sizeof(CHARFORMAT));
       cf.cbSize = sizeof(CHARFORMAT);
       cf.dwMask = CFM_BOLD | CFM_COLOR | CFM_ITALIC |
                              CFM_SIZE | CFM_UNDERLINE;
       cf.dwEffects = 0;
       if (h > 0)
          cf.yHeight = h;
       else
          cf.yHeight = 160;
       cf.yOffset = 0;
       if (col > 0)
          cf.crTextColor = col;
       else
          cf.crTextColor = RGB(0,0,0);
    
       Edit_SetSel(hRTF, x, x+1);
       buf[0] = c; buf[1] = '\0';
       SendMessage(hRTF, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM) &cf);
       Edit_ReplaceSel(hRTF, buf);
       Edit_SetSel(hRTF, 0, 0);
    
       Edit_Enable(hRTF, TRUE);
    
       return TRUE;
    }

  9. #9
    Join Date
    May 2006
    Location
    Dresden, Germany
    Posts
    458

    Re: RichEdit Control not show text

    If you really want to get help, please:


    • Be concise
    • Tell us what you've done so far (e.g. "I found the following link ...")
    • Describe as exact as possible where you have problems (e.g. "I tried this or this and I got the following error message ..:", or "I didn't understand ...")

    That way you used there is only a small chance to get help. Skizmo gave you the right keyword for a search and you asked again for the name of the function to set the text in a rich edit control

    Using google and skizmo's hint I got the following hint:

    "Before every use of a CRichText, you must call AfxInitRichEdit();".
    (source: http://www.programmersheaven.com/mb/...-edit-control/)

    Maybe that is what you're looking for?

    Regards
    PA

  10. #10
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: RichEdit Control not show text

    I don't think the responses here are really appropriate.

    OP did post code and asked a reasonable question.

    I've never used CRichEditCtrls so I can't help, but I did look at the documentation and didn't see any obvious function for setting the text either.

  11. #11
    Join Date
    May 2006
    Location
    Dresden, Germany
    Posts
    458

    Re: RichEdit Control not show text

    Hi,

    @GCDEF: Maybe I've been a little bit too harsh here.

    General answer to the use of rich edit controls:

    MSDN states:

    Because rich edit controls support almost all of the messages and notification codes used with multiline Edit Controls, applications that already use edit controls can easily be changed to use rich edit controls.
    Source link : http://msdn.microsoft.com/en-us/libr...=vs.85%29.aspx

    meaning that the WM_SETWINDOWTEXT message shoud work.

    I tried the following:

    In my Win32 MFC application I added a rich edit control to a test dialog, giving it a resource id and a member variable of type CRichEditCtrl. The result was that the dialog has not been created succesfully.

    After adding a call to AfxInitRichEdit before calling DoModal of the dialog all things worked fine.
    Please note that the multi line style shoud be enabled to get a proper working rich edit control.

    The reason for beeing just a little bit harsh to the OP was that he didn't refer to Skizmo's suggestions at all (but he did so after my harsh post).

    Regards
    PA

  12. #12
    Join Date
    Aug 2011
    Posts
    69

    Re: RichEdit Control not show text

    Thank you everypeople.
    @ProgramArtis I know I must call to AfxInitRichEdit2 before to call DoModal, it is not the problem.

    The problem is that when I call the dialog the container is in white, but maybe it is due to I call SetWindowsText instead of another function own of richedit control

    I'm going to investigate about everypeople said to me and I'm going to visit every web, and if I still have any question, I try to do the question more concise.

    Thank you

    EDIT: Finally I resolved my problem change richedit by edit. Thank you
    Last edited by a343; August 31st, 2011 at 03:45 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured