Dark Bit Factory & Gravity

PROGRAMMING => C / C++ /C# => Topic started by: va!n on June 07, 2012

Title: Win32 - How to draw a WCHAR (Unicode Char) with TextOut() ?
Post by: va!n on June 07, 2012
For my Win32 project i want like to draw special chars with something like TextOut()... I will define the special chars as WCHAR and set its HexValue like following codesnip but i cant get it work. Any idea how to solve this? Thanks!

Code: [Select]
WCHAR testchar = 0x00A9;

TextOut( hdc, 20, 10, TEXT("A"), 1);        // Works fine !
TextOut( hdc, 80, 10, (WCHAR)testchar , 2);   // Does not work :(

Btw yes, the project is compiled by using unicode charset!
Title: Re: Win32 - How to draw a WCHAR (Unicode Char) with TextOut() ?
Post by: Jim on June 07, 2012
WCHAR tc[2]={0};
tc[0]=testchar;
TextOut(,,,tc,2);

TextOut prints strings not characters so you need to make a string.
Jim
Title: Re: Win32 - How to draw a WCHAR (Unicode Char) with TextOut() ?
Post by: va!n on June 07, 2012
@Jim:
Cool! Many thanks for your help, it works fantastic now! This problem has cost me some hours ^^
K++
Title: Re: Win32 - How to draw a WCHAR (Unicode Char) with TextOut() ?
Post by: Canopy on June 07, 2012
if TextOut doesn't need a NULL terminator you could just do..

WCHAR testchar = 0x00A9;

TextOut( hdc, 20, 10, &testchar, 1);       




;)
Title: Re: Win32 - How to draw a WCHAR (Unicode Char) with TextOut() ?
Post by: va!n on June 07, 2012
@Canopy:
Thanks! I am not sure if TextOut() requires a NULL terminated string or not...
However, it seems to work ;) K++
Title: Re: Win32 - How to draw a WCHAR (Unicode Char) with TextOut() ?
Post by: energy on June 07, 2012
MultiByteToWideChar
Quote
This function maps a character string to a wide-character (Unicode) string.
http://msdn.microsoft.com/en-us/library/bb202786.aspx