在mfc中单击按钮时更改编辑框内容
我在对话框上有一个编辑框和一个按钮。单击按钮时如何更改编辑框运行时中的内容?我必须从文件中读取一条新记录,并在单击按钮时将其发布到编辑框中,并且我正在使用 mfc。
I have an Edit Box and a Button on a dialog. How can I change the content in the edit box runtime as the button is clicked? I have to read a new record from a file and post it in the Edit Box as the Button is clicked and I am using mfc.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
一旦捕获了按钮按下,在大多数情况下,更改编辑控件中的文本的最简单方法是:
其中,
IDC_EDIT_ID
是编辑控件的ID
(在属性
窗口)Once you have trapped the button press, in most cases the easiest way to change text in an Edit Control is:
Where
IDC_EDIT_ID
is theID
of the Edit Control (set in theproperties
window)您可以设置编辑控件的文本(由
CEdit
类包装 在 MFC 中)通过调用SetWindowText
方法,它继承来自 CWnd 基类。因此,您所需要做的就是响应按钮控件上的单击事件。您可以通过监听相应按钮的
BN_CLICKED
通知来执行此操作在父窗口的OnCommand
方法 中进行控制。例如:
获取并阅读一本有关 MFC 的书将会非常有帮助。这是相当基本的内容,但如果您还不了解基本概念,那么在一个答案中就需要涵盖很多内容。
使用类向导将使这变得更加容易...使用 Ctrl+W 键调用它并按照屏幕上的说明进行操作。你最终会得到类似的结果:
You can set the text of an Edit control (wrapped by the
CEdit
class in MFC) by calling theSetWindowText
method, which it inherits from theCWnd
base class.So then all you need to do is respond to a click event on your button control. You do this by listening for the
BN_CLICKED
notification from the appropriate button control within your parent window'sOnCommand
method.Something like:
Obtaining and reading a book on MFC would be very helpful. This is fairly basic stuff, but it's a lot to cover in a single answer if you don't already understand the fundamental concepts.
Using the Class Wizard would make this even easier... Invoke it with the Ctrl+W keys and follow the on-screen instructions. You'll end up with something like: