Board index » cppbuilder » Richedit selected text japanese characters

Richedit selected text japanese characters


2005-06-16 11:45:31 AM
cppbuilder7
I have a richedit. It is displaying text in Japanese. When I have
selected some text I am trying to get at it in code, but all I get is a
string of spaces. I can get the position (in bytes) of the first
character selected, and the length is correct for the multi bytes
selected. However SelText gives me one space for each character
selected. it appears to be a problem with EM_GETSELTEXT. I am using
windows 2000.
John Grabner.
 
 

Re:Richedit selected text japanese characters

John Grabner wrote:
Quote
I have a richedit. It is displaying text in Japanese. When I have
selected some text I am trying to get at it in code, but all I get is a
string of spaces. I can get the position (in bytes) of the first
character selected, and the length is correct for the multi bytes
selected. However SelText gives me one space for each character
selected. it appears to be a problem with EM_GETSELTEXT. I am using
windows 2000.

John Grabner.
Dear John,
I'm not a professional in those issues, but think that the components
are not specifically designed for that use. You should have a look at
Delphi / C++ Builder components called Tnt.
www.tntware.com/delphicontrols/unicode/
Those handle all unicode perfectly.
Best Regards,
Dave Deso
 

Re:Richedit selected text japanese characters

Dave Deso wrote:
Quote

Dear John,

I'm not a professional in those issues, but think that the components
are not specifically designed for that use. You should have a look at
Delphi / C++ Builder components called Tnt.

www.tntware.com/delphicontrols/unicode/

Those handle all unicode perfectly.

Best Regards,
Dave Deso
I cannot replace the components. The rich edit displays the text
correctly. When I have selected text I can get the correct byte counts
from the control i.e. start count and length. What I can't get is the
text its self.
John.
 

{smallsort}

Re:Richedit selected text japanese characters

John Grabner wrote:
Quote
When I have selected text I can get the correct byte counts from the
control i.e. start count and length. What I can't get is the text its
self.
How are you trying to get the text? Since it's Japanese you will have
to use Unicode or else have the machine configured for the Japanese
code page.
I've only just been playing with TRichEdit myself so I don't know all
its ins and outs but have you tried using the clipboard? You can tell
the TRichEdit to send the selection to the clipboard so presumably it
will be possible to get the Unicode string back from there.
--
Andrue Cope [TeamB]
[Bicester, Uk]
info.borland.com/newsgroups/guide.html
 

Re:Richedit selected text japanese characters

Andrue Cope [TeamB] wrote:
Quote
John Grabner wrote:


>When I have selected text I can get the correct byte counts from the
>control i.e. start count and length. What I can't get is the text its
>self.


How are you trying to get the text? Since it's Japanese you will have
to use Unicode or else have the machine configured for the Japanese
code page.

I am using the SelText property. I am after the multi byte version of
the selected text. Configuring my computer for Japanese lets me get the
correct text using SelText.
John.
 

Re:Richedit selected text japanese characters

John Grabner wrote:
Quote
>I am using the SelText property. I am after the multi byte version
>of the selected text. Configuring my computer for Japanese lets me
>get the correct text using SelText.
Try copying it to the clipboard then. I would assume that TRichEdit
will copy the multibyte text up there so you can get it back. The
following code does that for us but returns an AnsiString, it should be
easy enough to address that:
// Support classes ----------
#include <clipbrd.hpp>
class TGeneral_RAII_Clipboard
{
std::auto_ptr<TClipboard>MyClipBoard;
public:
TGeneral_RAII_Clipboard()
{
MyClipBoard.reset( new TClipboard() );
MyClipBoard->Open();
}
~TGeneral_RAII_Clipboard()
{
MyClipBoard->Close();
}
TClipboard * Clipboard()
{
return MyClipBoard.get();
}
};
class TGeneral_RAII_GlobalLocker
{
HANDLE MyHandle;
void * MyPointer;
public:
TGeneral_GlobalLocker( HANDLE Handle )
{
MyHandle=Handle;
MyPointer=GlobalLock( Handle );
}
~TGeneral_GlobalLocker()
{
GlobalUnlock( MyHandle );
MyPointer=NULL;
}
void * Pointer()
{
return MyPointer;
}
};
// Main function --------
AnsiString General_UnicodeClipBoardToAnsiString( WORD CodePage )
{
HANDLE cbData=GetClipboardData( CF_UNICODETEXT );
if( cbData )
{
TGeneral_GlobalLocker gl( cbData );
wchar_t * cbData=reinterpret_cast<wchar_t *>( gl.Pointer() );
// Convert to ASCII and paste
int tmpResultSize=3*wcslen( cbData )+1;
boost::scoped_array<char>
tmpResult( new char[ tmpResultSize ] ); // Plenty of room
int outputLen=WideCharToMultiByte( CodePage,
WC_COMPOSITECHECK|WC_DISCARDNS,
cbData,
-1,
tmpResult.get(),
tmpResultSize,
NULL,
NULL );
if( outputLen )
return tmpResult.get();
}
// Some 'at went wrong. Give up and let the VCL have a go
TGeneral_RAII_Clipboard clipBoard;
return clipBoard->AsText;
}
--
Andrue Cope [TeamB]
[Bicester, Uk]
info.borland.com/newsgroups/guide.html