SetDlgItemText( ); UpdateData(FALSE); 它們都能更新編輯框的内容。
差別是UpdateData(FALSE)更新的是視窗中所有編輯框中的内容,而SetDlgItemText隻更新特定的編輯中的内容。
Unicode庫,字元串需要用_T(),CString動态配置設定記憶體空間,LPCTSTR是在Unicode環境下const char*的宏定義。
CString s;
int i = 64;
s.Format("%d", i);
Windows使用兩種字元集ANSI和Unicode,前者在處理英文字元時使用單位元組方式,在進行中文字元時使用雙位元組方式。後者不管是英文字元還是中文字元都是采用雙位元組方式表示。ANSI(即MBCS):為多位元組字元集。字元集的選擇在項目-----屬性----配置屬性-----正常裡。
_T是一個适配宏。當定義了_UNICODE時,_T和_L相同;否則,_T的字元串采用ANSI編碼方式。_L不管你是以什麼方式編譯,一律以Unicode方法儲存。
LPSTR:指向一個字元串的32位指針,每個字元占1個位元組。
LPCSTR:指向一個常量字元串的32位指針,每個字元占1個位元組。
LPTSTR:指向一個字元串的32位指針,每個字元可能占1個位元組或2個位元組。
LPCTSTR:指向一個常量字元串的32位指針,每個字元可能占1個位元組或2個位元組。
ansi情況下,LPCTSTR 就是 const char*,而LPTSTR 就是 char*。CString 和 LPCTSTR 基本可以通用。CString 轉換到 LPTSTR (char*), 預定的做法是調用CString的GetBuffer函數,使用完畢之後一般都要再調用ReleaseBuffer函數來确認修改。CString是CStringT的一種,CStringT是從CSimpleStringT繼承來的。GetBuffer是CSimpleStringT的函數。
If nMinBufferLength is greater than the length of the current buffer, the call toGetBuffer destroys the current buffer, replacing it with a buffer of the requested size and resetting the reference count to zero.
If count is less than or equal to the length ofstrSource, a null character is not appended automatically to the copied string. Ifcount is greater than the length of strSource, the destination string is padded with null characters up to lengthcount。
CString strTest("test");
_tcsncpy(strTest.GetBuffer(10), _T("Taw234"), 7);
int sizeOfBuffer = strTest.GetAllocLength();
strTest.ReleaseBuffer();
當從一個CString産生另一個CString并不複制它的字元緩沖區内容,而隻是将字元緩沖區的"引用計數"加1。