Visual C++ and MFC Programming 2nd Edition

(Martin Jones) #1

Chapter 12: Dialog-Based Windows Visual C++ and MFC Fundamentals


10.1 Introduction to Win32 Library..................................................................


10.1.1..Overview...............................................................................................


Win32 is a library made of data types, variables, constants, functions, and classes (mostly
structures) that can be used to create applications for the Microsoft Windows operating
systems. A typical application is made of at least two objects: a control and a host object
on which the control is positioned.

To create a Win32 application using Microsoft Visual C++, display the New (5 and 6
versions) or New Project (7 version) dialog box and select Win32 application (5 and 6) or
Win32 Project (7) item.

Just like a C++ program always has a main() function, a Win32 program uses a central
function called WinMain. The syntax of that function is:

INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow );

Unlike the C++ main() function, the arguments of the WinMain() function are not
optional. Your program will need them to communicate with the operating system.

To create an application using the Microsoft Foundation Class (MFC) library, we have
seen that we can create a class derived from CWinApp. The CWinApp class implements
the role of the WinMain() function. To provide functionality as complete as possible, this
class is equipped with appropriate variables and methods.

Pratical Learning: Exploring the Win32 Library



  1. Start Microsoft Visual C++ or Visual Studio and display either the New dialog box
    and its Projects property page (MSVC 6) or the New Project dialog box (MSVC 7)

  2. Set the Project Type as either Win32 Application or Win32 Project

  3. Set the name as Win32B and click OK

  4. Set the project as An Empty Project for a Windows Application and click Finish

  5. Create a C++ Source File named Exercise

  6. In the empty file, type:


#include <windows.h>

INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow )
{
return 0;
}


  1. Save All

Free download pdf