Initialize the IDD_ABOUTBOX dialog
Return to Main


Resume :

  • To add a member function.
  • To display the 1st record of the database file - KJV.mdb.

    Note:
    The 1st record stores information about this database.
  • Details ...

    1. ClassWizard, Add a member function - (object ID: IDD_ABOUTBOX).
    2. On the View menu, click ClassWizard.
      The MFC ClassWizard dialog box appears, click the Message Maps tab.
    3. In the Class name box, select the class CAboutDlg.
    4. In the Object IDs list, select the IDD_ABOUTBOX.
    5. In the Messages list, select the WM_INITDIALOG.
    6. Click Add Function.
    7. The Add Member Function dialog box appears, click OK.
      To accept the default Member function name -
      OnInitDialog display(or rename it) and then click OK.
      The new item message -
      OnInitDialog...... ON_WM_INITDIALOG appearing in the Member functions list.
      ClassWizard makes changes to TestVC0Dlg.cpp file after you’ve added the member function. Examine these changes ...

      TestVC0Dlg.cpp file
      - the new Text Code is red.

      // TestVC0Dlg.cpp : implementation file
      //

      #include "stdafx.h"
      #include "TestVC0.h"
      #include "TestVC0Dlg.h"

      #ifdef _DEBUG
      #define new DEBUG_NEW
      #undef THIS_FILE
      static char THIS_FILE[] = __FILE__;
      #endif

      /////////////////////////////////////////////////////////////////////////////
      // CAboutDlg dialog used for App About

      class CAboutDlg : public CDialog
      {
      public:
      CAboutDlg();

      // Dialog Data
      //{{AFX_DATA(CAboutDlg)
      enum { IDD = IDD_ABOUTBOX };
      CString m_edsource;
      //}}AFX_DATA

      // ClassWizard generated virtual function overrides
      //{{AFX_VIRTUAL(CAboutDlg)
      protected:
      virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
      //}}AFX_VIRTUAL

      // Implementation
      protected:
      //{{AFX_MSG(CAboutDlg)
      virtual BOOL OnInitDialog();
      //}}AFX_MSG
      DECLARE_MESSAGE_MAP()
      };

      CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
      {
      //{{AFX_DATA_INIT(CAboutDlg)
      m_edsource = _T("");
      //}}AFX_DATA_INIT
      }

      void CAboutDlg::DoDataExchange(CDataExchange* pDX)
      {
      CDialog::DoDataExchange(pDX);
      //{{AFX_DATA_MAP(CAboutDlg)
      DDX_Text(pDX, IDC_EDSOURCE, m_edsource);
      //}}AFX_DATA_MAP
      }

      BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
      //{{AFX_MSG_MAP(CAboutDlg)
      //}}AFX_MSG_MAP
      END_MESSAGE_MAP()

      /////////////////////////////////////////////////////////////////////////////
      // CTestVC0Dlg dialog
      ...................................................................................................................................................
      ...................................................................................................................................................

      ...
      BOOL CAboutDlg::OnInitDialog()
      {
      CDialog::OnInitDialog();

      // TODO: Add extra initialization here

      return TRUE; // return TRUE unless you set the focus to a control
      // EXCEPTION: OCX Property Pages should return FALSE
      }
    8. ClassWizard, Edit the Code - (function OnInitDialog).
    9. In the ClassWizard dialog box, select the Message Maps tab and in the Class Name box,
      select the class CAboutdlg.
    10. In the Member Functions list, select the function name - OnInitDialog:
      Choose Edit Code
      -or-
      Double-click the function name.
      The insertion point moves to the function in theTestVC0Dlg.cpp file. Edit the Text Code, examine these changes ...

      TestVC0Dlg.cpp file
      - the new Text Code is red.

      // TestVC0Dlg.cpp : implementation file
      //

      ...
      ...................................................................................................................................................
      ...................................................................................................................................................

      BOOL CAboutDlg::OnInitDialog()
      {
      CDialog::OnInitDialog();

      //Database and Recordset objects declaration
      CDaoDatabase* m_pDBW;
      CDaoRecordset* m_pRSW;

      m_pDBW = new CDaoDatabase;
      m_pRSW = new CDaoRecordset(m_pDBW);

      TCHAR curdir[MAX_PATH]; //MAX_PATH - Maximum length of directory

      // Get Current Directory
      GetCurrentDirectory( MAX_PATH, curdir );

      //DataBase name, KJV.mdb at the current directory
      m_pDBW->Open((CString)curdir + _T("\\KJV.mdb"));

      m_pRSW->Open(dbOpenDynaset, "SELECT * from BibleTable", 0);

      //First record of the file KJV.mdb stores information about this database
      m_pRSW->Move(0);

      m_edsource = CString(V_BSTRT(&(m_pRSW->GetFieldValue(_T("TextData")))));
      UpdateData(FALSE);

      // TODO: Add extra initialization here

      return TRUE; // return TRUE unless you set the focus to a control
      // EXCEPTION: OCX Property Pages should return FALSE
      }
    Return to Main