Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

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

MDI - CDocument get pointer to its frame class

Hi,

I just want to get a pointer to the frame class instance of my document. My frame has a splitterwnd member that I want to change the layout for from the document class, thus I need access to it. How can I get it?

Thanks
0
minnirok
Asked:
minnirok
  • 7
  • 5
  • 2
1 Solution
 
jkrCommented:
The main problem is that a CDocument can have multiple views. You could use

   POSITION pos = GetFirstViewPosition();
   while (pos != NULL)
   {
      CMyView* pView = (CMyView*)GetNextView(pos);
      pView->ChangeSplitter();
   }  
0
 
minnirokAuthor Commented:
Hi jkr,

I need to access its frame, not one of its views. There should be one and only one frame per document, right?
0
 
jkrCommented:
Well, a frame is nothing else but a special view. Or, are you thinking about the main frame? That one is accessible using 'AfxGetMainWnd()'. BTW, regarding the views: Did you mean

  POSITION pos = GetFirstViewPosition();
  while (pos != NULL)
  {
     CMyView* pView = (CMyView*)GetNextView(pos);
     CFrameWnd* = pView->GetActiveFrame();
  }  

?
0
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!

 
minnirokAuthor Commented:
Here is a diagram of my app, I am still new to the MDI framework so I may be confusing you:

CChildFrameCustom   (stores m_wndSplitter... which is what I need to access)
           |
           V
CMyDocument  (this is my doc class from which I would like to access the child frame, just above)
           |
           V
CMyView

So now from the document class, I need to get at his frame which stores m_wndSplitter so that I can rearrange the layout of the view. It isn't the main frame.

So if I read your second posting right, calling GetActiveFrame() on any of my document's views should return just what I want, the child frame right?

Thanks
0
 
Jaime OlivaresSoftware ArchitectCommented:
>Well, a frame is nothing else but a special view
I am not sure this is a good definition of a frame, since it is not derived from CView

You can implement a function like this:

CChildFrameCustom *CMyDocument::GetFrame ()
{
    POSITION pos = GetFirstViewPosition();
    if (pos) {
         return (CChildFrameCustom *) (GetNextView(pos)->GetParent());
    else
         return NULL;
}
0
 
Jaime OlivaresSoftware ArchitectCommented:
Sorry, typo, also will simplify:

CChildFrameCustom *CMyDocument::GetFrame()
{
    POSITION pos = GetFirstViewPosition();
    return pos ?(CChildFrameCustom *) (GetNextView(pos)->GetParent()) : NULL;
}
0
 
minnirokAuthor Commented:
Thanks jaime. On the reverse side of that, how would I get the document that belongs to the custom child frame? I tried this but it did not work:


    POSITION posDoc = theApp.m_pDocTemplate->GetFirstDocPosition();
    if (posDoc == NULL) {
        TRACE("Couldn't get first doc in template container!\n");
        return false;
    }

    CDatasetDoc *pDoc = (CMyDoc *) theApp.m_pDocTemplate->GetNextDoc(posDoc);
    if (pDoc == NULL) {
        TRACE("Couldn't get DOC!\n");
        return false;
    }
0
 
Jaime OlivaresSoftware ArchitectCommented:
Assuming you are evaluating from your frame object, and since you have a splitter object

CMyDoc *CChildFrameCustom::GetDocument()
{
    // specify proper row/col for your pane (view), in this example is 0,0
    return ((CMyView *)(m_YourSplitter.GetPane(0,0)))->GetDocument();
}
0
 
minnirokAuthor Commented:
Hi jaime,

Anytime I try using that code, I get a:

ASSERT_VALID fails with illegal vtable pointer.

crash, do you know what that means?
0
 
Jaime OlivaresSoftware ArchitectCommented:
I am assuming you have a splitter, and needs a valid pane coordinate pair.

you can decompose it for testing purposes:

CMyDoc *CChildFrameCustom::GetDocument()
{
    CWnd *wnd = m_YourSplitter.GetPane(0,0); // specify proper row/col for your pane
    CMyView *view = (CMyView *)wnd;
    CMyDoc *doc = view->GetDocument();
    return doc;
}

0
 
minnirokAuthor Commented:
It seems to always give that error on the first line:

CWnd *wnd = m_YourSplitter.GetPane(0,0); // specify proper row/col for your pane

I have created 16 static panes prior to this function call, starting at index 0,0, so it should not be illegal?
0
 
Jaime OlivaresSoftware ArchitectCommented:
I have never seen 16 panes in my life, but must be related.

you can try with:

CMyDoc *CChildFrameCustom::GetDocument()
{
    CMyView *view = (CMyView *)GetActiveView();
    CMyDoc *doc = view->GetDocument();
    return doc;
}

but I can't ensure you because of splitter

0
 
minnirokAuthor Commented:
Oh...the get frame function is a bit off - it was:

return pos ?(CChildFrameCustom *) (GetNextView(pos)->GetParent()) : NULL;

After I changed it to:

return pos ?(CChildFrameCustom *) (GetNextView(pos)->GetParentFrame()) : NULL;

I don't get the crazy vtable error and it seems to work ok.

Thanks jaime!
0
 
minnirokAuthor Commented:
oh yeah I actually have 64 panes and it runs fine. Its an image viewer that can show many different series of a dataset, thus the crazy # of possible panes.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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