Presentation is loading. Please wait.

Presentation is loading. Please wait.

Introduction To GDI GDI Definition : It is a interface present in windows which provide function and related structures that an application can use to.

Similar presentations


Presentation on theme: "Introduction To GDI GDI Definition : It is a interface present in windows which provide function and related structures that an application can use to."— Presentation transcript:

1 Introduction To GDI GDI Definition : It is a interface present in windows which provide function and related structures that an application can use to generate graphical output for displays, printers and other devices GDI Function for Dispalying a text in client Area: 1 ) TextOut()  write character string to client area 2 ) DrawText()  draws formatted text in specified rectangle int DrawText(hdc, lpString, nCount, lpRect, uFormat ) Device Context: It is a data structure maintained internally by GDI.it is associated with particular display device such as printer DC are graphic attributes(how GDI drawing functions work) for TextOut the DC are Text color, background Color, x&y coordinates,font for text

2 Handle to DC : when program needs to paint it must first obtain the handle.windows fills internal device context structure with attribute values (processing of each message) Getting Device Context Handle: Method 1: (WM_PAINT msg) 2 functions  BeginPaint and EndPaint require handle to window and address of a structure varible of PAINT STRUCT (WINUSER.H) PAINTSTRUCT ps; BeginPaint()  validates invalid region and fills the fields of ps structure.the return value is device context handle.in program it is saved with name hdc EndPaint()  release the device context handle ps structure have following information in it PAINTSTRUCT { HDC hdc ; BOOL fErase; RECT rcPaint ; BOOL fRestore; BOOL fIncUpdate ; BYTE rgbreserved[32] ;}

3 Method 2: GetDC() and ReleaseDC() GetDC()  to get the Device Context ReleaseDC()  to release the device context The handle returned from GetDC has clipping rectangle equal to entire client area so,it is possible to paint on any part of client area. GetDC does not validate any invalid region.if the entire client area need to validate then ValidateRect() called Both function are respond to keyboard/ mouse message Scroll Bars : Display anything that requires more space than is available in window client area Vertical and horizontal (arrow mark/thumb) WS_VSCROLL/WS_HSCROLL Scroll Bar Range and Position Scroll bar Range  minimum value and maximum associated with it Position  the location of thumb within the range

4 By default the range for scroll bar 0 through 100 to change this setting the function is called SetScrollRange(hwnd,iBar,iMin,iMax,bRedraw); iBar  SB_VERT / SB_HORZ iMin and iMax  new minimum and maximum position of range bRedraw  set to TRUE redraw the scroll bar for new dimension The thumb position is always a discrete integral value.the below syntax is used to set a new thumb position within scroll bar range SetScrollPos(hwnd, iBar, iPos, bRedraw) iPos  new position for thumb (GetScrollRange and GetScrollPos)

5 Window’s responsibilities for Scroll bar :  Handle all process of mouse msg to scroll bar  provide reverse video flash when user click the scroll bar  Move the thumb as user drag thumb within scrollbar  Send scroll bar msg to window procedure of window that contain scroll bar Program Responsibilities : Intialilze range and position of scrollbar Process scroll bar message to window procedure Update position of scroll bar thumb Change contents of client area inresponse to change in scrollbar

6 Scroll Messages : Windows sends the WM_VSCROLL / WM_HSCROLL to WndProc when mouse / thumb action triggered.(2 actions for mouse). They are accompanied by wParam and lParam wParam are divided into two low word and high word. Low word  what the mouse is doing to scroll bar. this number is referred as notification code. SB_LINEUP, SB_LINEDOWN,SB_LINELEFT,SB_LINERIGHT, SB_PAGEUP,SB_PAGEDOWN,SB_PAGELEFT,SB_PAGERIGHT, SB_THUMBPOSITION, SB_THUMBTRACK, SB_ENDSCROLL At the time of position the mouse over scroll bar,the thumb is moved This generates msg with notification code SB_THUMBTRACK & SB_THUMBPOSITION When low word == SB_THUMBTRACK then high word == current position of scroll bar When low word == SB_THUMBPOSITION then high word == final position of scroll bar when user releasemouse (refer page num : 103 to 106 in charles petzold)

7 BASIC DRAWING GDI  several 100 functions & data types,macros and structures GDI PHILOSOPHY Graphics in windows is handled by functions in DLL. It call the routines in device drivers for video display & printers video driver access the h/w of video display. print driver convert GDI cmd into codes that understand by printers GDI must be support the “ device independent graphics “.the graphics output devices are divided into 2 groups 1. raster devices  rectangular pattern of dots 2. vector devices  draw images using lines GDI Function Calls * Function that get and release a device context * function that obtain information about device context * function that draw some information * function that set and get attributes of device context * function that work with GDI object (create Pen)

8 GDI PRIMITIVES The types of graphics which display on the screen can themselves divided into several groups which are called as Primitives. * Lines and curves (foundation for any vector graphics) * Filled areas * Bitmaps * Text The following are the other GDI non classifiable GDI aspects * Metafiles  collection of GDI commands in binary forms * Region  complex area of any function (bool combination) * Clipping  drawing restriction to particular area * paths  collection of straight lines & curves stored internally * Mapping modes and transform * Palettes

9 Drawing Dot and Lines Graphic device driver needs two function for drawing 1. SetPixel(hdc,x,y,crColor); 2. crColor=GetPixel(hdc,x,y); Drawing Straight Lines: windows 98 support 7 function for line drawings LineTo, Polyline & PolylineTo, PolyPolyline,Arc,PolyBezier & PolyBezierTo three additional functions in Windows NT ArcTo & AngleArc, polyDraw Following function draw lines and fill the enclosed area Rectangle, Ellipse,RoundRect, Pie,Chord 5 attributes of DC affect the appearance of the line drawing are: Current pen position pen Background Mode Background color Drawing mode

10 To draw a straight line we require two functions 1 st function specify point at which line begins MoveToEx(hdc,xBeg,yBeg,NULL) 2 nd function specify end point of the line LIneTo(hdc,xEnd,yEnd) To draw Polyline When there is array of points that has tobe connected with lines then polyline() may used POINT apt[5] ={50,50,100,50,100,100,50,100,50,50} Polyline(hdc,apt,5) Polyline doesn’t change / use current position To draw PolylineTo PolylineTo use current position for starting point and set it it to end of last line PolylineTo(hdc,apt+1,4);

11 BOUNDING BOX FUNCTIONS To Draw Rectangle bRectangle(hdc,xLeft,yTop,xRight,yBottom); To Draw Ellipse Ellipse(hdc,xLeft,yTop,xRight,yBottom); To Draw Round Rectangle RoundRect(hdc,xLeft,yTop,xRight,yBottom,xCornerEllipse,yCornerEllipse);

12 To Draw Arc Arc(hdc,xLeft,yTop,xRight,yBottom,xStart,yStart,xEnd,yEnd) To Draw Chord Chord(hdc,xLeft,yTop,xRight,yBottom,xStart,yStart,xEnd,yEnd) To Draw Pie Pie(hdc,xLeft,yTop,xRight,yBottom,xStart,yStart,xEnd,yEnd)


Download ppt "Introduction To GDI GDI Definition : It is a interface present in windows which provide function and related structures that an application can use to."

Similar presentations


Ads by Google