Windows Basics - Computer Programming - Lecture Notes, Study notes of Computer Engineering and Programming

Windows Basics, Brief History of Win32, Windows Components, Graphics Device Interface, User, Clipboard, Handles in Windows, Our first Win32 Program, Summary. As you can see in this file, how descriptive above mentioned points are explained in this lecture of computer programming. VU is one of best university for computer science in our country.

Typology: Study notes

2011/2012

Uploaded on 11/06/2012

ahsen
ahsen 🇵🇰

4.6

(88)

84 documents

1 / 10

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Chapter 8
8.1 BRIEF HISTORY OF WIN32 2
8.2 WINDOWS COMPONENTS 3
8.2.1 KERNEL 3
8.2.2 GDI (GRAPHICS DEVICE INTERFACE) 3
8.2.2.1 Pens 4
8.2.2.2 Brushes 4
8.2.3 USER 7
8.2.3.1 Clipboard 7
8.3 HANDLES IN WINDOWS 7
8.4 OUR FIRST WIN32 PROGRAM 8
SUMMARY 9
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download Windows Basics - Computer Programming - Lecture Notes and more Study notes Computer Engineering and Programming in PDF only on Docsity!

  • Chapter
  • 8.1 BRIEF HISTORY OF WIN
  • 8.2 WINDOWS C OMPONENTS
  • 8.2.1 KERNEL
  • 8.2.2 GDI (GRAPHICS DEVICE I NTERFACE )
  • 8.2.2.1 Pens
  • 8.2.2.2 Brushes
  • 8.2.3 USER
  • 8.2.3.1 Clipboard
  • 8.3 HANDLES IN W INDOWS
  • 8.4 OUR FIRST WIN 32 P ROGRAM
  • S UMMARY

8.1 Brief History of Win

Before 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 launched.
  • 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 this mode.
  • November 1989 Win word 1.0 finally shipped.
  • 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 Virtual 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. Multitasking is of two types. 1. Preemptive Multitasking. 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 not 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 launched.
  • 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.

GDI is responsible to display application’s graphics objects on Screen and Printer. The 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 device, and whenever we have to print something we get DC of printer device. GDI is implemented in the form of library GDI32.dll. This library contains all the APIs that need to draw graphics or text objects. We can write text, and draw rectangles, polygons, lines, points, etc by using Pens and Brushes:

8.2.2.1 Pens

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, hidden lines, section lines, center lines, and so on. Word processing and desktop publishing 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 operating system. These styles are illustrated in the following figure.

Figure 1 Pens types

8.2.2.2 Brushes

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 shapes; word processing applications use brushes to paint rules; computer-aided design (CAD)

Solid

Dash

Dot

Dash-Dot

Dash-Dot-Dot

Null

applications use brushes to paint the interiors of cross-section views; and spreadsheet applications use brushes to paint the sections of pie charts and the bars in bar graphs.

There are two types of brushes: logical and physical. A logical brush is one that you define in code as the ideal combination of colors and/or pattern that an application should use to paint shapes. A physical brush is one that a device driver creates, which is based on your logical-brush definition.

Brush Origin

When an application calls a drawing function to paint a shape, Windows positions a 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 called the brush origin.

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 boundaries of the specified shape. (Here, the term bitmap is used in its most literal sense—as an arrangement of bits—and does not refer exclusively to bits stored in an image file).

There are instances when the default brush origin should not be used. For example, it 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 parent window.

The following illustration shows a five-pointed star filled by using an application-defined brush. The illustration shows a zoomed image of the brush, as well as the location to which it was mapped at the beginning of the paint operation.

Horizontal

Vertical

Figure 3 Brush Styles

8.2.3 User

User component manages all the user interface elements. User interface elements include Dialogs, Menus, Text, Cursor, Controls, Clipboard, etc. User component is implemented in User32.dll file. You would be familiar with all the user interface elements but the new thing for you might be Clipboard.

8.2.3.1 Clipboard

In Windows, data is shareable among applications. For example you are typing in Notepad and after you have typed, you want to copy all the text written in Notepad to another Editor, say, MS Word. How could this be possible? The answer is: through 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 data you 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 paste operations.
  • 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 destroy, release and take other actions on the object. The basic types of handles in windows are:

  • HANDLE
  • HWND
  • HINSTANCE

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 of the application.

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 header also contains some other headers required for commonly used APIs.

#include <windows.h>

Every Windows GUI base program starts its execution from the WinMain API. And Every Windows console base program starts its execution from simple main function. Here we will be discussing about Windows Graphical User Interface programs. So we will start our program by writing WinMain.

int CALLBACK WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow) { MessageBox(NULL, “This is the First Windows Program \n Author: Shahid”, “Virtual Uinversity”, MB_OK|MB_ICONINFORAMTION); return 0; }

WinMain: 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 Window 16bit 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 defined as char *.
  4. Fourth parameter is windows style.

Calling Convention: CALLBACK is a calling convention which is a type defined as __stdcall. Return Value: In our application WinMain returns 0. WinMain always returns a value of type integer.

Copyright

Some of the course material and Documentation on Microsoft Windows APIs has been taken from Microsoft for the preparation of Win32 course. This course has been designed and prepared by Virtual University.

Microsoft, Visual C++, Windows, Windows NT, Win32, and Win32s are either registered trademarks or trademarks of Microsoft Corporation.