Thread: MFC: Accessing Frame window from the Document

  1. #1
    Registered User
    Join Date
    Aug 2002
    Location
    Hermosa Beach, CA
    Posts
    446

    MFC: Accessing Frame window from the Document

    What is the correct way to access the frame from the document class?

    Here is the deal: Part of the CDocument derived class changed, and as a result, I want the text in the statusbar (a member variable in the frame class) to be updated.

    And actually it seems like it should be the View class that detects that the document has changed, and then the view should update the statusbar. But either way, is there a standard way of doing this? If so, what is it?
    The crows maintain that a single crow could destroy the heavens. Doubtless this is so. But it proves nothing against the heavens, for the heavens signify simply: the impossibility of crows.

  2. #2
    Unregistered User
    Join Date
    Sep 2005
    Location
    Antarctica
    Posts
    341
    In your document class:

    Code:
    POSITION pos = GetFirstViewPosition();
    CMyView *p = (CMyView *)this->GetNextView(pos);
    CMyFrame *frame = (CMyFrame *)p->GetParentFrame();
    Remember there can be multiple views of the same document object, that's why you have to get the first view position.

  3. #3
    Registered User
    Join Date
    Aug 2002
    Location
    Hermosa Beach, CA
    Posts
    446
    Ok...that works. And now I need a philosophy lesson. Because I actually can't access the m_wndStatusBar member, because it's protected. That didn't stop me from just going over and changing it to public, but I was wondering if the writers of MFC had some other philosophy in mind here. For instance, is the document supposed to set some member variable (m_currentStatusBarText) and then is the Frame suppposed to pick up on this fact based on some windows message (maybe WM_PAINT or something)? It seems like that sort of approach would at least allow the Frame to maintain it's StatusBar as private.

    Also, I noticed that the statusbar is drawn into the client area--i.e. it isn't really part of the frame like the title bar and menu are. Given that this is the case, doesn't it make sense for the m_wndStatusBar member to be a member of the View (which is traditionally in charge of the window client area)? Or if not, then they could at least make the status bar really part of the frame...
    The crows maintain that a single crow could destroy the heavens. Doubtless this is so. But it proves nothing against the heavens, for the heavens signify simply: the impossibility of crows.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Pong is completed!!!
    By Shamino in forum Game Programming
    Replies: 11
    Last Post: 05-26-2005, 10:50 AM
  2. MFC document/view woes
    By VirtualAce in forum Windows Programming
    Replies: 4
    Last Post: 03-15-2005, 07:54 AM
  3. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 09:44 AM
  4. run a program
    By goodmonkie in forum Windows Programming
    Replies: 2
    Last Post: 10-07-2001, 11:19 AM
  5. Invoking MSWord
    By Donn in forum C Programming
    Replies: 21
    Last Post: 09-08-2001, 04:08 PM