在标准的ASCII码中,是有黑桃、红心、梅花、方块这几的字符定义的(0x03,0x04,0x05,0x06),我想在windows程序中可以输出这几个符号,但是windows使用的字符集是Windows ANSI字符集(基于ANSI/ISO 8859-1),请问怎样能在windows程序中输出这几个符号呢?我使用过unicode,但是也不能输出
我是这样写的
TCHAR t[100];
wsprintf(t,TEXT("%c"),0x0004);
TextOut(hdc,100,100,t,lstrlen(t));
编译的时候已经加上了UNICODE和_UNICODE两个宏,但是还是不能输出,我查了msdn,TextOut应该是支持unicode的
Unicode: implemented as Unicode and ANSI versions on Windows and Windows NT.(摘录自msdn)
望各位帮忙

解决方案 »

  1.   

    试试:WCHAR t = 0x04;
    TextOutW(hdc,100,100,&t,1);
      

  2.   

    TO:everandforever(Forever) 
    0x03:红心
    0x04:方块
    0x05:梅花
    0x06:黑桃
    就是这几个字符了。
    用你的方法还是不行的。WCHAR对应的应该是控制台程序的宽字符吧?windows使用宽字符,应该是用TCHAR,然后编译的时候加上UNICODE宏吧(我是看《windows程序设计》的时候看到的)
    问题没有解决,希望帮忙
      

  3.   

    以下代码你可以试试。黑红梅方不是你那几个字符,是下面我写的几个。UNICODE才支持,ANSI不支持。
    WCHAR是UNICODE字符。TEXTOUTW是输出UNICODE字符串。注:有的字体不支持显示黑红梅方这样的特殊字符。HDC hdc = ::GetDC( NULL );
    HFONT hFont = ::CreateFont( 28, 0, 0, 0, FW_NORMAL, FALSE,
    FALSE, 0, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS,
    CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
    DEFAULT_PITCH | FF_SWISS, _T("Arial") );
    HFONT hOldFont = ( HFONT )::SelectObject( hdc, hFont );
    WCHAR sz[4];
    sz[0] = 0x2660;
    sz[1] = 0x2665;
    sz[2] = 0x2663;
    sz[3] = 0x2666;
    ::TextOutW( hdc, 2, 2, sz, 4 );
    ::SelectObject( hdc, hOldFont );
    ::DeleteObject( hFont );
    ::ReleaseDC( NULL, hdc );
      

  4.   

    TO:everandforever(Forever)谢谢你的方法,确实可以显示到我需要的四个符号。我想问问原理是什么呢?为什么我用ASCII码不能输出到那4个符号呢?而在控制台程序上,是可以输出这4个符号的,在windows中为什么不能这样做呢?
    像这段代码:
    #include <iostream>using namespace std;int main(int argc,char* argv[])
    {
      char c[5] = {0x03,0x04,0x05,0x06,'\0'};
      cout <<c<<endl;
      return 0;
    }
    在控制台程序中,输出就是我要的4个符号了。
    还望 everandforever(Forever) 指点。
      

  5.   

    我想应该是使用CreateFont函数中其中一个参数:fdwCharSet指定字符集,然后再使用里面的字符
    Specifies the character set. The following values are predefined: 
    ANSI_CHARSET
    BALTIC_CHARSET
    CHINESEBIG5_CHARSET
    DEFAULT_CHARSET
    EASTEUROPE_CHARSET
    GB2312_CHARSET
    GREEK_CHARSET
    HANGUL_CHARSET
    MAC_CHARSET
    OEM_CHARSET
    RUSSIAN_CHARSET
    SHIFTJIS_CHARSET
    SYMBOL_CHARSET
    TURKISH_CHARSET Korean Windows: 
    JOHAB_CHARSET 
    Middle-Eastern Windows: 
    HEBREW_CHARSET
    ARABIC_CHARSET 
    Thai Windows: 
    THAI_CHARSET 
    The OEM_CHARSET value specifies a character set that is operating-system dependent. You can use the DEFAULT_CHARSET value to allow the name and size of a font to fully describe the logical font. If the specified font name does not exist, a font from any character set can be substituted for the specified font, so you should use DEFAULT_CHARSET sparingly to avoid unexpected results. Fonts with other character sets may exist in the operating system. If an application uses a font with an unknown character set, it should not attempt to translate or interpret strings that are rendered with that font. This parameter is important in the font mapping process. To ensure consistent results, specify a specific character set. If you specify a typeface name in the lpszFace parameter, make sure that the fdwCharSet value matches the character set of the typeface specified in lpszFace. 
      

  6.   

    ASCII并没有把3,4,5,6规定为黑红梅方,你在控制台看到的只能说是一种(字体的)特殊情况。
    只有UNICODE定义了黑红梅方,各种字体都必须支持。
      

  7.   

    果然,我在http://www.unicode.org/上找到了以上4个符号的unicode码,看来以前一直是理解错误了。
    但现在又一个不解的地方
    HDC hdc = ::GetDC( NULL );
    HFONT hFont = ::CreateFont( 28, 0, 0, 0, FW_NORMAL, FALSE,
    FALSE, 0, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS,
    CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
    DEFAULT_PITCH | FF_SWISS, _T("Arial") );
    HFONT hOldFont = ( HFONT )::SelectObject( hdc, hFont );
    WCHAR sz[4];
    sz[0] = 0x2660;
    sz[1] = 0x2665;
    sz[2] = 0x2663;
    sz[3] = 0x2666;
    ::TextOutW( hdc, 2, 2, sz, 4 );
    ::SelectObject( hdc, hOldFont );
    ::DeleteObject( hFont );
    ::ReleaseDC( NULL, hdc );
     everandforever(Forever) 你的这代码,我将
    HFONT hFont = ::CreateFont( 28, 0, 0, 0, FW_NORMAL, FALSE,
    FALSE, 0, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS,
    CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
    DEFAULT_PITCH | FF_SWISS, _T("Arial") );
    HFONT hOldFont = ( HFONT )::SelectObject( hdc, hFont );
    ::SelectObject( hdc, hOldFont );
    ::DeleteObject( hFont );
    这几句注释掉,仍然使用TextOutW输出,同是在编译的时候也定义了UNICODE和_UNICODE宏,但输出的确实一些乱码,这是不是因为默认字体没有支持unicode的原因呢?
      

  8.   

    好了,终于可以结贴了。谢谢everandforever(Forever)!