Introduction To Windows Concepts
Introduction To Windows Concepts
Concepts
Windows is a Graphical User Interface (GUI) and programs
written in Windows will also be graphical in nature(eg , MS
Word , Excel , PowerPoint etc)
Windows provides the application with a set of in built functions
which are collectively called as the Application Programming
Interface(API) .
Writing the window based programs using the API functions is
called as SDK (Software development kit)
Application Programming Interface
API is a set of system defined function that any
application can call
An API is an Interface between application and
windows environment.
API’ s are also provided by O/S to Apllications.
Every Windows environment has its own unique
API.
The Windows Environment
Features:
Unlike DOS , Windows is a Graphical user interface:
Unlike many MS_DOS programs which deal directly with the hardware devices
like the video display , memory , keyboard etc , windows make use of the GDI to
interact with the hardware devices .
Unlike the MS_DOS programs which call the operating system to get the user
input , windows programs process the user input via messages from the operating
system .
MS_DOS programs do not support multiple programs to be executed but windows
based programs support multitasking.
Windows Architecture
Windows based program is an event driven program
Send
Hardware Message
events
Application message Message
queue loop
System
Window
Queue procedure
Default
window
procedure
Post
Message
WinMain(…..) WndProc
•Entry Point •Also called as Window Procedure
•Responsible for •Responsible for processing
creating the window various messages sent by O/s &
others
WNDCLASSEX structure
The WNDCLASSEX structure contains window class
information
typedef struct _WNDCLASSEX {
UINT cbSize;
UINT style;
WNDPROC lpfnWndProc;
int cbClsExtra;
int cbWndExtra;
HINSTANCE hInstance;
HICON hIcon;
HCURSOR hCursor;
HBRUSH hbrBackground;
LPCTSTR lpszMenuName;
LPCTSTR lpszClassName;
HICON hIconSm;
} WNDCLASSEX, *PWNDCLASSEX;
WNDCLASS structure
•The two most important fields in the WNDCLASS structure are the
lpfnWndProc and lpszClassName .
•The (lpfnWndProc) is the address of a window procedure used
for all windows based on this class.
•The lpszClassName is the text name of the window class.
•This can be whatever you want.
•In programs that create only one window, the window class
name is commonly set to the name of the program.
wndclass.style = ?
•The statement
wndclass.style = CS_HREDRAW | CS_VREDRAW;
•combines two 32-bit "class style" identifiers with a C bitwise
OR operator.
•The next two fields are used to reserve some extra space in
the class structure and the window structure that Windows
maintains internally:
•wndclass.cbClsExtra = 0 ;
•wndclass.cbWndExtra = 0 ;
•If a program does not use this feature, 0 is specified.
wndclass.hInstance = hInstance;
•The statement
wndclass.hIcon=LoadIcon
(NULL,IDI_APPLICATION);
•sets an icon for all windows created based on this window
class. The icon is a small bitmap picture that represents the
program to the user.
•When the program is running, the icon appears in the
Windows taskbar and at the left side of the program window's
title bar.
wndclass.hIcon=LoadIcon(…)
The statement
wndclass.hCursor=LoadCursor(NULL,IDC_ARROW)
is similar to the previous statement.
•The LoadCursor function loads a predefined mouse cursor known
as IDC_ARROW and returns a handle to the cursor.
•This handle is assigned to the hCursor field of the WNDCLASSEX
structure.
•A small arrow appears over the client area of a window that is
created based on this class, which is called as the mouse cursor.
wndclass.hCursor=LoadCursor(…)
wndclass.lpszClassName=lpszClassName;
Registering the Window Class
•A window is always created based on a window class.
•The window class identifies the window procedure that processes
messages to the window.
•More than one window can be created based on a single window
class.
•For example, all button windows-including push buttons, check
boxes, and radio buttons-are created based on the same window
class.
Registering the Window Class
•The window class defines the window procedure and some other
characteristics of the windows that are created based on that class.
•When you create a window, you define additional characteristics
of the window that are unique to that window.
•Before you create an application window, you must register a
window class by calling RegisterClassEx.
RegisterClassEx(..)
The RegisterClassEx function registers a window class for subsequent use in
calls to the CreateWindow or CreateWindowEx function.
ATOM RegisterClassEx(
CONST WNDCLASSEX *lpwcx // class data
);
Parameters
hWnd
[in] Handle to the window.
nCmdShow
[in] Specifies how the window is to be shown.
Window States
Value Meaning
SW_HIDE Hides the window and activates another
window.
SW_MAXIMIZE Maximizes the specified window.
SW_MINIMIZE Minimizes the specified window and
activates the next top- level window
SW_SHOW Activates the window and displays it in
its current size and position.
UpdateWindow
The UpdateWindow function updates the client area of the
specified window by sending a WM_PAINT message to the
window. The function sends a WM_PAINT message directly
to the window procedure of the specified window, bypassing
the application queue.
BOOL UpdateWindow(
HWND hWnd // handle to window
);
The Message Loop
•After the UpdateWindow call, the window is fully visible on the
video display.
•The program must now make itself ready to read keyboard and
mouse input from the user.
•Windows maintains a "message queue" for each Windows
program currently running under Windows.
•When an input event occurs, Windows translates the event into a
"message" that it places in the program's message queue.
The Message Loop
BOOL TranslateMessage(
CONST MSG *lpMsg // message
information
);
DispatchMessage(..)
The DispatchMessage function dispatches a message
to a window procedure. It is typically used to dispatch
a message retrieved by the GetMessage function.
LRESULT DispatchMessage(
CONST MSG *lpmsg // message
information
);
The Window Procedure
•A window procedure is always associated with a particular
window class that you register by calling RegisterClassEx.
•The CreateWindow function creates a window based on a
particular window class.
•More than one window can be created based on the same window
class.
•A window procedure is always defined: LRESULT CALLBACK
WndProc (HWND hwnd, UINT message,WPARAM wParam,
LPARAM lParam);
The Window Procedure
•The four parameters to the window procedure are identical to the first four
fields of the MSG structure.
•The first parameter is hwnd, the handle to the window receiving the
message.
•The second parameter is the same as the message field in the MSG
structure. It's a number that identifies the message.
Processing the Messages
•Every message that a window procedure receives is identified
by a number, which is the message parameter to the window
procedure.
•Generally, Windows programmers use a switch and case
construction to determine what message the window procedure
is receiving and how to process it accordingly.
•When a window procedure processes a message, it should
return 0 from the window procedure.
Processing the Messages