Page 224 - DCAP408_WEB_PROGRAMMING
P. 224
Windows Programming
Notes Discuss Animated Graphics
Understand the function of Peek Message [] Loop
Introduction
In this unit, you will understand various concepts related to text and graphics output such as
Character mode vs. Graphic Mode, Device Context, Text output, WM_PAINT message, Graphics
Output, Animated Graphics, etc.
14.1 Character Mode vs. Graphic Mode
14.1.1 Character Mode
Many video adapters support several different modes of resolution. All such modes are divided
into two general categories: character mode (also called text mode) and graphics mode. In character
mode, the display screen is treated as an array of blocks, each of which can hold one ASCII
character. Of the two modes, character mode is much simpler. Programs that run in character
mode generally run much faster than those that run in graphics mode, but they are limited in the
variety of fonts and shapes they can display. Programs that run entirely in character mode are
called character-based programs.
14.1.2 Graphic Mode
In graphics mode, the display screen is treated as an array of pixels, with characters and other
shapes formed by turning on combinations of pixels. Of the two modes, graphics mode is the
more sophisticated. Programs that run in graphics mode can display an unlimited variety of
shapes and fonts, whereas programs running in character mode are severely limited. Programs
that run entirely in graphics mode are called graphics-based programs.
Self Assessment
Fill in the blanks:
1. Programs that run entirely in character mode are called ......................... programs.
2. In graphics mode, the display screen is treated as an array of ......................... .
14.2 The Device Context
A device context is a Windows data structure containing information about the drawing attributes
of a device such as a display or a printer. All drawing calls are made through a device-context
object, which encapsulates the Windows APIs for drawing lines, shapes, and text. Device contexts
allow device-independent drawing in Windows. Device contexts can be used to draw to the
screen, to the printer, or to a metafile.
CPaintDC objects encapsulate the common idiom of Windows, calling the BeginPaint function,
then drawing in the device context, then calling the EndPaint function. The CPaintDC constructor
calls BeginPaint for you, and the destructor calls EndPaint. The simplified process is to create
the CDC object, draw, and destroy the CDC object. In the framework, much of even this process
is automated. In particular, your OnDraw function is passed a CPaintDC already prepared
(via OnPrepareDC), and you simply draw into it. It is destroyed by the framework and the
218 LOVELY PROFESSIONAL UNIVERSITY