問題描述
我是 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 仍然相關嗎?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!