Dialog Bars/Tool Bars

I created a Dialog Bar Control with the dialog editor.
It contains 3 edit boxes that are to contain integer
values.  The values are obtained from the document.
I have no problem creating the Dlg Bar in the MainFrame
and displaying it the way I want to.

The problem is in displaying the values.  I gave the edit
boxes member variables, then obtained a pointer to
the frame and in turn accessed the variables of the
dialog bar ( I thought) this didn't work.  I get a compile
error that says that my variable is not a member of
CDialogBar.  I am also going to need to be able to set
the variables in the same Dialog Bar.  Obviously what
I am doing is incorrect.  So my question is :
How can I access variables attached to the controls on
a Dialog Bar that is created on the MainFrame?
Who is Participating?

Improve company productivity with a Business Account.Sign Up

paynConnect With a Mentor Commented:
First, the short answer: I'm willing to bet your variables are in the frame, not the dialog bar. Instead of pFrame->m_dlgBar.m_editFirst, try pFrame->m_editFirst. Or just open up the mainframe's header file, or look at the class in the ClassView, and see if they're there.

To people who don't use VC/MFC this is going to sound like a silly point, but when you said "I gave the edit boxes member variables," you didn't say how you did this. If you did it yourself, your natural inclination would be to derive a class from CDialogBar and add the member variables there. If you used the Class Wizard, Wizard Bar, or Add Class context menu to create the variables, VC didn't do this; it put them in your mainframe class. If you use the wizards, they make it difficult for you to subclass from CDialogBar at all, and there's a good reason for this.

CDialogBar just wraps a control bar; it's not really a dialog window. In particular, it doesn't receive any messages. You normally fake things by handling messages, data exchange, etc. in the enclosing window. MFC tries to make this easy for you, especially if the dialog bar is inside a CMainFrame, but it can still get a bit hairy at times.

WARNING: I don't do MFC

It sounds to me like you class is derived from CDialogBar, but you have a pointer to just a CDialogBar.  You need to down cast that pointer to a pointer to your dialog bar class type.
Does that make sense?  Do you know how to cast the pointer?
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Hope that this might help:

Perphaps you could consider modeless CDialogBox instead of CDialogBar. Derive a new class that inherits from the CDialogBox or CDialogBar. Then, have the member variables of the edit boxes declared. Then, you could actually declared another CStrings variables and that you could get the value of the edit using GetWindowText and that you pass the CString in. You could have the value of the edit control through the new class that inherits the DialogBox or the DialogBar. ie

CNewClass m_dlg; // the new class that inherits from CDialogBox or CDialogBar
CEdit m_edit;         // the member variable of the edit control
CString m_string    // Containing the text inside the edit control

m_dlg.m_edit.GetWindowText(m_string);  // Getting the text.

You also could get the text inside the new Class declared. However, I have yet to do that as above. But I have done that by gettting the text inside the new Class derived.

Tell me if it works.

jrmcgAuthor Commented:
Sorry, but this control has to specifically be used as a toolbar type dialog.  This control is to be constantly displayed and updated by more than one document.  It is also going to be changed.

Todd can you give me an example of casting the pointer?  The dialog box that the dialog bar is using as a resource can't put values into the controls when the dialog initializes, either.  I can't set an initial value for the CEdit control.

There is a sample program on MSDN but all it does is demonstrate creation of different types of Control Bars.  It never actually uses them in an interactive way.

Can you post your code where you try to access the members of the dialogbar object?  Also post the code where you declare the dialogbar class.  I can probably make that work.  I don't know enough MFC to do it from scratch.
How about adding variables to the dialog bar constructor which are the variables you want to update/change/examine?
jrmcgAuthor Commented:
Sorry it is taking so long.  Bare with me.  Today has been hectic.  I'll post the code tomorrow.  I appreciate you guys helping.

jrmcgAuthor Commented:
The way I created the member variables was using the class wizard with the dialog class.  I created the Dialog with the wizard and added the variables to the dialog.

In Frame.h:
CDialogBar m_wndDlgBar;

In Frame.cpp:

// IDD_DIALOG_CTRL_BAR is ID of Dialog created with wizard


In DlgBar.h: Declaration of Dlg Class

//public variables
int m_Value

In DlgBar.cpp: Implementation of Dlg Class

// In Data Exchange
DDX_Text(pDX, IDC_EDIT_VALUE, m_Value);

I can not even put values into these boxes using the OnInitDialog() function with the dialog class.

To access these variables inside the Document class, I would obtain a pointer to the frame, then access the variables of the m_wndDlgBar.

pFrame->m_wndDlgBar.m_Value = 999;

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.