Solved

General MFC Structure Query

Posted on 1997-10-08
5
232 Views
Last Modified: 2013-11-20
Hi,

You guys probably hate Uni student questions, but I hate Uni, so we're even.

I'm writing an MDI app that has initally one Window open, with a splitter control across the middle. The top view is a CFormView, and the bottom is a CEditView.

Basically, someone clicks on buttons in the top (Form view) box, which fires off dialog boxes. The user then clicks on check boxes in these dialog boxes which in turn spits out text into the CEditView control. The dialog box is also preinitalised before it is displayed by looking at what is already in the CEditView type control, as a user can also directly input text into this control.

The contents of the CEditView control will be saved as it is a "script" file for something else.

My problems at the moment are numerous, not to mention a crash course in MFC and C++ over the last 2 months, but basically I need to find out:

1. How to access the CEditView object from the CFormView object, possibly something like AfxGetMainWnd->GetMDIChild->GetPane(1,0) ...

2. Currently the CFormView fires off the event to generate the dialog boxes when the user clicks on a button. Is this the correct class to handle this event? If so, how do I then add data to the CEditView from here (eg, question 1)

3. Has anyone got any example code for this?

Any help would be dearly appreciated.

Thanks

Poor Stressed University Student
0
Comment
Question by:Jori
  • 4
5 Comments
 
LVL 10

Expert Comment

by:RONSLOW
ID: 1307703
I don't hate UNI students. But I DO hate students who come here, post their assignment questions verbatim and then sit back and wait for an expert to do their work for them.

You are obviously NOT one of THOSE kind of UNI students, and I'll be happy to help if I can :-)

0
 
LVL 10

Expert Comment

by:RONSLOW
ID: 1307704
>not to mention a crash course in MFC and C++ over the last 2 months

Does that mean you have crashed, MFC has crashed or a combination of the two? :-)

0
 
LVL 10

Accepted Solution

by:
RONSLOW earned 50 total points
ID: 1307705
>1. How to access the CEditView object from the CFormView object, possibly something like AfxGetMainWnd->GetMDIChild->GetPane(1,0) ...

Whoever creates the two view should be able to get and keep pointers to them.  Where (and how) do you create the two views?

Or you can do as you suggest, but you wouldn't need ::AfxGetMainWnd, your CFormView would call GetParent() to give you the splitter window and then you can determine the other window by looking at which pane contains the CFormView and so the other pane must contain the other CEditView (or you can use your knowledge aoubt which view is in which frame.)

>2. Currently the CFormView fires off the event to generate the dialog boxes when the user clicks on a button. Is this the correct class to handle this event? If so, how do I then add data to the CEditView from here (eg, question 1)

If it is a user interface issue, and the button is part of the CFormView (sounds like it is), then I'd say "YES".

Assuming you can get access to the edit control from the form view, then you can pass a pointer to it to the dialog, and it can do the rest.

3. Has anyone got any example code for this?

Doesn't sound general enough for someone else to have this sort of code.

One thing to think about is to have the data in the document and have two views of this data - one being the form and the other the edit view.  Then, as both are views of the one document, you don't need to keep them in sync - just tell the document to update all its views whenever it changes.

0
 

Author Comment

by:Jori
ID: 1307706
Hi,

Tried what you suggested. From the FormView pane, I did

CSplitterFrame* p_Parent = (CSplitterFrame*)GetParent();
CTextView p_Script =
      (CTextView*)p_Parent->m_wndSplitter.GetPane(1,0);

When the Panes are created, they are created in the class CSplitterFrame. It calls CreateStatic for Pane(0,0) which is the CFormView, and Pane(1,0) which is the CTextView (my script).
 I am thus assuming that by calling GetParent, I should get a pointer to the CSplitterFrame class object. So then by accessing the variable m_wndSplitter I should be able to get the pane for the CTextView. NO!

I get a debug assertion failure, line 358 of winsplit.cpp, which is the GetPane function, and is a test for NULL pointer! So I'm not quite there.

Is there something obviously wrong here? Maybe I can't cast the pointers like I'm doing?

Thanks for everything so far.
0
 
LVL 10

Expert Comment

by:RONSLOW
ID: 1307707
GetParent should give you the splitter window (m_wndSliptter) NOT the frame that holds it (which wuold be the grand-parent).

Do a IsKindOf() check on GetParent before casting it - it should be of type CSplitterWnd NOT CSplitterFrame.

Remember - an unchecked cast can be a dangerous thing - there is no systax or runtime error if you cast a pointer of one type to another - a cast tells the compiler "Trust me, I'm a programmer"!!


0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
repeatSeparator  java  challenge 13 56
iSeries FTP Exit Program 8 114
not able to insert into temp table 68 150
Problem to event 3 50
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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.
This video discusses moving either the default database or any database to a new volume.

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

19 Experts available now in Live!

Get 1:1 Help Now