Sie sind auf Seite 1von 34

WIN32 API Programming

Guided by : Mr. Debasis Mohapatra (Lecturer)


By :
Sujit Kumar Singh Barun Kumar Mishra Tapan Kumar Sethi

Introduction
WIN32 is a family of Windows which supports 32bit GUI based platform for applications. Following functions and features of WIN32 API makes it more userfriendly and powerful :

GUI platform with multithreading helps in multitasking. Various menus/popup-menus, dialog boxes and clipboard utilities. Supports various coding languages and linking between them. Manages the resource allotment to programs.

API Application Programming Interface is a source code that a program library provides in order to support request by any computer program. Helps program to interact with hardware while executing its codes. DLL Dynamic Linking Library is a shared library of executable functions or data. This mainly contains DLL, OCX (ActiveX file), DRV (driver file)

Modules
1. WIN 32 resources 2. Message and events 3. Characteristics of a Window 4. Management of different windows 5. GDI (Graphical Device Interface) 6. GDI tools 7. Bitmaps

Modules
1. WIN32 Resources :
Resources are menus, icons, cursors, dialog boxes, sounds having extension *.res (.rc for fonts). Text based resource (Keyboard accelerators) and graphics based resources. Usage : Resources can be created or imported just like a normal code. As these are mainly in graphical form so, two or more resources can be merge to create another.

Eg. Caret (the blinking line), Cursors, Icons, Keyboard accelerators etc. are the common resources.

2. Message and events :

Computer need commands to operate. OS sends messages of various constant positive integer. Every message have its unique value.

Windows Message

Keyboard Message passing

3. Characteristics of a Window :
An application window have different properties depending on its border type, title bar, caption, visibility style etc. WIN32 provides various functions to manipulate the application windows properties. For normal users, WIN32 provides simple drag-and-drop GUI based function to move or resize his/her window.

4. Management of different window :


Mainly windows are of two types Parent and Child. A child window may also have many sub child windows. Parent - A window is referred to as a parent when there are or there can be other windows that depend on it. Child - A window is referred to as child when its existence and especially its visibility depend on another window called its parent.

5. GDI (Graphics Device Interface) :


GDI is a Microsoft Windows application programming interface and core operating system component responsible for representing graphical objects and transmitting them to output devices such as monitors and printers. Functions and Usage : Responsible for drawing simple geometries like point, line, circle, square , polygon, curves, etc. Responsible for displaying any kind of simple or complex graphical based display/figure.

Converting to decimal, each number will produce :

Therefore, each number can have a value that ranges from 0 to 255 in the decimal system. These three numbers are combined to produce a single number as follows :

Converted to decimal, this number has a value of 255 * 255 * 255 = 16581375. This means that we can have approximately 16 million colors available. Microsoft Windows considers that a color is a 32-bit numeric value. Therefore, a color is actually a combination of 32 bits:

GDI Interface to Kernel

GUI Sequence diagram

6. GDI tools :
GDI tools are those applications by which an user can draw or create some simple textual or graphical based diagrams. Some GDI tools are :

Fonts - A font is a list of symbols that can be drawn on a device


context to produce a symbol. A font is designed by an artist.

Pens - A pen is a tool used to draw lines and curves on a device


context. In the graphics programming, a pen is also used to draw the borders of a geometric closed shape such as a rectangle or a polygon.

A pen can be used to draw only simple lines of a fixed width, less than or equal to 1 pixel.

Brushes - A brush is a drawing tool used to fill out closed shapes or


the interior of lines. Brushes selects more than one 1 pixel at a time so it produces a thicker image.

GDI Tools

GDI Interface

7. Bitmaps :
A bitmap is a series of points (bits) arranged like a map so that when put together, they produce a picture that can be written to, copied from, re-arranged, changed, manipulated, or stored as a computer file.

Bitmap can be monochrome in which each pixel have 1 bit. Color bitmap image have more than 1 bit in one pixel.

Line and Ellipse


This is a simple GDI based program where we use GDI tool Pen to draw some basic diagrams (Line and Ellipse). Pen tool takes the coordinates of points and joins them together to draw a complete line diagram.

Source Code

Output

Drawing
This is a simple GDI based program where we use GDI tool Pen to sketch some raw structure without any coordinates commands to program. User decides what to draw at the time of execution.

Source Code

Output

Tic Tac Toe


The famous Tic-Tac-Toe is a good example of GUI based application where two players interact with the game (application) to input their moves. This game has 3x3 grid to 7x7 grid depending on players choice. Players get chance in consecutive manner. If a player inserts his/her input more than once in one chance than game generates an error of invalid move. After each move game searches for winner, if not then it waits for next users input. The game comes to an end when there is a winner or a draw. Source Code Output

Matching Game
This is a complete game program which is entirely based on WIN32 GUI based application where an user matches all similar types of images or diagrams present in game in form of bitmap image files. When the user finds all similar images of the game then the game displays number of attemps made by that player.

Source Code

Output

Conclusion

WIN32 APIs are being used in every field of Windows programming. It is widely being used in approximately every application to make it user friendly by using GUI technology of various APIs of Windows. We are going to implement more applications and GUI based games by integrating various modules of WIN32 API and GUI properties. We can execute our applications according to our requirements with the help of self created and modified DLL files.

References

Programming Windows - Win32 Api (Mspress, Charles Petzold, 5th Edition) Programming Windows 6th edition Inside Windows Debugging (Tarik Soulami) Internet (www.msdn.microsoft.com)

Thanks

Das könnte Ihnen auch gefallen