|
The designs
1. |
IDD_KJV_VCNET_DIALOG
|
2. |
IDD_ABOUTBOX
|
1. |
Add
Database and Picture Files
- From the CD-Rom -
Teach_VNet, copy the database file
KJV2002.mdb
(\\C_Col_VC++Net\KJV_VCNet\res\KJV2002.mdb) to the
folder - c:\KJV_VCNet\res
- From the CD-Rom -
Teach_VNet, copy the bmp files
ingraphic1.bmp and About.bmp
(\\C_Col_VC++Net\KJV_VCNet\res\ingraphic1.bmp) to the
folder - c:\KJV_VCNet\res
- On the
Projet menu , click Add Resource, Add
Resource dialog box
appears, select Bitmap, click Import,
Import dialog box appears, select the file ingraphic1.bmp of the folder c:\KJV_VCNet\res,
and then click Open. New
item - IDB_BITMAP1 added to the Bitmap folder
of Resource View.
- On the
Projet menu , click Add Resource, Add
Resource dialog box
appears, select Bitmap, click Import,
Import dialog box appears, select the file
About.bmp of the folder c:\KJV_VCNet\res,
and then click Open. New
item - IDB_BITMAP2 added to the Bitmap folder
of Resource View
|
2. |
Create
the menu - IDR_MENU
- On the Project menu , click
Add Resource, The Add Resource dialog box
appears.
- In this
dialog, select Menu
and click New
- In the
Resource View -
KJV_VCNet display the Folder Menu.
- Use the Editor Menu to add
items to the menu
IDR_MENU
The IDR_MENU design
The Properties ...
Caption
|
ID |
Propmt |
Separator |
Info Menu
Book
-
About
-
Exit |
ID_INFOMENU_BOOK
ID_INFOMENU_ABOUT
ID_INFOMENU_EXIT |
Display the Book Dialog
Display the About Dialog
Quit the application |
False
True
False
True
False |
|
|
|
|
1. |
IDD_KJV_VCNET_DIALOG
1. |
The Dialog
design
|
2. |
The Dialog
Properties
Caption: Center: ID: Menu:
Maximize Box: |
KJV_VCNet Application True
IDD_KJV_VCNET_DIALOG
IDR_MENU
False |
|
|
3. |
From the
Toolbox/Dialog Editor add the following control to
IDD_KJV_VCNET_DIALOG
One Text control and one Picture control
The controls Properties
- Picture control
ID:
Image:
Type: |
IDC_STATIC
IDB_BITMAP1
Bitmap |
|
IDB_BITMAP1 = bmp file - ingraphic1.bmp
- Text
control
Align Text:
Caption:
ID: |
Center
Learn how to write ...
IDC_STATIC |
|
|
|
4. |
no Variables
to be added ...
|
5. |
Add Events
- On the View menu , click
Resource View, The Resource View - KJV_VCNet dialog box
appears.
- In this
dialog, expand KJV_VCNet , expand Menu folder,
click
IDR_MENU
- The
IDR_MENU
displays select the following items menu
and the coresponding Event Handler
- Select and right click
the item Menu - Book, select Add Event Handler
on the shortcut menu, the Event Handler wizard - KJV_VCNet dialog
box appears.
In this dialog, select....
- In the Message type
pane , select
COMMAND
- In the
Class list pane , select
CKJV_VCNetDlg
- In the
Function name box display OnIfomenuBook
-
Clik Add and Edit, new text codes to be added to the
files:
- In the
KJV_VCNetDlg.h
afx_msg
void
OnInfomenuBook(); -
In the KJV_VCNetDlg.cpp
ON_COMMAND(ID_INFOMENU_BOOK, OnInfomenuBook)
void
CKJV_VCNetApp::OnInfomenuBook()
{
// TODO: Add your command
handler code here
}
|
|
- Select and
right click the item Menu - About, select Add
Event Handler on the shortcut menu, the Event Handler
wizard - KJV_VCNet dialog box appears, in this dialog
....
- In the Message type
pane , select
COMMAND
- In the
Class list pane , select
CKJV_VCNetDlg
- In the
Function name box display OnIfomenuAbout
-
Clik Add and Edit, new text codes to be added to the
files:
- In the
KJV_VCNetDlg.h
afx_msg
void
OnInfomenuAbout(); -
In the KJV_VCNetDlg.cpp
ON_COMMAND(ID_INFOMENU_ABOUT, OnInfomenuAbout)
void
CKJV_VCNetApp::OnInfomenuAbout()
{
// TODO: Add your command
handler code here
}
|
|
- Select and
right click the item Menu - Exit, select Add
Event Handler on the shortcut menu, the Event Handler
wizard - KJV_VCNet dialog
box appears, in this dialog ....
- In the Message type
pane , select
COMMAND
- In the
Class list pane , select
CKJV_VCNetDlg
- In the
Function name box display OnIfomenuExit
-
Clik Add and Edit, new text codes to be added to the
files:
- In the
KJV_VCNetDlg.h
afx_msg
void
OnInfomenuExit(); -
In the KJV_VCNetDlg.cpp
ON_COMMAND(ID_INFOMENU_EXIT, OnInfomenuExit)
void
CKJV_VCNetApp::OnInfomenuExit()
{
// TODO: Add your command
handler code here
}
|
|
|
|
|
2. |
IDD_ABOUTBOX
1. |
The Dialog
design
This software use the
command -
GetCurrentDirectory (to get
the name of the current directory)
In this Form used the following database classes -
CDaoDatabase and CDaoRecordset
In the file stdafx.h add the
MFC database
support - afxdao.h |
2. |
The Dialog
Properties
Caption: Center: ID: Menu:
Maximize Box: |
About ... True
IDD_ABOTDLG
False |
|
|
3. |
From the
Toolbox/Dialog Editor add the following control to
IDD_KJV_VCNET_DIALOG
Two Text controls, one Picture control, one Edit
control and two Button control
The controls Properties
- Text controls
1. |
Align Text:
Caption:
ID: |
Left
About application
IDC_STATIC |
|
|
2. |
Align Text:
Caption:
ID: |
Left
Copyright (c) 2004
IDC_STATIC |
|
|
- Picture
control
ID:
Image:
Type: |
IDC_STATIC
IDB_BITMAP2
Bitmap |
|
IDB_BITMAP2 = bmp file - About.bmp
- Edit
control
Align Text:
ID:
MultLine |
Left
IDC_EDIT1
True |
|
- Button
control
Caption:
ID: |
Created by
IDC_BUTTON1 |
|
|
4. |
Add
Variables ...
- On the View menu , click
Resource View, in the Resource View - KJV_VCNet dialog
box appears, expand KJV_VCNet , expand Dialog
folder and click
IDD_ABOUTBOX
- Select
and right click the Edit control - IDC_EDIT1,
select Add variable ... on the
shortcut menu, the Add Member Variable Wizard - KJV_VCNet dialog box
appears.
In this
dialog ...
- In the Control ID
box , display
IDC_EDIT1
- In the
Control type box , display
Edit
- In the
Category box, select Value
- In the
Variable name box, type m_edit1
-
Click Finish. new
text codes to be added to the file - KJV_VCNetDlg.cpp
The codes ...
CString
m_edit1;
m_edit1(_T(""))
DDX_Text(pDX, IDC_EDIT1, m_edit1); |
|
|
5. |
Add Events
- On the View menu , click
Resource View, in the Resource View - KJV_VCNet dialog
box appears, expand KJV_VCNet , expand Dialog
folder and click
IDD_ABOUTBOX
- In the
IDD_ABOUTBOX dialog
displays, select and right click the
Button Created by, select Properties on the
shortcut menu, in the Properties dialog box appears, click
Control Events icon, from the dialog box appears
select BN_CLICKED and add event OnBnClickedButton1.
New text codes to be created in the
file :KJV_VCNetDlg.cpp
afx_msg
void
OnBnClickedButton1();
ON_BN_CLICKED(IDC_BUTTON1, OnBnClickedButton1)
void CAboutDlg::OnBnClickedButton1()
{
// TODO: Add your command
handler code here
} |
|
|
|
|
1.
2.
|
stdafx.h
The color of
the new text codes added is Red
//
stdafx.h : include file for standard system include files,
// or project specific include files that are used
frequently,
// but are changed infrequently
#pragma
once
#ifndef VC_EXTRALEAN
#define VC_EXTRALEAN
// Exclude rarely-used
stuff from Windows headers
#endif
// Modify the following defines if you have to target a
platform prior to the ones specified below.
// Refer to MSDN for the latest info on corresponding
values for different platforms.
#ifndef WINVER
// Allow use of features
specific to Windows 95 and Windows NT 4 or later.
#define WINVER 0x0400
// Change this to the
appropriate value to target Windows 98 and Windows 2000 or
later.
#endif
#ifndef _WIN32_WINNT
// Allow use of features
specific to Windows NT 4 or later.
#define _WIN32_WINNT 0x0400
// Change this to
the appropriate value to target Windows 98 and Windows
2000 or later.
#endif
#ifndef _WIN32_WINDOWS
// Allow use of features
specific to Windows 98 or later.
#define _WIN32_WINDOWS 0x0410
// Change this to
the appropriate value to target Windows Me or later.
#endif
#ifndef _WIN32_IE
// Allow use of features
specific to IE 4.0 or later.
#define _WIN32_IE 0x0400
// Change this to the
appropriate value to target IE 5.0 or later.
#endif
#define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS
// some CString
constructors will be explicit
// turns off MFC's hiding of some common and often
safely ignored warning messages
#define _AFX_ALL_WARNINGS
#include <afxwin.h>
// MFC core and standard
components
#include <afxext.h>
// MFC extensions
#include <afxdisp.h>
// MFC Automation classes
#include <afxdtctl.h>
// MFC support for Internet
Explorer 4 Common Controls
#include <afxdao.h>
// MFC database support
#ifndef _AFX_NO_AFXCMN_SUPPORT
#include <afxcmn.h>
// MFC support for Windows
Common Controls
#endif
// _AFX_NO_AFXCMN_SUPPORT |
KJV_VCNetDlg.h
The color of
the new text codes added is Red
//
KJV_VCNetDlg.h : header file //
#pragma
once
// CKJV_VCNetDlg dialog
class CKJV_VCNetDlg :
public
CDialog
{
// Construction
public :
CKJV_VCNetDlg(CWnd* pParent = NULL);
// standard constructor
// Dialog Data
enum
{ IDD = IDD_KJV_VCNET_DIALOG };
protected:
virtual
void
DoDataExchange(CDataExchange* pDX);
// DDX/DDV support
// Implementation
protected :
HICON m_hIcon;
// Generated
message map functions
virtual
BOOL OnInitDialog();
afx_msg void
OnSysCommand(UINT nID, LPARAM lParam);
afx_msg void
OnPaint();
afx_msg HCURSOR OnQueryDragIcon();
DECLARE_MESSAGE_MAP()
public :
afx_msg
void
OnInfomenuAbout();
afx_msg
void
OnInfomenuExit();
afx_msg
void
OnInfomenuBook();
}; |
|
3. |
KJV_VCNetDlg.cpp
The color of
the new text codes added is Red
//
KJV_VCNetDlg.cpp : implementation file //
#pragma
once
#include "stdafx.h"
#include "KJV_VCNet.h"
#include "KJV_VCNetDlg.h"
#include ".\kjv_vcnetdlg.h"
#include "Book.h"
#include "afxwin.h"
#include "Biography.h"
#ifdef _DEBUG
#define
new
DEBUG_NEW
#endif
// CAboutDlg dialog used for App About
class CAboutDlg :
public
CDialog
{
public :
CAboutDlg();
// Dialog Data
enum
{ IDD = IDD_ABOUTBOX };
protected:
virtual
void
DoDataExchange(CDataExchange* pDX);
// DDX/DDV support
// Implementation
protected :
DECLARE_MESSAGE_MAP()
public :
CString m_edit1;
virtual
BOOL OnInitDialog();
afx_msg void
OnBnClickedButton1();
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
, m_edit1(_T(""))
{
}
void
CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Text(pDX, IDC_EDIT1,
m_edit1);
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
ON_BN_CLICKED(IDC_BUTTON1,
OnBnClickedButton1)
END_MESSAGE_MAP()
// CKJV_VCNetDlg dialog
CKJV_VCNetDlg::CKJV_VCNetDlg(CWnd* pParent
/*=NULL*/)
: CDialog(CKJV_VCNetDlg::IDD, pParent)
{
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void
CKJV_VCNetDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(CKJV_VCNetDlg, CDialog)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
//}}AFX_MSG_MAP
ON_COMMAND(ID_INFOMENU_ABOUT,
OnInfomenuAbout)
ON_COMMAND(ID_INFOMENU_EXIT,
OnInfomenuExit)
ON_COMMAND(ID_INFOMENU_BOOK,
OnInfomenuBook)
END_MESSAGE_MAP()
// CKJV_VCNetDlg message handlers
BOOL CKJV_VCNetDlg::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
// TODO: Add
extra initialization here
return
TRUE; // return TRUE
unless you set the focus to a control
}
void
CKJV_VCNetDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if
((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you
will need the code below
// to draw the icon. For MFC applications using the
document/view model,
// this is automatically done for you by the framework.
void CKJV_VCNetDlg::OnPaint()
{
if
(IsIconic())
{
CPaintDC dc( this);
// device context
for painting
SendMessage(WM_ICONERASEBKGND,
reinterpret_cast<WPARAM>(dc.GetSafeHdc()),
0);
// Center icon in
client rectangle
int
cxIcon = GetSystemMetrics(SM_CXICON);
int
cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int
x = (rect.Width() - cxIcon + 1) / 2;
int
y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this function to obtain the cursor
to display while the user drags
// the minimized window.
HCURSOR CKJV_VCNetDlg::OnQueryDragIcon()
{
return
static_cast<HCURSOR>(m_hIcon);
}
void
CKJV_VCNetDlg::OnInfomenuAbout()
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
// TODO: Add your
command handler code here
}
void
CKJV_VCNetDlg::OnInfomenuExit()
{
this->EndDialog(0);
// TODO: Add your
command handler code here
}
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,
KJV2002.mdb at Current Directory
m_pDBW->Open((CString)curdir +
_T("\\KJV2002.mdb"));
m_pRSW->Open(dbOpenDynaset,
"SELECT * from BibleTable", 0);
//First record of
KJV2002.mdb file stores information about this database
m_pRSW->Move(0);
m_edit1 = 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
}
void
CKJV_VCNetDlg::OnInfomenuBook()
{
CBook dlgBook;
dlgBook.DoModal();
// TODO: Add your
command handler code here
}
void
CAboutDlg::OnBnClickedButton1()
{
CBiography dlgBio;
dlgBio.DoModal();
// TODO: Add your
control notification handler code here
} |
|
|
|
|