Home   Artículos   Recursos   Foros   
Artíclos recientes publicados en Latindevelopers:

Visual C++: NSDoubleEdit: Un control para el manejo de números decimales en Visual C++.
Visual C++: Implementando una Calculadora en Visual C++
Visual C++: CCommandLine: Una clase para el uso de la linea de comando
Visual C++: Una clase para el manejo del Registro


ORDENAR UNA FRASE

Aqui programadores en la plataforma Win32 con Visual C++ de Microsoft...

Moderador: latindeveloper

ORDENAR UNA FRASE

Notapor gabrieluno el Dom Dic 18, 2005 8:29 pm

HOLA AMIGOS QUIERO SABER COMO PUEDO IMPRIMIR EN LA VISTA UNA FRASE LARGA. POR EJEMPLO TENGO UNA CADENA DE 55 CARACTERES Y A PARTIR DE 20 CARACTERES QUE IMPRIMA EN LA SIGUIENTE LINEA EL RESTO DE LA FRASE, PERO QUE LAS PALABRAS NO SE CORTEN.

    ESTO ES UNA PRUEBA
    DE COMO SE DEBE
    IMPRIMIR EN LA VISTA


ES URGENTE AMIGOS LES AGRADESCO ANTICIPADAMENTE.
gabrieluno
Usuario Activo
Usuario Activo
 
Mensajes: 55
Registrado: Mar May 17, 2005 11:26 am

REPUESTA A MI PROPIA PREGUNTA

Notapor gabrieluno el Mié Ene 04, 2006 12:56 am

HOLA AMIGOS SE QUE ME DEMORE EN RESPONDERME YA QUE AGRADESCO A MUCHOS AMIGOS DE LA RED QUE PUDIERO AYUDARME MUCHO EN RESOLVER ESTE PROBLEMA DE ORDENAR UNA FRASE. BUENO AQUI LES DEJO EL CODIGO PARA QUE USTEDES LE DEAN UN BUEN USO.

AQUI ESTA LA CLASES QUE SE UTILIZARA PARA PODER ORDENAR
Código: Seleccionar todo
const int MAXPAL = 30;
class CObtenerPalabra
{
   char *buffer, palabra[MAXPAL];
   char *p_actual;
private:
   inline int IsSpace (int i) { return i == ' ' /*|| i == '\n' || i == '\t'*/; }
public:
   CObtenerPalabra (char* texto)
   {
      buffer = new char[strlen (texto) + 1];
      strcpy (buffer, texto);
      for (p_actual = buffer; *p_actual && IsSpace(*p_actual); //isspace(*p_actual);
     p_actual++);
   }
   ~CObtenerPalabra () { delete[] buffer; }
   
   char* SiguientePalabra ()
   {
      if (*p_actual == '\0')
         return NULL;
      for (int i = 0; *p_actual && !IsSpace(*p_actual) && i < MAXPAL; i++)
         palabra[i] = *p_actual++;
      
      palabra[i] = '\0';
      while (*p_actual && IsSpace(*p_actual))
            p_actual++;
   return palabra;
   }
   void Reset ()
   {
      for (p_actual = buffer; *p_actual && IsSpace(*p_actual); p_actual++);
   }
};


Y CON ESTO LO LLAMAN EN LA VISTA
Y SE ORDENARA.. APROPOSITO TIENEN QUE HACER QUE SU VARIABLE SEA DE TIPO CString m_Frase, es la que llamara a la frase del dialogo que quieran imprimir en la vista
Código: Seleccionar todo
LPTSTR lpsz = new TCHAR[m_Frase.GetLength()+1];
   _tcscpy(lpsz, m_Frase);

   
   CObtenerPalabra op (lpsz);
   int maximo = 40, count = 0,tt=0;
   char* p;
   // muestra el texto con un máximo de 24 caracteres
   while (1)
   {
      if ((p = op.SiguientePalabra ()) == NULL)
         break;
    
      if ((count + strlen (p) + 1) <= maximo)
     {
      pDC->TextOut(100+(count*10),100+(tt*15),p);
      count += strlen (p) + 1;
     } else
     {
      tt++;
      pDC->TextOut(100,100+(tt*15),p);
      count = strlen (p) + 1;
     }
    
   }

Espero que se les sea de mucha utilidad como a mi
bye.
gabrieluno
Usuario Activo
Usuario Activo
 
Mensajes: 55
Registrado: Mar May 17, 2005 11:26 am

Re: REPUESTA A MI PROPIA PREGUNTA

Notapor latindeveloper el Jue Ene 05, 2006 6:33 pm

Felicitaciones, este codigo realmente es bueno.
Imagen
Avatar de Usuario
latindeveloper
Administrador
Administrador
 
Mensajes: 1061
Registrado: Lun Jun 02, 2003 8:29 pm
Ubicación: Peru


Volver a Visual C++

¿Quién está conectado?

Usuarios navegando por este Foro: No hay usuarios registrados visitando el Foro y 0 invitados