[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 773
  • Last Modified:

CDialogBar, how to interact with member variables & controls

Hello,
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.

Regards
Saqib
0
jhapak
Asked:
jhapak
  • 3
  • 2
1 Solution
 
AlexFMCommented:
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,
       CBRS_LEFT|CBRS_TOOLTIPS|CBRS_FLYBY, 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);
}
0
 
jhapakAuthor Commented:
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.
0
 
AlexFMCommented:
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"));
0
 
jhapakAuthor Commented:
oh man!, I am doing same. But the error is:
'AfxGetMainFrame' : undeclared identifier
0
 
jhapakAuthor Commented:
thanks, it worked!
use AfxGetMainWnd instead of AfxGetMainFrame
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now