我用的基于对话框的应用程序:在CEdit控件的ON_EN_CHANGE响应消息函数中: void CNetDlg::OnChangeEdit2()
{
//很多代码省略,只写主要的
CString in;
GetDlgItem(IDC_EDIT2)->GetWindowText(in);//获得用户输入的文字 if(in.GetAt(in.GetLength()-1)=='/n')
//若用户按下回车键,则在IDC_EDIT1控件中显示输入的文本
{
GetDlgItem(IDC_EDIT1)->SetWindowText(in);
GetDlgItem(IDC_EDIT2)->SetWindowText("");
}
}
为什么我测试的时候,按下回车键不管用,也就是说:if(in.GetAt(in.GetLength()-1)=='/n')
这句话没有被通过?是什么原因??
程序就可以运行了,不管我输入什么字符,只要我一打a,输入框的问题就显示到IDC_EDIT2 上了。
void CExample1Dlg::OnInputText()
CString in;
GetDlgItem(IDC_INPUTTEXT)->GetWindowText(in);
//输入框中只有回车键被按下,所以不发送回车键字符
if(in.GetLength()<1)
{
return;
}
if(in.GetAt(in.GetLength()-1)=='\n')
{
//in.TrimRight(" ")用来消去无用的空格键字符
in.TrimRight(" ");
//将输入框中的字符清空,表示字符已经被发送
GetDlgItem(IDC_INPUTTEXT)->SetWindowText("");
if(in.GetLength()>2)
{
m_sShowText+=in;
//将输入的话显示到显示窗口中
GetDlgItem(IDC_SHOWTEXT)->SetWindowText(m_sShowText);
CEdit * output=(CEdit *)GetDlgItem(IDC_SHOWTEXT);
//随时跟踪滚动条的位置
output->LineScroll(output->GetLineCount()); //服务器端
if(!m_bClient)
{
int length=m_connectionList.GetCount();
SOCKET socket;
for(int i=0;i<length;i++)
{
socket=m_connectionList.GetAt(m_connectionList.FindIndex(i));
send(socket,in.GetBuffer(0),in.GetLength(),0);
}
}
//客户端
else
{
m_client.SendString(in);
}
}
}它的消息映射:ON_EN_UPDATE(IDC_INPUTTEXT,OnInputText)
运行正常
ON_EN_CHANGE The user has taken an action that may have altered text in an edit control. Unlike the EN_UPDATE notification message, this notification message is sent
after Windows updates the display. 所以当按下回车键的时候,在ON_EN_CHANGE无法发现那个回车符。
另外,需要将Edit对话框设置为Want return 和 Vertical Scroll。
ON_EN_CHANGE The user has taken an action that may have altered text in an edit control. Unlike the EN_UPDATE notification message, this notification message is sent
after Windows updates the display. 所以当按下回车键的时候,在ON_EN_CHANGE无法发现那个回车符。
另外,需要将Edit对话框设置为Want return 和 Vertical Scroll。