Solved

Dialog Bars/Tool Bars

Posted on 1998-08-10
9
322 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
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
 
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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
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 viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

706 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

20 Experts available now in Live!

Get 1:1 Help Now