cancel
Showing results for 
Search instead for 
Did you mean: 

How deal with "wchar_t" in textArea?

Wrend.1
Senior

I want to display a long "wchar_t" type text in a textArea.

Here is my code.

void seasoningDisplay::setSeasoningText(const wchar_t* input)
{
	touchgfx::Unicode::UnicodeChar tmpfmt[200];
	touchgfx::Unicode::strncpy(tmpfmt, (const char*)input, 200);
	Unicode::snprintf(seasoningTextBuffer, SEASONINGTEXT_SIZE, "%s", tmpfmt);
	seasoningText.resizeToCurrentText();
	seasoningText.invalidate();
}

I know it is not correct, please tell me how to realize it.

2 REPLIES 2
Martin KJELDSEN
Chief III

What\re you putting into `input`? UnicodeChar is 16-bit unsigned int, so just make sure your conversion matches that.

Yes. I use this function like:

setSeasoningText(L"这是中文");

​I used to think I need to use "touchgfx:: Unicode:: strncpy (tmpfmt, (const char *) input, 200) " to break through the textarea display size (63). It is my foolly.

Now I write the function like this:

void seasoningDisplay::setSeasoningText(const char* input)
{
	setlocale(LC_ALL, "chs");
	wchar_t *m_wchar = NULL;	
	int len = mbstowcs(m_wchar, input, 100) + 1;
	m_wchar = new wchar_t[len];
	mbstowcs(m_wchar, (const char*)input, 100);
	
	Unicode::snprintf(seasoningTextBuffer, SEASONINGTEXT_SIZE, "%s", m_wchar);
	seasoningText.resizeToCurrentText();
	seasoningText.invalidate();
	
	memset(m_wchar,0, len);
	delete m_wchar;
	setlocale(LC_ALL, "C");
}

By the way, It failed only in real board (compiled by keil). I works in PC simulator.

It just work when I use the char* like"12345". When I use the chinese character. I failed due to the exception of "mbstowcs".

So, how to setup keil make it work?