Activate the Push Button - IDC_DISPLAY
Return to Main

Resume :

  1. Activate the Edit Box - (IDC_EDWORD) :
    • To add a member function.
    • The button - IDC_DISPLAY set enable, when you type a word in the Edit Box.
  2. Activate the Push Button - (IDC_DISPLAY) :
    • To add a member function.
    • To clear the List control.
    • To convert the word you specified to uppercase and lowercase characters.
    • Search operation, two types of information appear:
      1. A list of information about all records include the word you specified will appear in the List control - (each item of this list stores the order of the record corresponding and the values of Book field, Title field, Chapter field and Verse field in this record).
      2. The number of records found.

      Note:
      For more information, algoritm - activate the Push Button.

Details ...

  1. Activate the Edit Control - IDC_EDWORD :
    1. ClassWizard, Add the member function - (object ID: IDC_EDWORD).
    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_EDWORD.
    5. In the Messages list, select the EN_CHANGE.
    6. Click Add Function.
    7. The Add Member Function dialog box appears, click OK.
      To accept the default Member function name -
      OnChangeEdword display(or rename it) and then click OK.
      The new item message -
      OnChangeEdword...... ON_IDC_EDWORD:EN_CHANGE 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
      DECLARE_MESSAGE_MAP()
      void CalculValue();
      void SetButtons(BOOL bVal);
      void SetButtonsAll(BOOL bVal);
      };
      ...................................................................................................................................................
      ...................................................................................................................................................

      ...


      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_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)
      //}}AFX_MSG_MAP
      END_MESSAGE_MAP()
      ...
      ...................................................................................................................................................
      ...................................................................................................................................................

      void CTestVC0Dlg::OnChangeEdword()
      {
      // TODO: If this is a RICHEDIT control, the control will not
      // send this notification unless you override the CDialog::OnInitDialog()
      // function and call CRichEditCtrl().SetEventMask()
      // with the ENM_CHANGE flag ORed into the mask.

      // TODO: Add your control notification handler code here

      }
    8. ClassWizard, Edit the Code - (function OnChangeEdword).
    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 - OnChangeEdword:
      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::OnChangeEdword()
      {
      //set the IDC_DISPLAY button enable
      m_display.EnableWindow(TRUE);
      // TODO: If this is a RICHEDIT control, the control will not
      // send this notification unless you override the CDialog::OnInitDialog()
      // function and call CRichEditCtrl().SetEventMask()
      // with the ENM_CHANGE flag ORed into the mask.

      // TODO: Add your control notification handler code here

      }
  2. Activate the Push Button- IDC_DISPLAY :
    1. ClassWizard, Add the member function - (object ID: IDC_DISPLAY).
    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_DISPLAY.
    5. In the Messages list, select the BN_CLICKED.
    6. Click Add Function.
    7. The Add Member Function dialog box appears, click OK.
      To accept the default Member function name -
      OnDisplay display(or rename it) and then
      click OK.
      The new item message -
      OnDisplay...... ON_IDC_DISPLAY:BN_CLICKED 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
      DECLARE_MESSAGE_MAP()
      void CalculValue();
      void SetButtons(BOOL bVal);
      void SetButtonsAll(BOOL bVal);
      };
      ...................................................................................................................................................
      ...................................................................................................................................................

      ...


      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_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)
      //}}AFX_MSG_MAP
      END_MESSAGE_MAP()

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

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

      }
    8. ClassWizard, Edit the Code - (function OnDisplay).
    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 - OnDisplay:
      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"

      #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
      {
      (............)
      };

      CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
      {
      (............)
      }

      void CAboutDlg::DoDataExchange(CDataExchange* pDX)
      {
      (............)
      }

      BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
      //{{AFX_MSG_MAP(CAboutDlg)
      // No message handlers
      //}}AFX_MSG_MAP
      END_MESSAGE_MAP()

      /////////////////////////////////////////////////////////////////////////////
      // CTestVC0Dlg dialog

      CTestVC0Dlg::CTestVC0Dlg(CWnd* pParent /*=NULL*/)
      : CDialog(CTestVC0Dlg::IDD, pParent)
      {
      //{{AFX_DATA_INIT(CTestVC0Dlg)
      m_book = _T("");
      m_chapter = _T("");
      m_title = _T("");
      m_verse = _T("");
      m_textdata = _T("");
      m_edword = _T("");
      m_staticfound = _T("");
      //}}AFX_DATA_INIT
      // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
      m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
      m_pDB = NULL;
      m_pRS = NULL;
      m_pRSW0 = NULL;
      }

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


      void CTestVC0Dlg::OnDisplay()

      {
      CString vrecordno, vtextdata, vbook, vtitle, vchapter, vverse;
      CString upperword,lowerword, leftword, rightword, ulword;
      long recordno;
      char chrrecno[40];
      int nNewItem, i, j;
      COleVariant var;

      //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);

      //Set the IDC_DISPLAY button disable
      m_display.EnableWindow(FALSE);

      UpdateData(TRUE);

      //Clear the list control
      m_searchlist.DeleteAllItems();
      m_staticfound = "";

      //Uppercase style
      upperword = m_edword;
      upperword.MakeUpper();

      //Lowercase style
      lowerword = m_edword;
      lowerword.MakeLower();

      //Uppercase + lowercase style
      leftword = m_edword.Left(1);
      rightword = m_edword.Right(m_edword.GetLength() - 1);
      leftword.MakeUpper();
      rightword.MakeLower();
      ulword = leftword + rightword;

      i = 0;
      m_pRSW0->Move(2);

      //Max items to found = 4999
      while (!m_pRSW0->IsEOF() && i < 5000)
      {
      //Value of TextData field
      var = m_pRSW0->GetFieldValue(_T("TextData"));
      vtextdata = CString(V_BSTRT(&var));

      //Search condition
      if ((vtextdata.Find(upperword) != -1) || (vtextdata.Find(lowerword) != -1) || (vtextdata.Find(ulword) != -1))

      {
      //Absolute position of record
      recordno = m_pRSW0->GetAbsolutePosition();

      //convert long to string, data types
      ltoa(recordno,chrrecno,10);
      vrecordno = CString(chrrecno);

      //Value of Book field
      var = m_pRSW0->GetFieldValue(_T("Book"));
      vbook = CString(V_BSTRT(&var));

      //Value of Title field
      var = m_pRSW0->GetFieldValue(_T("BookTitle"));
      vtitle = CString(V_BSTRT(&var));

      //Value of Chapter field
      var = m_pRSW0->GetFieldValue(_T("Chapter"));
      vchapter = CString(V_BSTRT(&var));

      //Value of Verse field
      var = m_pRSW0->GetFieldValue(_T("Verse"));
      vverse = CString(V_BSTRT(&var));

      //Insert item to the List control
      nNewItem = m_searchlist.InsertItem(i,vrecordno,1);
      m_searchlist.SetItem(nNewItem,1,LVIF_TEXT,vbook,0,0,0,0);
      m_searchlist.SetItem(nNewItem,2,LVIF_TEXT,vtitle,0,0,0,0);
      m_searchlist.SetItem(nNewItem,3,LVIF_TEXT,vchapter,0,0,0,0);
      m_searchlist.SetItem(nNewItem,4,LVIF_TEXT,vverse,0,0,0,0);

      i = i + 1;
      j = i - 1;
      }
      m_pRSW0->MoveNext();

      }

      /Information about the items found
      if (i == 0)
      m_staticfound = "0 item found.";
      else
      {
      itoa(j+1 ,chrrecno,10);
      if (j >= 4999)
      m_staticfound = "More then " + (CString)chrrecno + " items found.";
      else
      m_staticfound = (CString)chrrecno + " items found. ";
      }

      UpdateData(FALSE);

      // TODO: Add your control notification handler code here

      }


      Note:
      To construct a CDaoRecordset object.
      Examine these changes to TestVC0Dlg.h file
      - the new Text Code is red.

      // TestVC0Dlg.h : header file
      //

      #if !defined(AFX_TESTVC0DLG_H__073CEC4B_1920_11D7_BFCA_87C57485DA49__INCLUDED_)
      #define AFX_TESTVC0DLG_H__073CEC4B_1920_11D7_BFCA_87C57485DA49__INCLUDED_

      #if _MSC_VER > 1000
      #pragma once
      #endif // _MSC_VER > 1000

      /////////////////////////////////////////////////////////////////////////////
      // CTestVC0Dlg dialog

      class CTestVC0Dlg : public CDialog
      {
      // Construction
      public:
      CTestVC0Dlg(CWnd* pParent = NULL); // standard constructor

      // Dialog Data
      //{{AFX_DATA(CTestVC0Dlg)
      enum { IDD = IDD_TESTVC0_DIALOG };
      CStatic m_statictype;
      CStatic m_staticfoundcontrol;
      CListCtrl m_searchlist;
      CEdit m_edwordcontrol;
      CButton m_display;
      CTabCtrl m_tab1;
      CString m_book;
      CString m_chapter;
      CString m_title;
      CString m_verse;
      CString m_textdata;
      CString m_edword;
      CString m_staticfound;
      //}}AFX_DATA

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

      // Implementation
      protected:
      HICON m_hIcon;
      CDaoDatabase* m_pDB;
      CDaoRecordset* m_pRS;
      CDaoRecordset* m_pRSW0;
      ...
      ...................................................................................................................................................
      ...................................................................................................................................................
    Return to Main