在mfc中单击按钮时更改编辑框内容

发布于 2025-01-01 02:33:19 字数 89 浏览 4 评论 0原文

我在对话框上有一个编辑框和一个按钮。单击按钮时如何更改编辑框运行时中的内容?我必须从文件中读取一条新记录,并在单击按钮时将其发布到编辑框中,并且我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

预谋 2025-01-08 02:33:19

一旦捕获了按钮按下,在大多数情况下,更改编辑控件中的文本的最简单方法是:

SetDlgItemText(IDC_EDIT_ID, "Desired Text String")

其中,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:

SetDlgItemText(IDC_EDIT_ID, "Desired Text String")

Where IDC_EDIT_ID is the ID of the Edit Control (set in the properties window)

雨落□心尘 2025-01-08 02:33:19

您可以设置编辑控件的文本(由 CEdit 类包装 在 MFC 中)通过调用 SetWindowText 方法,它继承来自 CWnd 基类。

因此,您所需要做的就是响应按钮控件上的单击事件。您可以通过监听相应按钮的BN_CLICKED通知来执行此操作在父窗口的 OnCommand 方法 中进行控制。

例如:

BOOL CMyDialog::OnCommand(WPARAM wParam, LPARAM lParam)
{
    if (HIWORD(wParam) == BN_CLICKED && LOWORD(lParam) == IDC_MYBUTTON)
    {
        m_Edit.SetWindowText(TEXT("My string"));
    }
    return CWnd::OnCommand(wParam, lParam);
}

获取并阅读一本有关 MFC 的书将会非常有帮助。这是相当基本的内容,但如果您还不了解基本概念,那么在一个答案中就需要涵盖很多内容。

使用类向导将使这变得更加容易...使用 Ctrl+W 键调用它并按照屏幕上的说明进行操作。你最终会得到类似的结果:

void CMyDialog::OnMyButton()
{
    m_Edit.SetWindowText(TEXT("My string"));
}

You can set the text of an Edit control (wrapped by the CEdit class in MFC) by calling the SetWindowText method, which it inherits from the CWnd 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's OnCommand method.

Something like:

BOOL CMyDialog::OnCommand(WPARAM wParam, LPARAM lParam)
{
    if (HIWORD(wParam) == BN_CLICKED && LOWORD(lParam) == IDC_MYBUTTON)
    {
        m_Edit.SetWindowText(TEXT("My string"));
    }
    return CWnd::OnCommand(wParam, lParam);
}

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:

void CMyDialog::OnMyButton()
{
    m_Edit.SetWindowText(TEXT("My string"));
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文