|
How to create new Visual
C++ .Net project, type MFC.
Run Microsoft
Visual Studio .Net. On the File menu , click New,
and then click Project .... The New Project dialog box
appears.
- In the Project
Types pane, select the Visual C++ Projects
folder.
- In the Templates
pane, select MFC Application icon (project type). A
message appears indicating the type of project you are going to
create - (An Application that uses the Microsoft Foundation Class
Library).
- In the Name
box, type KJV_VCNet.
- In the
Location box, type C:\
- Click OK.
MFC
Application Wizard - KJV_VCNet dialog box appears
In the
MFC Application Wizard - KJV_VCNet dialog box:
- Select Application Type.
-
Select Dialog based
radio button
-
Select MFC Standard radio button
-
Select Use MFC in a
shared DLL check button
-
Click Finish.
|
The
MFC Application create all necessary files and
opens the Visual C++ .Net project - KJV_VCNet
|
1. |
On the View menu, click Solution
Explorer, dialog box appears
... Solution Explorer -
KJV_VCNet - provides you with an organized view
of your projects and their files as well as ready access to
the commands that pertain to them .
|
2. |
On the View menu, click Resource View, dialog box appears
... Resource View -
KJV_VCNet- displays the resource files created
|
3. |
On the View menu, click Class
view, dialog box appears
... Class View -
KJV_VCNet -
displays a programmatic view of
symbols in your code.
|
|
1. |
The Dialogs ...
1. |
IDD_KJV_VCNET_DIALOG
The MFC
class and files corresponding to this dialog ...
MFC class
name:
Header file name:
Source file name: |
CKJV_VCNetDlg
KJV_VCNetDlg.h
KJV_VCNetDlg.cpp |
|
|
2. |
IDD_ABOUTBOX
The MFC class
and files corresponding to this dialog ...
MFC class
name:
Header file name:
Source file name: |
CAboutDlg
-
KJV_VCNetDlg.cpp |
|
|
|
2. |
The Files ...
1. |
Resource.h
//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ generated include file.
// Used by KJV_VCNet.RC
//
#define IDR_MAINFRAME 128
#define IDM_ABOUTBOX 0x0010
#define IDD_ABOUTBOX 100
#define IDS_ABOUTBOX 101
#define IDD_KJV_VCNET_DIALOG
102
#define IDR_MANIFEST
CREATEPROCESS_MANIFEST_RESOURCE_ID
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef
APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE
129
#define _APS_NEXT_CONTROL_VALUE
1000
#define _APS_NEXT_SYMED_VALUE
101
#define _APS_NEXT_COMMAND_VALUE
32771
#endif
#endif |
|
2. |
stdafx.h
//
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
#ifndef _AFX_NO_AFXCMN_SUPPORT
#include <afxcmn.h>
// MFC support for
Windows Common Controls
#endif
// _AFX_NO_AFXCMN_SUPPORT |
|
3. |
KJV_VCNet.h
//
KJV_VCNet.h : main header file for the PROJECT_NAME
application //
#pragma
once
#ifndef __AFXWIN_H__
#error
include 'stdafx.h' before including this file for PCH
#endif
#include "resource.h"
// main symbols
// CKJV_VCNetApp:
// See KJV_VCNet.cpp for the implementation of this
class
//
class CKJV_VCNetApp :
public
CWinApp
{
public :
CKJV_VCNetApp();
// Overrides
public:
virtual
BOOL InitInstance();
// Implementation
DECLARE_MESSAGE_MAP()
};
extern CKJV_VCNetApp theApp; |
|
4. |
KJV_VCNet.cpp
//
KJV_VCNet.cpp : Defines the class behaviors for the
application. //
#include "stdafx.h"
#include "KJV_VCNet.h"
#include "KJV_VCNetDlg.h"
#ifdef _DEBUG
#define
new
DEBUG_NEW
#endif
// CKJV_VCNetApp
BEGIN_MESSAGE_MAP(CKJV_VCNetApp, CWinApp)
ON_COMMAND(ID_HELP, CWinApp::OnHelp)
END_MESSAGE_MAP()
// CKJV_VCNetApp construction
CKJV_VCNetApp::CKJV_VCNetApp()
{
// TODO: add
construction code here,
// Place all
significant initialization in InitInstance
}
// The one and only CKJV_VCNetApp object
CKJV_VCNetApp theApp;
// CKJV_VCNetApp initialization
BOOL CKJV_VCNetApp::InitInstance()
{
//
InitCommonControls() is required on Windows XP if an
application
// manifest
specifies use of ComCtl32.dll version 6 or later to
enable
// visual
styles. Otherwise, any window creation will fail.
InitCommonControls();
CWinApp::InitInstance();
AfxEnableControlContainer();
// Standard
initialization
// If you are
not using these features and wish to reduce the size
// of your
final executable, you should remove from the following
// the
specific initialization routines you do not need
// Change the
registry key under which our settings are stored
// TODO: You
should modify this string to be something appropriate
// such as
the name of your company or organization
SetRegistryKey(_T("Local AppWizard-Generated
Applications"));
CKJV_VCNetDlg dlg;
m_pMainWnd = &dlg;
INT_PTR nResponse = dlg.DoModal();
if
(nResponse == IDOK)
{
// TODO:
Place code here to handle when the dialog is
// dismissed
with OK
}
else
if
(nResponse == IDCANCEL)
{
// TODO:
Place code here to handle when the dialog is
// dismissed
with Cancel
}
// Since the
dialog has been closed, return FALSE so that we exit
the
//
application, rather than start the application's
message pump.
return
FALSE;
} |
|
5. |
KJV_VCNetDlg.h
//
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()
}; |
|
6. |
KJV_VCNetDlg.cpp
//
KJV_VCNetDlg.cpp : implementation file //
#include "stdafx.h"
#include "KJV_VCNet.h"
#include "KJV_VCNetDlg.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()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
}
void
CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
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
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);
} |
|
|
|
1. |
IDD_BOOK
Create new
Dialog ...
- On the Project menu , click
Add Resource, The Add Resource dialog box
appears.
- In this
dialog, select Dialog
and click New
-
New item - IDD_DIALOG1 added to the Dialog
folder
in the Resource View -
KJV_VCNet dialog box
-
New dialog design -
IDD_DIALOG1 appears
Rename this dialog
Old Name
|
New Name
|
IDD_DIALOG1 |
IDD_BOOK |
|
Add
Class ...
- On the Project menu , click
Add Class, The MFC class wizard - KJV_VCNet dialog box
appears.
- In this wizard dialog box,
type the following data ...
Class name:
Base class:
Dialog ID:
.h file:
.cpp file: |
CBook
CDialog
IDD_BOOK
Book.h
Book.cpp |
|
The files corresponding ..
1. |
Book.h
#pragma
once // CBook dialog
class CBook :
public
CDialog
{
DECLARE_DYNAMIC(CBook)
public :
CBook(CWnd* pParent = NULL);
// standard constructor
virtual
~CBook();
// Dialog Data
enum
{ IDD = IDD_BOOK };
protected :
virtual
void
DoDataExchange(CDataExchange* pDX);
// DDX/DDV support
DECLARE_MESSAGE_MAP()
}; |
|
2. |
Book.cpp
//
Book.cpp : implementation file
//
#include "stdafx.h"
#include "KJV_VCNet.h"
#include "Book.h"
// CBook dialog
IMPLEMENT_DYNAMIC(CBook, CDialog)
CBook::CBook(CWnd* pParent
/*=NULL*/)
: CDialog(CBook::IDD, pParent)
{
}
CBook::~CBook()
{
}
void
CBook::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(CBook, CDialog)
END_MESSAGE_MAP()
// CBook message handlers |
|
|
2. |
IDD_BIOGRAPHY
Create new
Dialog ...
- On the Project menu , click
Add Resource, The Add Resource dialog box
appears.
- In this
dialog, select Dialog
and click New
-
New item - IDD_DIALOG2 added to the Dialog
folder
in the Resource View -
KJV_VCNet dialog box
-
New dialog design -
IDD_DIALOG2 appears
Rename this dialog
Old Name
|
New Name
|
IDD_DIALOG2 |
IDD_BIOGRAPHY |
|
Add
Class ...
- On the Project menu , click
Add Class, The MFC class wizard - KJV_VCNet dialog box
appears.
- In this wizard dialog box,
type the following data ..
.Class name:
Base class:
Dialog ID:
.h file:
.cpp file: |
CBiography
CDialog
IDD_BIOGRAPH
Biography.h
Biography.cpp |
|
The files corresponding ..
1. |
Biography.h
#pragma
once // CBiography dialog
class CBiography :
public
CDialog
{
DECLARE_DYNAMIC(CBiography)
public :
CBiography(CWnd* pParent = NULL);
// standard constructor
virtual
~CBiography();
// Dialog Data
enum
{ IDD = IDD_BIOGRAPHY };
protected :
virtual
void
DoDataExchange(CDataExchange* pDX);
// DDX/DDV support
DECLARE_MESSAGE_MAP()
}; |
|
2. |
Biography.cpp
//
Biography.cpp : implementation file
//
#include "stdafx.h"
#include "KJV_VCNet.h"
#include "Biography.h"
// CBiography dialog
IMPLEMENT_DYNAMIC(CBiography, CDialog)
CBiography::CBiography(CWnd* pParent
/*=NULL*/)
: CDialog(CBiography::IDD, pParent)
{
}
CBiography::~CBiography()
{
}
void
CBiography::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(CBiography, CDialog)
END_MESSAGE_MAP()
// CBiography message handlers |
|
|
3. |
The Classes used in this
Application:
On the
Project menu , click
Class View
|
| |
|