May 072008
 

Introduction

OnInitDialog is a special function earmarked for dialog UI related sub components to initialize. A good place to sub-class or to set properties on controls, to position controls, to set text on controls etc. Default code in OnInitDialog makes changes to system menu and to set icons.

Functions called before and after OnInitDialog

Two functions to look up would be…

  • _AfxPreInitDialog
  • _AfxPostInitDialog

As the name suggests:

  • _AfxPreInitDialog gets called before OnInitDialog is called.
  • _AfxPostInitDialog gets called after OnInitDialog is called.

What happens in _AfxPreInitDialog and _AfxPostInitDialog?

_AfxPostInitDialog centers a dialog if user hasn’t changed position of the dialog in OnInitDialog, so how is this done? _AfxPreInitDialog stores co-ordinates of the dialog before OnInitDialog was called and if these co-ordinates hasn’t changed then _AfxPostInitDialog calls CenterWindow MFC function.

All of this is taking place in AfxCallWndProc! WM_INITDIALOG is handled as a special case. Also HandleInitDialog function calls PreInitDialog and OnInitDialog functions!

So have fun looking up these functions!

Leave a Reply