 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
John Grabner Guest
|
Posted: Thu Jun 16, 2005 3:45 am Post subject: Richedit selected text japanese characters |
|
|
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.
|
|
| Back to top |
|
 |
Dave Deso Guest
|
Posted: Thu Jun 16, 2005 7:12 am Post subject: 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.
http://www.tntware.com/delphicontrols/unicode/
Those handle all unicode perfectly.
Best Regards,
Dave Deso
|
|
| Back to top |
|
 |
John Grabner Guest
|
Posted: Thu Jun 16, 2005 9:02 pm Post subject: 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.
http://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.
|
|
| Back to top |
|
 |
Andrue Cope [TeamB] Guest
|
Posted: Fri Jun 17, 2005 8:51 am Post subject: 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]
http://info.borland.com/newsgroups/guide.html
|
|
| Back to top |
|
 |
John Grabner Guest
|
Posted: Sun Jun 19, 2005 8:39 pm Post subject: 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.
|
|
| Back to top |
|
 |
Andrue Cope [TeamB] Guest
|
Posted: Mon Jun 20, 2005 8:36 am Post subject: 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]
http://info.borland.com/newsgroups/guide.html
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|