如何从 Visual C++/MFC 中的 MainFrame 更新 DialogBar 中的编辑文本
How to update Edit Text in DialogBar from MainFrame in Visual C++/MFC
我在 Visual C++ 2015 中使用 MFC 创建了一个带有 SDI 的 C++ 应用程序。该应用程序包含一个对话框。其中包含一个编辑文本。我只想从 MainFrame 更新 Edit Text 的值。请提供解决方案
我尝试使用以下代码更新编辑文本
SetDlgItemText(IDC_EDIT1, "hi");
但不更新编辑文本中的值
考虑到您在项目资源中有对话框栏的对话框资源 ID,并且在大型机中有 CDialogBar 成员变量,将尝试对此进行解释。
您将在 int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
函数中包含以下代码。
if ( ! m_wndMyDialogBar.Create(this, IDD_DIALOGBAR, CBRS_TOP , IDD_DIALOGBAR)) //IDD_DIALOGBAR resource id of dialog bar
{
TRACE0("Failed to create dialog bar from CMyDialogBar class\n");
return -1; // fail to create
}
一旦你有了有效的对话栏对象,你就可以按照以下步骤设置 window 文本到编辑框:
m_wndMyDialogBar.GetDlgItem(IDC_EDIT1)->SetWindowText("TEXT YOU WANT"); //Where IDC_EDIT1 is id of text box present on IDD_DIALOGBAR resource.
我在 Visual C++ 2015 中使用 MFC 创建了一个带有 SDI 的 C++ 应用程序。该应用程序包含一个对话框。其中包含一个编辑文本。我只想从 MainFrame 更新 Edit Text 的值。请提供解决方案
我尝试使用以下代码更新编辑文本
SetDlgItemText(IDC_EDIT1, "hi");
但不更新编辑文本中的值
考虑到您在项目资源中有对话框栏的对话框资源 ID,并且在大型机中有 CDialogBar 成员变量,将尝试对此进行解释。
您将在 int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
函数中包含以下代码。
if ( ! m_wndMyDialogBar.Create(this, IDD_DIALOGBAR, CBRS_TOP , IDD_DIALOGBAR)) //IDD_DIALOGBAR resource id of dialog bar
{
TRACE0("Failed to create dialog bar from CMyDialogBar class\n");
return -1; // fail to create
}
一旦你有了有效的对话栏对象,你就可以按照以下步骤设置 window 文本到编辑框:
m_wndMyDialogBar.GetDlgItem(IDC_EDIT1)->SetWindowText("TEXT YOU WANT"); //Where IDC_EDIT1 is id of text box present on IDD_DIALOGBAR resource.