如何在MFC中使用编辑控件? [英] how to use edit control in MFC?

查看:103
本文介绍了如何在MFC中使用编辑控件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个编辑控制框,用户可以在其中输入一些值.所以我将编辑控件拖到对话框中.将变量类型为CString的值添加到此编辑控件.然后将消息类型为EN_CHANGE的事件处理程序添加到此编辑控件.下一步我该怎么做?

i want to make an edit control box in which user can enter some value. so i drag an edit control to my dialog. add a variable "value of type CString to this edit control. then i add an event handler of message type EN_CHANGE to this edit control. what should i do next?

推荐答案

尝试编译该应用程序.


除非您计划在用户键入内容时进行某些操作,例如更新预览或在另一个控件中进行选择,否则不需要EN_CHANGE的事件处理程序.

查看您的虚拟 DoDataExchange() [ ^ ]函数,您将了解您的CEdit如何与CString对象交换数据.另外,请阅读 UpdateData() [
You don''t need an event handler for EN_CHANGE unless you plan on doing something while the user types, like updating a preview or making selections in another control.

Look at your implementation of the virtual DoDataExchange()[^] function and you will see how your CEdit is interchanging data with the CString object. Also, read about the UpdateData()[^] function on msdn.

...and of course, don''t forget John Simmons suggestion. It is a good one! ;)


UpdateData()仅影响您已连接到DoDataExchange()中的控件的变量.
* .h
UpdateData() only affects the variables you have hooked up to your control in DoDataExchange().
*.h
CString m_strEditValue;


* .cpp


*.cpp

DoDataExchange(CDataExchange* pDX)
{
    DDX_Text(pDX, IDC_EDIT, m_strEditValue);
}
SomewhereElse()
{
    UpdateData(TRUE); // Get value from control to variable
      // m_strEditValue now contains the value entered in the edit control

    UpdateDate(FALSE); // Send variable data to control
      // The edit control now contains the value of m_strEditValue
}



UpdateData()最终将调用您的DoDataExchange()方法.使用调试器进入它,看看它如何工作以更好地理解.



UpdateData() will eventually call your DoDataExchange() method. Step into it with a debugger and see how it works to get a better understanding.


这篇关于如何在MFC中使用编辑控件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆