C++
BOOL AutoLoad();
Description
This method is intended to initialize the control following creation or subclassing, usually based on defaults set in the constructor. The method is declared virtual for use by derived classes. If you override this method, you are encouraged to call the inherited method from your routine.
The default routine applies the control's current Drag & Drop and PointedAt Effects enable settings.
Note that the button's window should have been created and subclassed prior to calling AutoLoad(). It's easiest to use Dynamic Data Exchange in a dialog to subclass the control and call the button's AutoLoad from the dialog's OnInitDialog(), after the dialog's base class OnInitDialog() has been called. The following example illustrates this.
Returns TRUE if initialization is successful, FALSE otherwise.
Example:
In a dialog class derived from CAdUiDialog add a member for the button. Ensure DoDataExchange() and OnInitDialog() are declared.
class CMyDialog : public CAdUiDialog { public: //{{AFX_DATA(CMyDialog) ... CAdUiOwnerDrawButton m_myButton; //}}AFX_DATA //{{AFX_VIRTUAL(CMyDialog) protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support //}}AFX_VIRTUAL protected: //{{AFX_MSG(CMyDialog) virtual BOOL OnInitDialog(); //}}AFX_MSG DECLARE_MESSAGE_MAP() };
Provide a message map:
BEGIN_MESSAGE_MAP(CMyDialog, CAdUiDialog) //{{AFX_MSG_MAP(CMyDialog) ... //}}AFX_MSG_MAP END_MESSAGE_MAP()
Use DDX_Control to subclass the button in DoDataExchange:
void CMyDialog::DoDataExchange(CDataExchange* pDX) { CAdUiDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CMyDialog) ... DDX_Control(pDX, ID_MYBUTTON, m_myButton); //}}AFX_DATA_MAP }
In OnInitDialog() auto-load the button after the controls have been created. Normally, this would occur after a call to the inherited OnInitDialog().
BOOL CMyDialog::OnInitDialog() { CAdUiDialog::OnInitDialog(); // Initialize the button. m_myButton.AutoLoad(); // Finish initialization normally. return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE }