8.1 BRIEF HISTORY OF WIN32 2
8.2 WINDOWS COMPONENTS 3
8.2.2 GDI (GRAPHICS
22.214.171.124 Pens 4
126.96.36.199 Brushes 4
188.8.131.52 Clipboard 7
8.3 HANDLES IN WINDOWS 7
8.4 OUR FIRST WIN32 PROGRAM 8
8.1 Brief History of Win32Before starting windows programming lets
take a short look at the history of Windows.
• In 1983
Windows announced for the
first time in history.
• In November 1985 Windows 1.0 is
• In April 1987 Windows 2.0 shipped.
• In 1988 Windows/386 emerged out. This
version of Windows supported Multiple
DOS boxes. DOS boxes are
the Consol windows which are enabled to get input or
show output only in text form or character form and no GUI is supported in
• November 1989 Win word 1.0 finally
• In May 1990 Windows 3.0 shipped. It is
designed to operate in 3 Modes. These are
A. Real Mode or 8086 mode
B. Protected Mode or 286 mode
C. Enhanced or 386 mode with multiple DOS boxes and with support of
Memory. In virtual Memory some
of the area on Hard disk is used as system Memory.
• Late 1991 Windows version
3.1 released. This version of Windows came with the
Multimedia extensions that later became the part of Windows standard builds.
• Late 1992 Windows NT beta version
released. And with this version Win32 API also
published. Windows NT offers preemptive
Multitasking is of two types.
In Preemptive multi tasking, the operating system
parcels out CPU time slices to each program.
2. Cooperative or Non
Preemptive Multitasking. In
this type of multitasking
each program can control the CPU for as long as it needs it. If a program is
using the CPU it can allow another program to use it temporarily.
• Summer 1993, Windows NT
version 3.1 is launched. This version of windows is
enabled to run as well, on MIPS and Alpha CPU’s as Intel x86 CPU.
• Summer 1994 Windows version 3.5 is
• In August 1995 Windows95 shipped.
Windows95 was designed for home computing.
• September 1995 Windows version 3.51
released. And it is considered as the most
solid version of NT for servers.
• Summer 1996, Support for the MIPS and
PowerPC machines are dropped.
• June 1998, Windows98 released with
built in Internet Explorer version 4.
• September 1998, Visual Studio 6.0
released. Visual Studio6.0 consists of three
languages i.e. Visual C++, Visual Basic and Visual J++. Visual studio comes
categories, i.e. learner or student edition, professional and Enterprise
Visual C++ is a compiler
that will be using in the Windows programming course. This
Visual C++ compiler would be the part of Professional or Enterprise Visual
• Feb 2000 Windows 2000 released with
major improvements. It is proved to be a much
stable version than the earlier versions of Microsoft Windows series of
systems. It is also called Windows NT5.
8.2 Windows Components
Microsoft Windows consists of three important components. These are:
2. GDI (Graphics Device Interface)
Kernel is a main module of the operating system. This provides system
managing threads, memory, and resources.
Kernel has to perform very important responsibilities e.g.
1. Process Management
2. File Management
3. Memory Management (System and Virtual Memory)
In Windows Operating System Kernel is implemented in the form of
The Kernel is responsible for scheduling and synchronizing threads,
exception and interrupts. Loading applications and managing memory. Kernel
responsible for the system stability and efficiency.
8.2.2 GDI (Graphics Device Interface)
GDI is a subsystem responsible for displaying text and images on display
printers. The GDI processes Graphical function calls from a Windows-based
It then passes those calls to the appropriate device driver, which generates
the output on
the display hardware. By acting as a buffer between applications and output
GDI presents a device-independent view of the world for the application
in a device-dependent format with the device.
GDI is responsible to display application’s graphics objects on Screen and
Applications that use GDI need not worry about Graphics Hardware because GDI
provides the suitable device independent interface. In GDI subsystem,
anything we want
to display or print, there’s Device
context or DC. Device context or DC is a logical term
in windows. Whenever we have to display something, we get DC of display
whenever we have to print something we get DC of printer device.
GDI is implemented in the form of GDI32.dll. This contains
all the APIs
that need to draw graphics or text objects. We can write text, and draw
polygons, lines, points, etc by using
Pens and Brushes:
A pen is a graphics tool
that an application for Microsoft Windows uses to draw lines and
curves. Drawing applications use pens to draw freehand lines, straight
lines, and curves.
Computer-aided design (CAD) applications use pens to draw visible lines,
section lines, center lines, and so on. Word processing and desktop
applications use pens to draw borders and rules. Spreadsheet applications
use pens to
designate trends in graphs and to outline bar graphs and pie charts.
Each pen consists of three attributes: style, width, and color. While no
limits are imposed
on the width and color of a pen, the pen's style must be supported by the
system. These styles are illustrated in the following figure.
Figure 1 Pens types
A brush is a graphics tool
that a Windows based application uses to paint the interior of
polygons, ellipses, and paths. Drawing applications use brushes to paint
processing applications use brushes to paint rules; computer-aided design
applications use brushes to paint the interiors of cross-section views; and
applications use brushes to paint the sections of pie charts and the bars in
There are two types of brushes: logical
and physical. A
logical brush is one that
define in code as the ideal combination of colors and/or pattern that an
use to paint shapes. A physical brush
is one that a device driver creates, which is based
on your logical-brush
When an application calls a drawing function to paint a shape, Windows
brush at the start of the paint operation and maps a pixel in the brush
bitmap to the
window origin of the client area. (The window origin is the upper-left
corner of the
window's client area.) The coordinates of the pixel, that Windows maps, are
The default brush origin is located in the upper-left corner of the brush
bitmap at the
coordinates (0,0). Windows then copies the brush across the client area,
forming a pattern
that is as tall as the bitmap. The copy operation continues, row by row,
until the entire
client area is filled. However, the brush pattern is visible only within the
the specified shape. (Here, the term bitmap is used in its most literal
arrangement of bits—and does not refer exclusively to bits stored in an
There are instances when the default brush origin should not be used. For
may be necessary for an application to use the same brush to paint the
backgrounds of its
parent and child windows and blend a child window's background with that of
The following illustration shows a five-pointed star filled by using an
brush. The illustration shows a zoomed image of the brush, as well as the
which it was mapped at the beginning of the paint operation.
Figure 2 Brush Origin
(Description from MSDN)
Logical Brush Types
Logical brushes come in three varieties: solid, pattern, and
A solid brush consists of a color
or pattern defined by some element of the
Windows user interface (for example, you can paint a shape with the color
pattern conventionally used by Windows to display disabled buttons).
A hatched brush consists of a
combination of a color and of one of the six patterns
defined by Win32. The following table illustrates the appearance of these
Brush Style Illustration
Figure 3 Brush Styles
User component manages all the user interface elements.
User interface elements include Dialogs, Menus, Text, Cursor, Controls,
User component is implemented in User32.dll file. You would be familiar with
user interface elements but the new thing for you might be Clipboard.
In Windows, data is shareable among applications. For example you are typing
Notepad and after you have typed, you want to copy all the text written in
another Editor, say, MS Word. How could this be possible? The answer is:
clipboard. Yes, in clipboard, firstly we copy all the data to clipboard and
then paste that
data to MS Word because clipboard is shareable object. All the text or image
have previously copied can now be pasted in other application.
Following are some of the features of clipboard.
• User32.dll manages clipboard.
• Clipboard is used to cut copy and
• Clipboard is temporary storage area. When you
shut down windows, data saved in
clipboard will be lost.
8.3 Handles in Windows
A term handle is a 32 bit number in Win32 environment. It is
normally a type defined as
void *. Handle has an extensive use in Windows. Using handles you can
and take other actions on the object. The basic types of handles in windows
HWND is of type Handle to Window.
HINSTANCE is of type Handle to instance of the application.
Every application has unique identifier in Memory that is called an instance
8.4 Our first Win32 Program
For writing win32 program you should be
familiar of programming concepts in C++.
First we will include header file
windows.h in our source file
because this header contains
prototype of useful APIs that will be used in our windows programs. This
contains some other headers required for commonly used APIs.
Every Windows GUI base program starts its execution from the
WinMain API. And
Every Windows console base program starts its execution from simple
Here we will be discussing about Windows Graphical User Interface programs.
So we will start our program by writing
int CALLBACK WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR
MessageBox(NULL, “This is the First Windows Program \n Author: Shahid”,
“Virtual Uinversity”, MB_OK|MB_ICONINFORAMTION);
WinMain is the starting point in Every Win32 GUI programs.
WinMain has four
Parameters these are,
1) First is instance of the current application.
2) Second parameter is also an instance of this application which is used
for the previous
application of the same type that is already running. It is used only in
editions or Windows 3.1. Windows 32bit editions do not support this
parameter. It is here
just for compatibility.
3) Third parameter is a command line argument of string type which is a type
4) Fourth parameter is windows style.
CALLBACK is a calling convention which is a type defined as
In our application WinMain returns 0. WinMain always returns a
value of type integer.
MessageBox API is used to display a message on screen. It comes
in windows dialog
form and has caption and client area, both of these contains strings. It
also has buttons,
like Ok, Cancel, Yes, No, Retry, Abort. It has four arguments.
1) First is the HANDLE to window, this handle is a parent handle of the
our case it has no parent handle so we write NULL here that shows that it
2) Second parameter is a string type which print string in the body of the
which is also called client area of the message box
3) Third parameter is also a string type it prints string in a caption of
the message box.
4) Fourth parameter is a buttons that will be displayed in the message box.
here some of the constants like MB_OK|MB_ICONINFORMATION which display ok
button and icon information on the left side of the message box. These
constants can be
presented here by using bitwise OR operator.
In this Lecture, we studied about the windows history about when and how
editions were released. Then we learnt about the windows components: Kernel,
User. Kernel is the heart of Operating system and GDI is a Graphics device
windows which is used to display and print graphics and text objects. Then
user component which is responsible to control all the dialogs, menu,
controls, etc. ‘Handles in windows’ is the introductory part of handles used
Handles are 32 bit number that may be void * type which is defined in
header file. Finally we wrote our first Win32 program. We always write
every windows program because WinMain is the starting point of Windows
And we learnt how to display message box in WinMain function and then we
from WinMain with the returned value Zero. And we discussed about the
API and explained its parameters as well.
Tips: Never use second parameter
(HINSTANCE) of WinMain because it is not used in
recent version of windows. In future lectures, we will discuss how to
existence of previous application.
Some of the course material and Documentation on Microsoft Windows APIs has
taken from Microsoft for the preparation of Win32 course. This course has
and prepared by Virtual University.
Microsoft, Visual C++, Windows, Windows NT, Win32, and Win32s are either
registered trademarks or trademarks of Microsoft Corporation.