Make these controls visible ..., 1st tab page
Return to Main

Resume :

  1. Initial sitiuation :
  2. To define the hearder row of the List control.
  3. To make the last controls added visible in the 1st tab page of the Tab control.
  4. Activate the Tab control - (IDC_TAB1) :
  5. To add a member function.
  6. To make the controls visible or invisible when the user select the corresponding tab.

Details ...

  1. Initial sitiuation :

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


    // TestVC0Dlg.cpp : implementation file
    //
    ...
    ................................................................................................................................................
    .................................................................................................................................................

    /////////////////////////////////////////////////////////////////////////////
    // CTestVC0Dlg message handlers

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

    // Add "About..." menu item to system menu.

    // IDM_ABOUTBOX must be in the system command range.
    ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
    ASSERT(IDM_ABOUTBOX < 0xF000);

    CMenu* pSysMenu = GetSystemMenu(FALSE);
    if (pSysMenu != NULL)
    {
    CString strAboutMenu;
    strAboutMenu.LoadString(IDS_ABOUTBOX);
    if (!strAboutMenu.IsEmpty())
    {
    pSysMenu->AppendMenu(MF_SEPARATOR);
    pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
    }
    }

    // Set the icon for this dialog. The framework does this automatically
    // when the application's main window is not a dialog
    SetIcon(m_hIcon, TRUE); // Set big icon
    SetIcon(m_hIcon, FALSE); // Set small icon

    //Define the header row of the List Control
    int strWidth1 = m_searchlist.GetStringWidth(_T("00000"));
    m_searchlist.InsertColumn(1, _T("Record"), LVCFMT_LEFT,2*strWidth1, 1);
    m_searchlist.InsertColumn(2, _T("Bk"), LVCFMT_LEFT, strWidth1, 1);
    m_searchlist.InsertColumn(3, _T("Title"), LVCFMT_LEFT, 4*strWidth1, 1);
    m_searchlist.InsertColumn(4, _T("Ch"), LVCFMT_LEFT, strWidth1, 1);
    m_searchlist.InsertColumn(5, _T("Verse"), LVCFMT_LEFT, 3*strWidth1/2, 1);

    //Make these controls visible - (1st tab page)
    m_searchlist.ShowWindow(SW_SHOW);
    m_edwordcontrol.ShowWindow(SW_SHOW);
    m_display.ShowWindow(SW_SHOW);
    m_statictype.ShowWindow(SW_SHOW);
    m_staticfoundcontrol.ShowWindow(SW_SHOW);

    // TODO: Add extra initialization here

    return TRUE; // return TRUE unless you set the focus to a control
    }
    ................................................................................................................................................
    .................................................................................................................................................
    ...


  2. Activate the Tab Control - IDC_TAB1 :
    1. ClassWizard, Add the member function - (object ID: IDC_TAB1).
    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_TAB1.
    5. In the Messages list, select the TCN_SELCHANGE.
    6. Click Add Function.
    7. The Add Member Function dialog box appears, click OK.
      To accept the default Member function name - OnSelchangeTab1 display(or rename it) and then click OK.
      The new item message -
      OnSelchangeTab1...... ON_IDC_TAB1:TCN_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
      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)
      //}}AFX_MSG_MAP
      END_MESSAGE_MAP()

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

      void CTestVC0Dlg::OnSelchangeTab1(NMHDR* pNMHDR, LRESULT* pResult)
      {
      // TODO: Add your control notification handler code here

      *pResult = 0;
      }
    8. ClassWizard, Edit the Code - (function OnSelchangeTab1).
    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 - OnSelchangeTab1:
      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::OnSelchangeTab1(NMHDR* pNMHDR, LRESULT* pResult)
      {
      int ntab = m_tab1.GetCurSel();
      switch(ntab)
      {
      case 0: //tab label = By Word
      {
      m_searchlist.ShowWindow(SW_SHOW);
      m_edwordcontrol.ShowWindow(SW_SHOW);
      m_display.ShowWindow(SW_SHOW);
      m_statictype.ShowWindow(SW_SHOW);
      m_staticfoundcontrol.ShowWindow(SW_SHOW);

      break;
      }
      case 1: //tab label = By address
      {
      m_searchlist.ShowWindow(SW_HIDE);
      m_edwordcontrol.ShowWindow(SW_HIDE);
      m_display.ShowWindow(SW_HIDE);
      m_statictype.ShowWindow(SW_HIDE);
      m_staticfoundcontrol.ShowWindow(SW_HIDE);
      break;
      }
      }

      // TODO: Add your control notification handler code here

      *pResult = 0;
      }
    Return to Main