CDialogBar, how to interact with member variables & controls

Posted on 2004-11-21
Last Modified: 2013-11-20
I have created a CDialogBar, there are some controls on it. Lets say one edit box and one list box. These controls can interact with from the CMainFrame class. But the question is: It is an MDI Application. I need to set value of edit box and list box in the CDialogBar through the View class. In detail:

1. I have a CDialogBar
2. I can interact through CMainFrame.
3. But I want to interact (set and retreive) values from CDlgView class.

Is there any way.

Question by:jhapak
    LVL 48

    Expert Comment

    Check out MFC sample CTRLBARS.
    All messages from CDialogBar controls are sent to dialog bar parent and not to dialog bar itself. Usually program doesn't contain CDialogBar-derived class, instead of this all controls are managed in the parent form.

    See the following code fragments from CTRLBARS sample:

    CDialogBar  m_wndDlgBar;

    int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
        if (!m_wndDlgBar.Create(this, IDD_VIEWSELECT,

    void CMainFrame::OnUpdatePalette(CCmdUI* pCmdUI)
        CComboBox* pCBox = (CComboBox*)m_wndDlgBar.GetDlgItem(IDC_PALETTE);    // talk with combobox on the dialog bar
        UINT nIndex = pCBox->GetCurSel();
        pCmdUI->SetCheck((UINT)(ID_PALETTE_BASE + nIndex) == pCmdUI->m_nID);
    LVL 1

    Author Comment

    I still can't understand it properly. Actually the thing is, I have a document in MDI, when I click in the document, the list box in CDialogBar must also update itself.
    LVL 48

    Accepted Solution

    Read the sample. Messages from all controls placed on CDialogBar are handled in CMainFrame. For example, if you want to add UPDATE_UI message handler for some control in the dialog bar, add this message handler to CMainFrame. If you want to handle button click, add this handler to CMainFrame.
    If you want to access some control and change it's state, do this from CMainFrame. For example, you want to set text in IDC_EDIT1 edit box on CDialogBar. Let's say that CMainnFrame class has public member CDialogBar  m_wndDlgBar. You can add this code to any class:

    CMainFrame* pFrame = (CMainFrame*)AfxGetMainFrame();
    CEdit* pEdit = (CEdit*)pFrame->m_wndDlgBar.GetDlgItem(IDC_EDIT1);    
    pEdit->SetWindowText(_T("New text"));
    LVL 1

    Author Comment

    oh man!, I am doing same. But the error is:
    'AfxGetMainFrame' : undeclared identifier
    LVL 1

    Author Comment

    thanks, it worked!
    use AfxGetMainWnd instead of AfxGetMainFrame

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    Suggested Solutions

    Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
    If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
    This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    9 Experts available now in Live!

    Get 1:1 Help Now