Can anyone point me in the direction of a site that has a good tutorial on using Tab Controls on a MFC program?

Dani AI

Generated

— since the Hunnsoft approach got the tabs created, the simplest, safest ways to retrieve the edit-box text from a tab page into the main window (without adding a button on the page) are:

  1. Give the page a public accessor that forces DDX to pull the control value into the CString and returns it. This keeps the page’s internals encapsulated and is easy to call from the parent (property sheet or dialog):
/* in MyTabPage.h */
public:
CString GetTestString()
{
    UpdateData(TRUE);   // control -> m_strTest
    return m_strTest;
}

/* in parent (sheet/main dialog) */
CMyTabPage* p = DYNAMIC_DOWNCAST(CMyTabPage, mySheet.GetPage(0));
if (p) {
    CString s = p->GetTestString();
}
  1. Read the control text directly from the child dialog/page if a public accessor is undesired:
CString s;
m_pTabDlg1->GetDlgItemText(IDC_EDIT_TEST, s);  // works if the child dialog is created

Practical notes and cautions:

  • Always call UpdateData(TRUE) on the page before reading an associated DDX CString; otherwise the member may be stale.
  • Make sure the page/dialog objects live long enough (store them as members, not local temporaries), otherwise pointers returned by GetPage or stored m_pTabDlg1 will be invalid.
  • For immediate, real‑time updates consider sending a notification (EN_CHANGE) or a custom message from the page to the parent, or have the page call a small public method on the parent — but prefer a registered/custom message or well-defined public API to avoid tight coupling.

This mirrors the usual patterns shown in the CTAB/PropertyPage examples that pointed to, but focuses on safe access and lifetime/UpdateData details you’ll need to get correct.

Recommended Answers

All 2 Replies

Try This

Hmm I followed that one, but it wouldn't work right. I found another
So I've got my tab control. YAY! :) Next question. I have a Editbox w/ the CString variable m_strTest attached to it in the first Tab Control. The question is, how do I get said variable to the main window with out making a button in the Tab Control itself?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.