SetWindowText(SetWindowTextW)
void SetWindowText( LPCTSTR lpszString );
GetWindowText(GetWindowTextW)
void SetWindowText( LPCTSTR lpszString );
GetDlgItemText
int GetDlgItemText(
int nID, LPTSTR lpStr,
int nMaxCount ) const;
int GetDlgItemText(
int nID,
CString& rString ) const;
一、button
1.赋值
CString str; str="赋值字符串"; GetDlgItem(IDC_Button_***)->SetWindowTextW(str);
2.取值
方法一:
CString str; GetDlgItem(IDC_Button_***)->GetWindowTextW(str); MessageBox(str); str.ReleaseBuffer();
方法二:
UpdateData(TRUE); CString strText; GetDlgItemText(IDC_Button_***, strText);//IDC_Button_***是Button的ID UpdateData(FALSE); MessageBox(strText); str.ReleaseBuffer();
二、Edit
1.赋值
CString str; str="赋值字符串"; GetDlgItem(IDC_Edit_***)->SetWindowTextW(str); str.ReleaseBuffer();
2.取值
方法一:
CString str; GetDlgItem(IDC_Edit_***)->GetWindowTextW(str); MessageBox(str); str.ReleaseBuffer();
方法二:
UpdateData(TRUE); CString strText; GetDlgItemText(IDC_Edit_***, strText);//IDC_Edit_***是Edit的ID UpdateData(FALSE); MessageBox(strText); str.ReleaseBuffer();