Click here to Skip to main content
15,883,558 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,
m trying to extract text from Microsoft Rich Textbox Control 6.0 by using GetWindowText(). My code is-

CString str;
m_richctrl.GetWindowText(str);
MessageBox(str);

bt by using this, m getting abort message and empty messagebox.
How do I get text from Rich Textbox & display it?
I know this is very easy task, bt i don't know hw to do it.
Plz help me..
Thanx in advnc............
Posted

SMS speak is not acceptable on these forums.
 
Share this answer
 
Use GetLine(int nIndex,LPTSTR lpszBuffer) function to read specific line from Rich Textbox it will copy specified index line into buffer. To read whole line use GetLineCount() function which will return you the total no. of lines in Rich Textbox, using this make loop to read all lines.
 
Share this answer
 
Comments
virus131 8-Apr-11 7:47am    
its not working
Check your m_richctrl is valid window or not.Also, Where you are using control in dialog box or like a view in MainFrame.
 
Share this answer
 
You can do it in this way:
#include <Richedit.h>
unsigned int GetRichText(HWND hrich,int bRTF,TCHAR* buff,const unsigned int size)
{
  struct _
  {
    static unsigned int  copy(char* dst,unsigned int ndst,char* src,unsigned int nsrc)
      { unsigned int i; for(i=0;i<min(ndst,nsrc);i++) dst[i]=src[i]; dst[i<ndst?i:i-1]=0; return i; }
    static unsigned int  copy(unsigned short* dst,unsigned int ndst,unsigned short* src,unsigned int nsrc)
      { unsigned int i; for(i=0;i<min(ndst,nsrc);i++) dst[i]=src[i]; dst[i<ndst?i:i-1]=0; return i; }
  #ifdef _UNICODE
    static void  rtfW(unsigned long p,unsigned short* pbBuff,long cb,long* pcb)
      { _*me=(_*)p; me->done=copy(me->buff,me->size,pbBuff,cb); *pcb=cb; }
    static void  txtW(unsigned long p,unsigned short* pbBuff,long cb,long* pcb)
      { _*me=(_*)p; me->done=copy(me->buff,me->size,pbBuff,cb); *pcb=cb; }
  #else
    static void  rtfA(unsigned long p,char* pbBuff,long cb,long* pcb)
      { _*me=(_*)p; me->done=copy(me->buff,me->size,pbBuff,cb); *pcb=cb; }
    static void  txtA(unsigned long p,char* pbBuff,long cb,long* pcb)
      { _*me=(_*)p; me->done=copy(me->buff,me->size,pbBuff,cb); *pcb=cb; }
  #endif
    
    TCHAR*        buff;
    unsigned int  size;
    unsigned int  done;
  }             get = { buff,size,0 };
  EDITSTREAM    eds = { (DWORD_PTR)&get,0, };

  if(bRTF)
  {
  #ifdef _UNICODE
    eds.pfnCallback = (EDITSTREAMCALLBACK)get.rtfW;
    SendMessage(hrich,EM_STREAMOUT,SF_RTF|SF_UNICODE,(LPARAM)&eds);
  #else
    eds.pfnCallback = (EDITSTREAMCALLBACK)get.rtfA;
    SendMessage(hrich,EM_STREAMOUT,SF_RTF,(LPARAM)&eds);
  #endif
  }
  else
  {
  #ifdef _UNICODE
    eds.pfnCallback = (EDITSTREAMCALLBACK)get.txtW;
    SendMessage(hrich,EM_STREAMOUT,SF_TEXT|SF_UNICODE,(LPARAM)&eds);
  #else
    eds.pfnCallback = (EDITSTREAMCALLBACK)get.txtA;
    SendMessage(hrich,EM_STREAMOUT,SF_TEXT,(LPARAM)&eds);
  #endif
  }
  return get.done;
}

Regards.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900