TCHAR 仍然相关吗?

Is TCHAR still relevant?(TCHAR 仍然相关吗?)
本文介绍了TCHAR 仍然相关吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!


我是 Windows 编程的新手,在阅读了 Petzold 的书后,我想知道:

I'm new to Windows programming and after reading the Petzold book I wonder:

使用 TCHAR 类型和 _T() 函数来声明字符串还是我应该只使用 wchar_t 函数的好习惯> 和 L"" 字符串在新代码中?

is it still good practice to use the TCHAR type and the _T() function to declare strings or if I should just use the wchar_t and L"" strings in new code?

我将只针对 Windows 2000 及更高版本,并且我的代码从一开始就是 i18n.

I will target only Windows 2000 and up and my code will be i18n from the start up.


如果我今天在做一个新项目,我仍然会使用 TCHAR 语法.使用它和 WCHAR 语法之间没有太大的实际区别,我更喜欢明确字符类型的代码.由于大多数 API 函数和辅助对象采用/使用 TCHAR 类型(例如:CString),因此使用它才有意义.此外,如果您决定在某个时候在 ASCII 应用程序中使用代码,或者如果 Windows 演变为 Unicode32 等,它会为您提供灵活性.

I would still use the TCHAR syntax if I was doing a new project today. There's not much practical difference between using it and the WCHAR syntax, and I prefer code which is explicit in what the character type is. Since most API functions and helper objects take/use TCHAR types (e.g.: CString), it just makes sense to use it. Plus it gives you flexibility if you decide to use the code in an ASCII app at some point, or if Windows ever evolves to Unicode32, etc.

如果你决定走 WCHAR 路线,我会明确说明这一点.即,使用 CStringW 代替 CString,并在转换为 TCHAR 时转换宏(例如:CW2CT).

If you decide to go the WCHAR route, I would be explicit about it. That is, use CStringW instead of CString, and casting macros when converting to TCHAR (eg: CW2CT).


That's my opinion, anyway.

这篇关于TCHAR 仍然相关吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!



Algorithm to convert RGB to HSV and HSV to RGB in range 0-255 for both(将 RGB 转换为 HSV 并将 HSV 转换为 RGB 的算法,范围为 0-255)
How to convert an enum type variable to a string?(如何将枚举类型变量转换为字符串?)
When to use inline function and when not to use it?(什么时候使用内联函数,什么时候不使用?)
Examples of good gotos in C or C++(C 或 C++ 中好的 goto 示例)
Significance of ios_base::sync_with_stdio(false); cin.tie(NULL);(ios_base::sync_with_stdio(false) 的意义;cin.tie(NULL);)
C99 stdint.h header and MS Visual Studio(C99 stdint.h 头文件和 MS Visual Studio)