Presentation is loading. Please wait.

Presentation is loading. Please wait.

Prepared by Fareeha Lecturer DCS IIUI 1 Windows API.

Similar presentations


Presentation on theme: "Prepared by Fareeha Lecturer DCS IIUI 1 Windows API."— Presentation transcript:

1 Prepared by Fareeha Lecturer DCS IIUI 1 Windows API

2 Lecture 22 What is Window API API Stands for Application Programming Interface Set of Functions that are part of Windows OS Program created by calling Functions present in APIs Internal of functions don’t have to be known All API functions contained in DLL

3 Lecture 23 Types of Window API Two basic varieties –API for 16-bit windows (Win16 API) –API for 32-bit windows (Win32 API) Both are almost same Win16 API is subset of Win32 API

4 Lecture 24 Core Components of APIs Win16 APIWin32 API USER.EXEUSER.DLL Responsible for window management, including messages, menus, cursor GDI.EXEGDI.DLL Graphical device interface KRNL386.EXEKRNL386.DLL Handles low level functions In Win16 extension is.EXE but actually all are DLLs.

5 Lecture 25 Win32 API Programming Event-driven, graphics oriented Example: User clicks mouse over a program’s window area— – Windows decodes HW signals from mouse – figures out which window user has selected – sends a message to that window’s program:

6 Lecture 26 "User has clicked over (X,Y)” "Do something and return control to me” – Program reads message data, does what's needed, returns control to Windows

7 Lecture 27 Events occur in response to –Message being passed between windows –User interaction with OS and application EDM is similar to heart, Message loop. Message loop is While loop() Windows provide Message Queue for each process

8 Lecture 28 Win32 API Program Structure--2 main tasks: Initial activities –Creating program own window –Startup activities Process messages from Windows (the message loop)

9 Lecture 29 PSEUDOCODE Initialize variables, memory space Create & show program's Window Loop – Fetch any msg sent from Windows to this pgm – If message is QUIT terminate program, return control to Windows – If message is something else take actions based on message & parameters return control to Windows End Loop

10 Lecture 210 Essential Parts of a Windows Programming The source program (.c/.cpp file): – A. WinMain() function Entering point of window application Like main() Windows searches it at run time

11 Lecture 211 Functions performed by WinMain() 1.Declarations, initialization, etc. Program window declare through Window Class Structure (WNDCLASS) which define class icon, cursor shape, background color, either want Menu Resource, Window class name 2.register window class Pass window settings to operating system OS assign ID to this program window so that OS can send message to correct window

12 Lecture 212 Functions performed by WinMain() 3.create a window based on a registered class 4.show window 5.Create a message loop  get messages from Windows (send to application queue)  dispatch back to Windows for forwarding to correct callback message-processing function Message Queue Windows provided area for holding yours application's messages All messages sent by Windows are stored in queue until called for

13 Lecture 213 Types of Messages Queued Messages –Caused by user Input from either mouse or Keyboard –Windows places them in queue –WinMain() extract them from queue for processing Non-Queued Messages –Concerned with windows management –Handle by Windows itself

14 Lecture 214 The Message Loop Every thing in Windows happen in response to message Standard Mechanism for retrieving messages from message Queue while( GetMessage( &msg, NULL, 0, 0 ) ) { TranslateMessage( &msg ); DispatchMessage( &msg ); } Program must keep checking for messages Retrieve a message from message queue OS Fills MSG struct msg ID value. data passed in msg more data in msg time msg was sent mouse cursor position (x,y) when message was posted

15 Lecture 215 B. WndProc(): the msg-processing function. The Window Procedure "callback" function (called by Windows) Handle message for particular window Should contain a switch/case statement : – Looks at message ID of current message – Acts appropriately on "interesting" messages – Handle all queued messages – Forwards other messages (non queued) to default Window procedure--DefWindowProc()

16 Lecture 216 Some Important Messages WM_COMMAND--User clicked on menu item (Param) = menu item ID WM_*BUTTONDOWN--left/right mouse button pressed (* = L or R, lParam=x,y coordinates) WM_MOUSEMOVE--mouse moved (lParam=x,y coords) WM_PAINT--Part of window was exposed & should be redrawn WM_KEYDOWN--keyboard key pressed (wParam= virtual key code)


Download ppt "Prepared by Fareeha Lecturer DCS IIUI 1 Windows API."

Similar presentations


Ads by Google