Home Index  | Back

New Page 1
Lesson 1 -Building Your First Windows Application

1.1 : Creating a Windows Application

1.2 : Creating a Dialog-Based Application

1.3 : Creating DLLs, Console Applications, and More

1.4 : Changing Your AppWizard Decisions
 1.5 : Understanding AppWizard’s Code
 1.6 : Understanding a MDI Application
 1.7 : Understanding the Components of a Dialog-Based Application

Lesson 2 - Dialogs and Controls

2.1 : Understanding Dialog Boxes

2.2 : Creating a Dialog Box Resource

 2.3 : Writing a Dialog Box Class
 2.4 : Using the Dialog Box Class
Lesson 3 - Messages and Commands

3.1 : Understanding Message Routing

3.2 : Understanding Message Loops

 3.3 : Reading Message Maps
 3.4 : Learning How ClassWizard Helps You Catch Messages
 3.5 : Recognizing Messages
 3.6 : Understanding Commands
 3.7 : Understanding Command Updates
 3.8 : Learning How ClassWizard Helps You Catch Commands and Command Updates

Lesson 4 - Documents and Views

4.1 : Understanding the Document Class

4.2 : Understanding the View Class

4.3 : Creating the Rectangles Application

 4.4 : Other View Classes

4.5 : Document Templates, Views, and Frame Windows

Lesson 5 - Drawing on the Screen

5.1 :Understanding Device Contexts

 5.2 : Introducing the Paint1 Application
 5.3 : Building the Paint1 Application
 5.4 : Scrolling Windows
 5.5 : Building the Scroll Application
Lesson 6 - Building a Complete Application: ShowString

6.1 : Building an Application That Displays a String

 6.2 : Building the ShowString Menus
 6.3 : Building the ShowString Dialog Boxes
 6.4 : Making the Menu Work
 6.5 : Making the Dialog Box Work
 6.6 : Adding Appearance Options to the Options Dialog Box
Lesson 7 -  Status Bars and Toolbars

7.1 : Working with Toolbars

 7.2 : Working with Status Bars
Lesson 8 - Common Controls

8.1 : The Progress Bar Control

 8.2 : The Up-Down Control
 8.3 : The Image List Control
 8.4 : The List View Control
 8.5 : The Tree View Control
 8.6 : The Rich Edit Control
 8.7 : The Date Picker Control
 8.8 : Month Calendar Control
 8.9 : Scrolling the View
Lesson 9 - Property Pages and Sheets

9.1 : Introducing Property Sheets

 9.2 : Creating the Property Sheet Demo Application
 9.3 : Running the Property Sheet Demo Application
Lesson 10 - ActiveX Concepts

10.1 : The Purpose of ActiveX

10.2 : Object Linking

10.3 : Object Embedding

 10.4 : Containers and Servers
 10.5 : Toward a More Intuitive User Interface
 10.6 : The Component Object Model  

10.7 : Automation

 10.8 : ActiveX Controls

Lesson 11 -  Building an ActiveX Control

11.1 : Creating a Rolling-Die Control

11.2 : Displaying the Current Value

11.3 : Reacting to a Mouse Click and Rolling the Die 

 11.4 : Creating a Better User Interface
 11.5 : Generating Property Sheets
Lesson 12 - Database Access

12.1 : Understanding Database Concepts

12.2 : Creating an ODBC Database Program

 12.3 : Choosing Between ODBC and DAO
 12.4 : OLE DB

Lesson - 1 : Building Your First Windows Application

1.7 : Understanding the Components of a Dialog-Based Application

Dialog applications are much simpler than SDI and MDI applications. Create one called FirstDialog, with an About box, no Help, 3D controls, no automation, ActiveX control support, no sockets, source file comments, and MFC as a shared DLL. In other words, accept all the default options.

Three classes have been created for you for the application called FirstMDI:

  • CAboutDlg, a dialog class for the About dialog box

  • CFirstDialogApp, a CWinApp class for the entire application

  • CFirstDialogDlg, a dialog class for the entire application

  • Listing 1.5 shows the header file for CFirstDialogApp.

    Listing 1.5 dialog16.h—Main Header File

    // FirstDialog.h : main header file for the FIRSTDIALOG application

    //

    #if !defined(AFX_FIRSTDIALOG_H__CDF38DB4_8718
    _11D0_B02C_0080C81A3AA2__INCLUDED_)

    #define AFX_FIRSTDIALOG_H__CDF38DB4_8718
    _11D0_B02C_0080C81A3AA2__INCLUDED_

    #if _MSC_VER >= 1000

    #pragma once

    #endif // _MSC_VER >= 1000

    #ifndef __AFXWIN_H__

    #error include ‘stdafx.h’ before including this file for PCH

    #endif

    #include "resource.h" // main symbols

    ////////////////////////////////////

    // CFirstDialogApp:

    // See FirstDialog.cpp for the implementation of this class

    //

    class CFirstDialogApp : public CWinApp

    {

    public:

    CFirstDialogApp();

    // Overrides

    // ClassWizard generated virtual function overrides

    //{{AFX_VIRTUAL(CFirstDialogApp)

    public:

    virtual BOOL InitInstance();

    //}}AFX_VIRTUAL

    // Implementation

    //{{AFX_MSG(CFirstDialogApp)

    // NOTE - The ClassWizard will add and remove member functions here.

    // DO NOT EDIT what you see in these blocks of generated code !

    //}}AFX_MSG

    DECLARE_MESSAGE_MAP()

    };

    ////////////////////////////////////////

    //{{AFX_INSERT_LOCATION}}

    // Microsoft Developer Studio will insert additional declarations immediately

    // before the previous line.

    #endif // !defined(AFX_FIRSTDIALOG_H_
    CDF38DB4_8718_11D0_B02C_0080C81A3AA2

    ¬__INCLUDED_)

    CFirstDialogApp inherits from CWinApp, which provides most of the functionality. CWinApp has a constructor, which does nothing, as did the SDI and MDI constructors earlier in this unit, and it overrides the virtual function InitInstance(), as shown in Listing 1.6.

    Listing 1.6 FirstDialog.cpp CDialog16App::InitInstance()

    BOOL CFirstDialogApp::InitInstance()

    {

    AfxEnableControlContainer();

    // Standard initialization

    // If you are not using these features and want to reduce the size

    // of your final executable, you should remove from the following

    // the specific initialization routines you don’t need.

    #ifdef _AFXDLL

    Enable3dControls(); // Call this when using MFC in a shared DLL

    #else

    Enable3dControlsStatic(); // Call this when linking to MFC statically

    #endif

    CFirstDialogDlg dlg;

    m_pMainWnd = &dlg;

    int 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

    }

    // Because the dialog has been closed, return FALSE so that you exit the

    // application, rather than start the application’s message pump.

    return FALSE;

    }

    This enables 3D controls, because you asked for them, and then puts up the dialog box that is the entire application. To do that, the function declares an instance of CDialog16Dlg, dlg, and then calls the DoModal() function of the dialog, which displays the dialog box onscreen and returns IDOK if the user clicks OK, or IDCANCEL if the user clicks Cancel. It’s up to you to make that dialog box actually do something. Finally, InitInstance() returns FALSE because this is a dialog-based application and when the dialog box is closed, the application is ended. As you saw earlier for the SDI and MDI applications, InitInstance() usually returns TRUE to mean "everything is fine—run the rest of the application" or FALSE to mean "something went wrong while initializing." Because there is no "rest of the application," dialog-based apps always return FALSE from their InitInstance().

     

    Next>>
     
    © Dewsoft Overseas