Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Flow of called methods in MFC

81 views
Skip to first unread message

ScottBright762

unread,
Sep 25, 2008, 12:19:57 PM9/25/08
to
Hi all!

Does someone know where I can find the sequence of methods that are
called when I use this Microsoft's framework?

Thanks in advance.

Joseph M. Newcomer

unread,
Sep 25, 2008, 1:17:47 PM9/25/08
to
Under what conditions? There are several thousand methods in MFC.

For startup, it calls the virtual methods CWinApp::InitInstance, CWinApp::PumpMessage and
CWinApp::ExitInstance. You can override these, but in practice you only want to override
the InitInstance and ExitInstance. After that, you need to say a lot more about what you
want to know.
joe

On Thu, 25 Sep 2008 09:19:57 -0700 (PDT), ScottBright762 <emerson...@gmail.com>
wrote:

Joseph M. Newcomer [MVP]
email: newc...@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm

ScottBright762

unread,
Sep 25, 2008, 1:25:31 PM9/25/08
to
I wanted a general view of this. Any special book, website, and so
forth.
I asked this because I was facing problems in my SDI application. When
I was creating the views I didn't know which method would be called at
first like, OnCreate, InitialUpdate, UpdateData, OnEraseBkng, ...
So I wanted to know each sequence of calls for methods that this
framework is supposed to do.

[]'s


On 25 set, 14:17, Joseph M. Newcomer <newco...@flounder.com> wrote:
> Under what conditions?  There are several thousand methods in MFC.
>
> For startup, it calls the virtual methods CWinApp::InitInstance, CWinApp::PumpMessage and
> CWinApp::ExitInstance.  You can override these, but in practice you only want to override
> the InitInstance and ExitInstance.  After that, you need to say a lot more about what you
> want to know.
>                                 joe
>

> On Thu, 25 Sep 2008 09:19:57 -0700 (PDT), ScottBright762 <emersonespin...@gmail.com>


> wrote:
>
> >Hi all!
>
> >Does someone know where I can find the sequence of methods that are
> >called when I use this Microsoft's framework?
>
> >Thanks in advance.
>
> Joseph M. Newcomer [MVP]

> email: newco...@flounder.com

Victor

unread,
Sep 25, 2008, 4:24:33 PM9/25/08
to
Did you try to insert TRACE outputs in all (or at least most of) these
overrides/methods and than analyze to sequence?

Victor

"ScottBright762" <emerson...@gmail.com> wrote in message
news:71d2734c-0cce-4ef5...@y38g2000hsy.googlegroups.com...

ScottBright762

unread,
Sep 25, 2008, 4:42:32 PM9/25/08
to
Not really! I'd appreciate to find some documentation about it.

[]'s


On 25 set, 17:24, "Victor" <nijegorodov.otp...@freenet.de> wrote:
> Did you try to insert TRACE outputs in all (or at least most of) these
> overrides/methods and than analyze to sequence?
>
> Victor
>

> "ScottBright762" <emersonespin...@gmail.com> wrote in message

Serge Wautier

unread,
Sep 25, 2008, 5:04:32 PM9/25/08
to
regarding books:

Start with "Programming Windows with MFC" by Jeff Prosise. An atypical
programming book where the author didn't fill the book with screenshots of
wizards.
http://www.amazon.com/Programming-Windows-Second-Jeff-Prosise/dp/1572316950

Then if you need more advanced stuff or deeper details: MFC Internals by
Sheperd and Wingo

http://www.amazon.com/MFC-Internals-Microsoft-Foundation-Architecture/dp/0201407213

HTH,

Serge.
http://www.apptranslator.com - Localization tool for your MFC applications


"ScottBright762" <emerson...@gmail.com> wrote in message

news:0c7ced8f-37bf-4f07...@59g2000hsb.googlegroups.com...

Joseph M. Newcomer

unread,
Sep 25, 2008, 10:53:58 PM9/25/08
to
OK, now THAT'S a specific question.

As far as a book, the long-out-of-print-but-sometimes-findable-on-the-Internet (try
Amazon's used books) "MFC Internals" by Shepherd and Wingo is probably the best reference
on how MFC works that was ever written. Chapter 7 talks about doc/view architecture, but
I don't have time to read it right now. Maybe tomorrow I'll have time.

OnCreate is called when the view is created. UpdateData is only called for a CFormView,
and that is called from the CView::OnInitialUpdate handler (which is why you typically
will want to call that as the first line of *your* OnInitialUpdate handler). My own view
is that except for database support, you never want to call UpdateData on your own.

OnInitialUpdate is called when the view is first created and attached to a document. By
that time, the document has been successfully loaded.

OnEraseBkgnd is called when the client area of the view has been invalidated. Then the
OnDraw method is called. HOWEVER, for a CScrollView or for printing, OnPrepareDC will be
called before OnDraw, and that's where you can set up the DC with the right scaling
factors for the printer or for the current scrolling position.

Note that all of these represent quite discrete situations and are in many cases unrelated
to each other. You know that by the time OnEraseBkgnd is called, for example, that you
have a window. In OnInitialUpdate, you have a view; if it is a CFormView all of the
controls are created, and if you have specified control variables for them, after the
superclass OnInitialUpdate returns all the controls are bound to their variables. For a
view, an OnUpdate call with (NULL, 0) is typically passed to the base class, which
ultimately leads to CView::OnUpdate which does an Invalidate(), but you can do something
more sophisticated, including using nonzero lHint and pHint to provide information as to
what should be invalidated, or something like that, or indicating that the controls of a
CFormView should now be reflected back into the document, or a control should be loaded
from its document value (which is not the same as UpdateData, which does it for ALL
controls)

Much more interesting is the sequence of document and view calls; for example, the
document is created, OnNewDocument is called, then--if I recall correctly--OpenDocument
and Serialize (if you don't override the CView methods). There are particular
considerations about SDI documents which have to be reused, as opposed to MDI where the
old document has been destroyed, and these *are* documented in the MSDN documentation. If
the document creates properly, you can then create the view(s) and the framework creates
the view specified by the dialog template and attaches it to the view, after which
OnInitialUpdate is called. I think this is the sequence, but I usually have to study the
documentation each time to be sure.
joe
On Thu, 25 Sep 2008 10:25:31 -0700 (PDT), ScottBright762 <emerson...@gmail.com>
wrote:

>I wanted a general view of this. Any special book, website, and so

email: newc...@flounder.com

0 new messages