Activate the Combo Box - IDC_COMBOBOOK
Return to Main

Resume :

Details ...

  1. ClassWizard, Add the member function - (object ID: IDC_COMBOBOOK ).
  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 CTestVC0Dlg.
  4. In the Object IDs list, select the IDC_COMBOBOOK.
  5. In the Messages list, select the CBN_SELCHANGE.
  6. Click Add Function.
  7. The Add Member Function dialog box appears, click OK.
    To accept the default Member function name -
    OnClickSearchlist display(or rename it) and then click OK.
    The new item message - OnSelchangeComboBook
    ...... ON_IDC_COMBOBOOK:CBN_SELCHANGE appearing in the Member functions list.
    ClassWizard makes changes to TestVC0Dlg.h and TestVC0Dlg.cpp files after you’ve added the member function. Examine these changes ...

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

    // TestVC0Dlg.h : header file
    //
    ...
    ...................................................................................................................................................
    ...................................................................................................................................................

    // Generated message map functions
    //{{AFX_MSG(CTestVC0Dlg)
    virtual BOOL OnInitDialog();
    afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
    afx_msg void OnPaint();
    afx_msg HCURSOR OnQueryDragIcon();
    afx_msg void OnRecordFirst();
    afx_msg void OnRecordPrev();
    afx_msg void OnRecordNext();
    afx_msg void OnRecordLast();
    afx_msg void OnAbout();
    afx_msg void OnSelchangeTab1(NMHDR* pNMHDR, LRESULT* pResult);
    afx_msg void OnChangeEdword();
    afx_msg void OnDisplay();
    afx_msg void OnClickSearchlist(NMHDR* pNMHDR, LRESULT* pResult);
    afx_msg void OnSelchangeComboBook();
    //}}AFX_MSG
    DECLARE_MESSAGE_MAP()
    void CalculValue();
    void SetButtons(BOOL bVal);
    void SetButtonsAll(BOOL bVal);
    void SetSituation();
    };
    ...................................................................................................................................................
    ...................................................................................................................................................

    ...


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

    // TestVC0Dlg.cpp : implementation file
    //

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

    void CTestVC0Dlg::DoDataExchange(CDataExchange* pDX)
    {
    CDialog::DoDataExchange(pDX);
    //{{AFX_DATA_MAP(CTestVC0Dlg)
    DDX_Control(pDX, IDC_COMBO_TITLE, m_combotitle);
    DDX_Control(pDX, IDC_COMBO_CHAPTER, m_combochapter);
    DDX_Control(pDX, IDC_STATICVERSE, m_staticverse);
    DDX_Control(pDX, IDC_STATICTITLE, m_statictitle);
    DDX_Control(pDX, IDC_STATICSEL, m_staticsel);
    DDX_Control(pDX, IDC_STATICCHAPTER, m_staticchapter);
    DDX_Control(pDX, IDC_STATICBOOK, m_staticbook);
    DDX_Control(pDX, IDC_COMBO_VERSE_RECNO, m_comboverserecno);
    DDX_Control(pDX, IDC_COMBO_VERSE, m_comboverse);
    DDX_Control(pDX, IDC_COMBO_TITLE_RECNO, m_combotitlerecno);
    DDX_Control(pDX, IDC_COMBO_CHAPTER_RECNO, m_combochapterrecno);
    DDX_Control(pDX, IDC_COMBO_BOOK_RECNO, m_combobookrecno);
    DDX_Control(pDX, IDC_COMBO_BOOK, m_combobook);
    DDX_Control(pDX, IDC_STATICTYPE, m_statictype);
    DDX_Control(pDX, IDC_STATICFOUND, m_staticfoundcontrol);
    DDX_Control(pDX, IDC_SEARCHLIST, m_searchlist);
    DDX_Control(pDX, IDC_EDWORD, m_edwordcontrol);
    DDX_Control(pDX, IDC_DISPLAY, m_display);
    DDX_Control(pDX, IDC_TAB1, m_tab1);
    DDX_Text(pDX, IDC_BOOK, m_book);
    DDX_Text(pDX, IDC_CHAPTER, m_chapter);
    DDX_Text(pDX, IDC_TITLE, m_title);
    DDX_Text(pDX, IDC_VERSE, m_verse);
    DDX_Text(pDX, IDC_TEXTDATA, m_textdata);
    DDX_Text(pDX, IDC_EDWORD, m_edword);
    DDX_Text(pDX, IDC_STATICFOUND, m_staticfound);
    //}}AFX_DATA_MAP
    }

    BEGIN_MESSAGE_MAP(CTestVC0Dlg, CDialog)
    //{{AFX_MSG_MAP(CTestVC0Dlg)
    ON_WM_SYSCOMMAND()
    ON_WM_PAINT()
    ON_WM_QUERYDRAGICON()
    ON_BN_CLICKED(IDC_RECORD_FIRST, OnRecordFirst)
    ON_BN_CLICKED(IDC_RECORD_PREV, OnRecordPrev)
    ON_BN_CLICKED(IDC_RECORD_NEXT, OnRecordNext)
    ON_BN_CLICKED(IDC_RECORD_LAST, OnRecordLast)
    ON_BN_CLICKED(IDC_ABOUT, OnAbout)
    ON_NOTIFY(TCN_SELCHANGE, IDC_TAB1, OnSelchangeTab1)
    ON_EN_CHANGE(IDC_EDWORD, OnChangeEdword)
    ON_BN_CLICKED(IDC_DISPLAY, OnDisplay)
    ON_NOTIFY(NM_CLICK, IDC_SEARCHLIST, OnClickSearchlist)
    ON_CBN_SELCHANGE(IDC_COMBO_BOOK, OnSelchangeComboBook)
    //}}AFX_MSG_MAP
    END_MESSAGE_MAP()
    ...
    ...................................................................................................................................................
    ...................................................................................................................................................

    void CTestVC0Dlg::OnSelchangeComboBook()
    {
    // TODO: Add your control notification handler code here

    }
  8. ClassWizard, Edit the Code - (function OnSelchangeComboBook).
  9. In the ClassWizard dialog box, select the Message Maps tab and in the Class Name box,
    select the class CTestVC0Dlg.
  10. In the Member Functions list, select the function name - OnSelchangeComboBook:
    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
    //

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

    void CTestVC0Dlg::OnSelchangeComboBook()
    {
    CString varcombo;
    CString vcombbook1, vcombchapter1;
    long varrecno;

    //Record corresponding to the item selected of the book conbobox
    m_pRS->MoveFirst();

    m_combobookrecno.SetCurSel(m_combobook.GetCurSel());
    m_combobookrecno.GetLBText(m_combobookrecno.GetCurSel(),varcombo);
    varrecno = atol(varcombo.GetBuffer(80));
    m_pRS->Move(varrecno);
    CalculValue();
    SetSituation();

    //In the current string of the title combobox displays the title of the book
    m_combotitle.SetCurSel(m_combobook.GetCurSel());

    //Recordset declaration
    if (m_pRSW0)
    if (m_pRSW0->IsOpen())
    m_pRSW0->Close();

    delete m_pRSW0;

    m_pRSW0 = new CDaoRecordset(m_pDB);
    m_pRSW0->Open(dbOpenDynaset, "SELECT * from BibleTable", 0);

    //Clear the coomboboxes
    m_combochapter.ResetContent();
    m_combochapterrecno.ResetContent();
    m_comboverse.ResetContent();
    m_comboverserecno.ResetContent();

    //Chapter combobox stores all chapters orders of the book
    //Verse combobox stores all verses orders of the 1st chapter of this book
    m_combobook.GetLBText(m_combobook.GetCurSel(),vcombbook1);

    m_pRSW0->Move(varrecno);

    m_pRSW0->GetFieldValue(_T("Chapter"), varchapter0);

    while (!m_pRSW0->IsEOF())
    {
    m_pRSW0->GetFieldValue(_T("Book"), varbook0);
    m_pRSW0->GetFieldValue(_T("Chapter"), varchapter1);
    m_pRSW0->GetFieldValue(_T("Verse"), varverse1);

    pos = m_pRSW0->GetAbsolutePosition();
    ltoa(pos,chrrecno,10);

    if (CString(V_BSTRT(&varbook0)) == vcombbook1)
    {
    if (CString(V_BSTRT(&varchapter1)) == "001")
    {
    if (CString(V_BSTRT(&varverse1)) == "001")
    {
    m_combochapter.AddString(CString(V_BSTRT(&varchapter1)));
    m_comboverse.AddString(CString(V_BSTRT(&varverse1)));

    m_combochapterrecno.AddString(CString(chrrecno));
    m_comboverserecno.AddString(CString(chrrecno));

    }
    else
    {
    m_comboverse.AddString(CString(V_BSTRT(&varverse1)));
    m_comboverserecno.AddString(CString(chrrecno));
    }
    }
    else
    {
    //Unique chapters orders
    if (CString(V_BSTRT(&varchapter0)) != CString(V_BSTRT(&varchapter1)))
    {
    m_combochapter.AddString(CString(V_BSTRT(&varchapter1)));

    m_combochapterrecno.AddString(CString(chrrecno));
    varchapter0 = varchapter1;
    }
    }
    }
    m_pRSW0->MoveNext();
    }

    //In the current string of the chapter coombobox displays the 1st chapter order of the book
    //In the current string of the verse coombobox displays the 1st verse order of the 1st chapter
    m_combochapter.SetCurSel(0);
    m_comboverse.SetCurSel(0);

    UpdateData(FALSE);

    // TODO: Add your control notification handler code here

    }
    void CTestVC0Dlg::SetSituation()
    {
    CString vcombbook,vcombtitle;
    CString vcombchapter,vcombverse;

    m_combobook.GetLBText(m_combobook.GetCurSel(),vcombbook);
    m_combotitle.GetLBText(m_combotitle.GetCurSel(),vcombtitle);
    m_combochapter.GetLBText(m_combochapter.GetCurSel(),vcombchapter);
    m_comboverse.GetLBText(m_comboverse.GetCurSel(),vcombverse);

    //The 2nd record data ...
    if (vcombbook == _T("01") && vcombchapter == _T("001") && vcombverse == _T("001"))
    SetButtons(TRUE);
    else
    {
    //The last record data ...
    if (vcombbook == _T("66") && vcombchapter == _T("022") && vcombverse == _T("021"))
    SetButtons(FALSE);
    else
    SetButtonsAll(TRUE);
    }
    }
Return to Main