Click to See Complete Forum and Search --> : DrawText dilemma


JohnIdol
November 14th, 2007, 09:10 AM
Hi everyone.

I am trying to draw some text I retrieve from file but somehow I can't get it to display correctly.
I am retrieving the text as LPCSTR but as I am building with unicode Drawtext is mapped to DrawTextW.

If I translate my LPCSTR to LPCWSTR with MultiByteToWideChar I see Chinese characters when displaying.

If I use explictly DrawTextA everything works fine BUT I can't get to work carriage return and line feed sequences...

this is my code:


static char strText[1000];
char* strTemp= (char *)myModel->GetInstructions();
strcpy(strText, strTemp);

int a = lstrlenA(strText);
BSTR unicodestr = SysAllocStringLen(NULL, a);
::MultiByteToWideChar(CP_ACP, 0, strText, a, unicodestr, a);
::SysFreeString(unicodestr);

g_pFont1->DrawText(g_pTextSprite,
(LPCWSTR) &unicodestr,
lstrlenW(unicodestr),
&textbox,
DT_LEFT | DT_WORDBREAK,
D3DXCOLOR( 0.0f, 0.0f, 0.0f, 0.8f ));
}


Any help would be appreciated!

thanks in advance,

JI

JohnIdol
November 14th, 2007, 09:25 AM
Ok two stupid errors:

(LPCWSTR) &unicodestr -> remove &

::SysFreeString(unicodestr); -> move it after the DrawText(...)

Now the text is displaying correctly, but the sequence "\x0D\x0A" I retrieve from text is displaying as characters instead of as carriage return linefeed as expected.

Help!

Marc G
November 14th, 2007, 10:05 AM
Since the DrawText you are using is not the standard DrawText, we need to see the implementation of that DrawText function.

JohnIdol
November 14th, 2007, 10:33 AM
Tanks for answering, but I solved it; with this escape sequence it started working: 
 or 

Cheers,

JI