






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
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
1 / 10
This page cannot be seen from the preview
Don't miss anything!







Before starting windows programming lets take a short look at the history of Windows.
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.
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:
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
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
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.
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.
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:
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.
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,
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.