在标准的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)
望各位帮忙
我是这样写的
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)
望各位帮忙
解决方案 »
- clw文件没了,类向导重建时,文件名如何选呀?(有图)
- 有个小活儿外包
- 程序在结束前几句里出现NULL pointer?请大家进来看看,帮忙分析下,谢谢。
- CTreeView 中在OnLButtonDown函数怎么判断鼠标是否点击到节点?
- 昨天上VC在线www.vczx.com中毒了,大家注意!!
- 日历控件选择日期后怎么会发送两个 DTN_DATETIMECHANGE 通知消息呢
- 关于WINDOWPLACEMENT
- 请问:classview不能显示类了,该如何办???
- 请问:如何通过OnSize调整Dialog的大小?
- 在对话框上有一编辑框,我该如何在里面画图?请指教。
- 怎样动态SetActiveView
- 两个对话框的相互关系
TextOutW(hdc,100,100,&t,1);
0x03:红心
0x04:方块
0x05:梅花
0x06:黑桃
就是这几个字符了。
用你的方法还是不行的。WCHAR对应的应该是控制台程序的宽字符吧?windows使用宽字符,应该是用TCHAR,然后编译的时候加上UNICODE宏吧(我是看《windows程序设计》的时候看到的)
问题没有解决,希望帮忙
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 );
像这段代码:
#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) 指点。
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.
只有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的原因呢?