Author Topic: Win32 - How to draw a WCHAR (Unicode Char) with TextOut() ?  (Read 10161 times)

0 Members and 1 Guest are viewing this topic.

Offline va!n

  • Pentium
  • *****
  • Posts: 1435
  • Karma: 109
    • View Profile
    • http://www.secretly.de
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!
« Last Edit: June 07, 2012 by va!n »
- hp EliteBook 8540p, 4 GB RAM, Windows 8.1 x64
- Asus P5Q, Intel Q8200, 6 GB DDR2, Radeon 4870, Windows 8.1 x64
http://www.secretly.de
Challenge Trophies Won:

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
WCHAR tc[2]={0};
tc[0]=testchar;
TextOut(,,,tc,2);

TextOut prints strings not characters so you need to make a string.
Jim
Challenge Trophies Won:

Offline va!n

  • Pentium
  • *****
  • Posts: 1435
  • Karma: 109
    • View Profile
    • http://www.secretly.de
@Jim:
Cool! Many thanks for your help, it works fantastic now! This problem has cost me some hours ^^
K++
- hp EliteBook 8540p, 4 GB RAM, Windows 8.1 x64
- Asus P5Q, Intel Q8200, 6 GB DDR2, Radeon 4870, Windows 8.1 x64
http://www.secretly.de
Challenge Trophies Won:

Offline Canopy

  • Atari ST
  • ***
  • Posts: 208
  • Karma: 20
    • View Profile
if TextOut doesn't need a NULL terminator you could just do..

WCHAR testchar = 0x00A9;

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




;)

Offline va!n

  • Pentium
  • *****
  • Posts: 1435
  • Karma: 109
    • View Profile
    • http://www.secretly.de
@Canopy:
Thanks! I am not sure if TextOut() requires a NULL terminated string or not...
However, it seems to work ;) K++
- hp EliteBook 8540p, 4 GB RAM, Windows 8.1 x64
- Asus P5Q, Intel Q8200, 6 GB DDR2, Radeon 4870, Windows 8.1 x64
http://www.secretly.de
Challenge Trophies Won:

Offline energy

  • Amiga 1200
  • ****
  • Posts: 280
  • Karma: 25
    • View Profile
MultiByteToWideChar
Quote
This function maps a character string to a wide-character (Unicode) string.
http://msdn.microsoft.com/en-us/library/bb202786.aspx
coding: jwasm,masm
hobby: www.scd2003.de