Solved

Dialog Bars/Tool Bars

Posted on 1998-08-10
9
328 Views
Last Modified: 2010-04-02
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?
0
Comment
Question by:jrmcg
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 
LVL 22

Expert Comment

by:nietod
ID: 1169845
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.
0
 
LVL 22

Expert Comment

by:nietod
ID: 1169846
Does that make sense?  Do you know how to cast the pointer?
0
 

Expert Comment

by:khan_yew
ID: 1169847
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.

0
Technology Partners: 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!

 
LVL 2

Author Comment

by:jrmcg
ID: 1169848
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.

Thanks
0
 
LVL 22

Expert Comment

by:nietod
ID: 1169849
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.
0
 
LVL 2

Expert Comment

by:tdubroff
ID: 1169850
How about adding variables to the dialog bar constructor which are the variables you want to update/change/examine?
0
 
LVL 2

Author Comment

by:jrmcg
ID: 1169851
Sorry it is taking so long.  Bare with me.  Today has been hectic.  I'll post the code tomorrow.  I appreciate you guys helping.

JR
0
 
LVL 1

Accepted Solution

by:
payn earned 70 total points
ID: 1169852
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.

0
 
LVL 2

Author Comment

by:jrmcg
ID: 1169853
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

m_wndDlgBar.Create(this,IDD_DIALOG_CTRL_BAR,CBRS_TOP | WS_VISIBLE,
                          IDD_DIALOG_CTRL_BAR))

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;

 
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

623 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