EDIT类的GetWindowTextW方法为什么得不到准确的值?
CMFCTestView类
// MFCTestView.h :
...
public:
CString csViewCString;//先在View类中定义一个CString型的全局变量
// MFCTestView.cpp
//VIEW菜单命令中写代码,显示一个对话框
void CMFCTestView::OnOpen()
{
// TODO: 在此添加命令处理程序代码
csViewCString="ok";//给全局变量赋值
CDlgTest dlg; //CDlgTest是添加好的对话框资源类
dlg.DoModal();//显示对话框
}
//对话框资源类CDlgTest,对话框上有一个EDIT,对其添加了一个CEDIT型的控件变量EdtDlg
...
BOOL CDlgTest::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: 在此添加额外的初始化
CMFCTestView *p=(CMFCTestView*)(((CMainFrame*)AfxGetMainWnd())->GetActiveView());
//将View类中的csViewCString变量值显示在EdtDlg中
EdtDlg.SetWindowTextW((LPCTSTR)(p->csViewCString));
return TRUE; // return TRUE unless you set the focus to a control
}
//可以看到EdtDlg中显示了"ok"
...在EdtDlg中在"ok"后用键盘输入"!"
void CDlgTest::OnBnClickedOk()
{
// TODO: 在此添加控件通知处理程序代码
CMFCTestView *p=(CMFCTestView*)(((CMainFrame*)AfxGetMainWnd())->GetActiveView());
char bufi[10];
EdtDlg.GetWindowTextW((LPTSTR)bufi,10);//将EdtDlg中内容写入bufi,令我不解的是bufi中,内容不是"ok!"而是"o",这是为什么呢?
p->csViewCString=bufi;
OnOK();
}
重说一遍问题:将EdtDlg中内容写入bufi,但bufi中内容不是"ok!"而是"o",这是为什么呢?
我哪里做的不对呢?