コードの問題は、呼び出した後、呼び出す前に_T("1")
文字列を変更(連結)しようとしたことだと思います。さらに、アンバランス/コールがあります。GetBuffer()
ReleaseBuffer()
GetBuffer()
ReleaseBuffer()
m_display
それがインスタンスであると仮定すると、次のCEdit
ようなコードを試すことができます(私のために働いた):
void CcalculatorDlg::OnBnClickedButton1()
{
// Get current text from edit control
// (assume a single-line edit control)
CString grabData;
m_display.GetWindowText(grabData);
// Concatenate "1"
grabData += L'1';
// Update edit control text
m_display.SetWindowText(grabData);
}
複数行の編集コントロールがあり、を使用して最初の(最上部の)行を取得する場合はCEdit::GetLine()
、次のようなコードを使用できます( MSDNのドキュメントによると、コピーされた行は終了EM_GETLINE
しないため、次のようになります。NUL
行の長さを明示的に指定するにはReleaseBuffer()
):
//
// Read first line from edit control
//
CString grabData;
static const int kMaxBufferLength = 80;
wchar_t* buffer = grabData.GetBuffer(kMaxBufferLength + 1);
// Note '+ 1' for NUL string terminator (it seems that EM_GETLINE, which is
// wrapped by CEdit::GetLine(), doesn't NUL-terminate the returned string).
const int grabDataLength = m_display.GetLine(0, buffer, kMaxBufferLength);
grabData.ReleaseBuffer(grabDataLength);
// *After* calling ReleaseBuffer(), you can modify the string, e.g.:
grabData += L'1'; // concatenate "1"