We are detailing about Anatomy of a Windows-Based Application, Elements of a Windows-Based Application, Resource type Description, how a Window Processes Message, and show you the illustration of Anatomy of a windows-based application.

Anatomy of a Windows-Based Application

Knowing the elements that make up a Windows-based application and how windows communicate information between the application and the user is important to writing effective MFC applications.

In this section, you will learn about the essential components of a Windows-based application and get a brief introduction to how messages are processed in the Windows environment.

This section includes the following topics:

Elements of a Windows-Based Application

The basic elements that make up a Windows-based application include code, user interface resources, and library modules invoked by the application through dynamic linking.

The primary content of any application is executable code. Windows-based applications have two required functions. One, called WinMain, provides an entry point for the operating system. The second function, a window procedure, is needed to handle messages from the operating system.

User Interface Resources

Many application-defined elements of an application’s graphical user interface (GUI), such as menus and dialog boxes, are stored as templates and references in a special read-only section of the corresponding executable or DLL file. When required, Windows reads from this resource section and constructs the GUI element dynamically.

Note that while resources are primarily used to store information about the GUI elements of an application, any read-only information could be placed in the resource section. The advantage is that resources are shipped as part of the executable file, minimizing the need for additional files to be shipped with an application.

The following table lists the common Win32 resources.

Resource type  Description

Accelerator Stores the keystrokes and their command associations.
Bitmap  Contains a graphical image in Windows-compatible format.

Dialog box Details the controls, layouts, and attributes for dialog boxes.

Icon Stores special sets of bitmaps for icons.

Menu Details the text and layout for menus and their items.

String table Stores character strings and an associated ID value.

Toolbar Details toolbar layouts and contains references to the special bitmaps that are used to draw the button faces.

Version information  Maintains program status information, such as program name, author, copyright data, version number, and so on.

Cursor Contains the special bitmap that is used to draw the cursor.

Library Modules

Microsoft Windows, along with most modern operating systems, supports dynamic linking, a method for invoking library modules at run time. A library module is a binary file that contains the executable library routines. A library module that can be loaded in this manner is called a dynamic-link library, or DLL.

How an Application Is Started?

For a Windows-based application to get up and running, several events must occur first. When a user starts an application, the following events occur in sequence:

  1. The operating system creates a new process and an initial thread.
  2. The application code is loaded into memory.
  3. Dynamic-link libraries also are loaded into memory, if your application uses them.
  4. Space for items, such as data and stacks, is allocated from physical memory and mapped into the virtual address space.
  5. The application begins execution.

How a Window Processes Message?

Most Windows users are familiar with the term window and the visual elements that characterize applications. From a developer’s standpoint, windows take on a new meaning. In a Windows-based application, windows are the primary method of communicating information from the application to the user. Similarly, the user uses the window to communicate with the application, thus achieving the desired behavior to accomplish a task.

The following steps explain how a Windows-based application prepares itself to receive messages that are sent to it by the system queue.

  1. When a Windows-based application is started, the operating system connects with the application at a predefined entry point. This entry point is defined in the WinMain function, a required function in all Windows-based applications.
  2. The application then creates one or more windows. Each window contains a window procedure that is responsible for determining what the window displays and how the window responds to user input.
  3. A section of code called a message loop retrieves messages from the message queue and gives them back to Windows to send to the appropriate window procedure. This gives the application a chance to preprocess messages before they are sent to a window.

The code to implement each of the steps in this process is presented in a sample application and described in detail in Analyzing a Simple Windows-Based Application later in this chapter.

The following illustration shows how messages passed from the system queue are processed by the application.

LEAVE A REPLY

Please enter your comment!
Please enter your name here