Presentation Outline Introduction Painting and Repainting GDI.

Slides:



Advertisements
Similar presentations
Interaction Design: Visio
Advertisements

 2001 Prentice Hall, Inc. All rights reserved. 1 Chapter 7 - JavaScript: Introduction to Scripting Outline 7.1 Introduction 7.2 Simple Program: Printing.
Foundation Level Course
PowerPoint. Getting Started with PowerPoint Objectives Start PowerPoint and open presentations Explore toolbars and menus Use the Office Assistant Work.
IS 1181 IS 118 Introduction to Development Tools VB Chapter 06.
Creating Custom Forms. 2 Design and create a custom form You can create a custom form by modifying an existing form or creating a new form. Either way,
1 of 6 This document is for informational purposes only. MICROSOFT MAKES NO WARRANTIES, EXPRESS OR IMPLIED, IN THIS DOCUMENT. © 2007 Microsoft Corporation.
Automating Tasks With Macros. 2 Design a switchboard and dialog box for a graphical user interface Database developers interact directly with Access.
Graphics and Multimedia. Outline Introduction Graphics Contexts and Graphics Objects Color Control.
Event Handling. In this class we will cover: Keyboard Events Mouse Events Focus Events Action Interface Multicasting.
Intro to Windows Programming Basic Ideas. Program Entry Point Int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)
Chapter 5 Using Business Information Sets
Graphics and Multimedia. Introduction The language contains many sophisticated drawing capabilities as part of namespace System.Drawing and the other.
Using Draw Tools C 2012jkc. Click File on the menu bar and select Page Setup on the drop- down menu to get the Page Setup dialog box. Under the Margins.
Chapter 3 Introduction to Event Handling and Windows Forms Applications.
WORKING WITH MACROS CHAPTER 10 WORKING WITH MACROS.
Saving and Loading Simple Text Files A sequential file stores characters one after the other like songs on a cassette tape. New characters are added to.
Tutorial 6 Using Form Tools and Creating Custom Forms
Microsoft Excel 2000 Adding Visual Elements and Managing Files.
Microsoft PowerPoint Getting Started Guide Prepared for Towson University Dr. Jeff M. Kenton Amy Chase Martin 2007.
Chapter 6 Advanced Report Techniques
Introduction to Matlab & Data Analysis
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Typing Application Introducing Keyboard Events, Menus, Dialogs and the Dictionary.
Prepared by Fareeha Lecturer DCS IIUI 1 Windows API.
Overview of Previous Lesson(s) Over View  Visual C++ provides us with 3 basic ways of creating an interactive Windows application  Using the Windows.
Chapter 1: Hello, MFC Windows Programming Model Department of Digital Contents Sang Il Park.
Chapter 1: Hello, MFC Your first MFC Application Department of Digital Contents Sang Il Park.
Windows Programming Text and Fonts This presentation will probably involve audience discussion, which will create action items. Use PowerPoint to keep.
© Paradigm Publishing Inc. MICROSOFT WINDOWS XP MAINTAINING FILES AND CUSTOMIZING WINDOWS Section 2.
BZUPAGES.COM Visual Programming Lecture – 2 Miss. SADAF MAJEED SIAL Computer Science Department Bahauddin Zakariya University Multan.
Datasheets III: Make data easier to read by formatting columns and rows Overview: Data clarity A datasheet is a grid of rows and columns that displays.
1 Windows GDI Programming CIS 487/587 Bruce R. Maxim UM-Dearborn.
Creating Graphical User Interfaces (GUI’s) with MATLAB By Jeffrey A. Webb OSU Gateway Coalition Member.
Microsoft Access 2010 Chapter 8 Advanced Form Techniques.
Introduction to Microsoft publisher
Microsoft Publisher 2010 Chapter 1 Creating a Flyer.
Chapter2: Drawing a Window. Review: Introducing MFC.
Visual Basic Programming Introduction VB is one of the High level language VB has evolved from the BASIC language. BASIC stands for Beginners All-purpose.
Quanta Confidential QUANTA WBU Study Report 1 昭正 2008/08/01.
Lesson: 2 Common Features and Commands After completing this lesson, you will be able to: Identify the main components of the user interface. Identify.
Chapter2: Drawing a Window
Adobe Photoshop CS5 Chapter 1 Editing a Photo. Start Photoshop and customize the Photoshop workspace Open a photo Identify parts of the Photoshop workspace.
GAM666 – Introduction To Game Programming ● DirectDraw, the 2D component of DirectX, uses the term “surface” to mean an area of memory in which pixel data.
®® Microsoft Windows 7 Windows Tutorial 7 Managing Multimedia Files.
Learning Programming Windows API Morpheus Feb-28, 2008.
PhotoShop Creative Suite 3 Chapter 1 The Work Area.
Overview of Previous Lesson(s) Over View  Windows Programming  WinMain()  Where execution of the program begins and basic program initialization is.
 2002 Prentice Hall. All rights reserved. 1 Introduction to the Visual Studio.NET IDE Outline Introduction Visual Studio.NET Integrated Development Environment.
Adobe ® Photoshop ® CS6 Chapter 1 Editing a Photo.
Drawing in Windows. To help with drawing on the Windows operating system, Microsoft created the Graphical Device Interface, abbreviated as GDI. – It is.
Introduction To GDI GDI Definition : It is a interface present in windows which provide function and related structures that an application can use to.
Windows Programming Lecture 14. WM_PAINT message Whenever an application receives the WM_PAINT message, whether the entire window needs repainting? WM_PAINT.
Presentation Outline Introduction Painting and Repainting GDI.
An Introduction to Computers and Visual Basic
Windows Programming Lecture 09.
Windows Programming Model
Graphics and Multimedia
An Introduction to Computers and Visual Basic
Chapter 1 Editing a Photo
Windows Development Dynadata Copyright, 2014 © DynaData S.A. 1/10.
Queued and Nonqueued Messages
Windows Controls & Concepts
Made by Aistė Augustinaitė Software Engineering 3 group
Graphic Device Interface
Windows Programming Lecture 13
CS 1253 Visual Programming Unit I Windows Environment
An Introduction to Computers and Visual Basic
Windows Development Dynadata Copyright, 2014 © DynaData S.A. 1/10.
Chapter 14 Drawing in a Window
MAINTAINING FILES AND CUSTOMIZING WINDOWS Section 2
Presentation transcript:

Presentation Outline Introduction Painting and Repainting GDI

Introduction Client area is the part of the window on which a program is free to draw and deliver visual information to the user. When a program displays text or graphics in its client area, it is often said to be "painting" its client area.

Painting and Repainting (2) Windows is a message-driven system. Windows informs applications of various events by posting messages in the application's message queue or sending messages to the appropriate window procedure. Windows informs a window procedure by posting a WM_PAINT message.

The WM_PAINT Message A window procedure receives a WM_PAINT message whenever one of the following events occurs:  hidden area of the window is brought into view when a user moves a window or uncovers a window.  The user resizes the window (if the window class style has the CS_HREDRAW and CW_VREDRAW bits set).  The program uses the InvalidateRect or InvalidateRgn function to explicitly generate a WM_PAINT message.

The WM_PAINT Message (2) Windows may sometimes post a WM_PAINT message when:  Windows removes a dialog box or message box that was overlaying part of the window.  A menu is pulled down and then released.  A tool tip is displayed.

The WM_PAINT Message (2) In a few cases, Windows always saves the area of the display it overwrites and then restores it. This is the case whenever:  The mouse cursor is moved across the client area.  An icon is dragged across the client area.

Valid and Invalid Rectangles Repainting is required only for the rectangular area uncovered when the dialog box is removed. That area is known as an "invalid region" or "update region." The presence of an invalid region in a client area is what prompts Windows to place a WM_PAINT message in the application's message queue. Your window procedure receives a WM_PAINT message only if part of your client area is invalid.

Valid and Invalid Rectangles(2) Windows internally maintains a "paint information structure" for each window. This structure contains, among other information, the coordinates of the smallest rectangle that encompasses the invalid region. This is known as the "invalid rectangle.“ Windows does not place multiple WM_PAINT messages in the message queue.

Valid and Invalid Rectangles(3) InvalidateRect. GetUpdateRect BeginPaint ValidateRect

An Introduction to GDI To paint the client area of your window, we use Windows Graphics Device Interface (GDI) functions. Windows provides several GDI functions for writing text strings to the client area of the window TextOut (hdc, x, y, psText, iLength) ; TextOut writes a character string to the client area of the window.  The psText argument is a pointer to the character string, and  iLength is the length of the string in characters.  The x and y arguments define the starting position of the character string in the client area.  The hdc argument is a "handle to a device context"

The Device Context The device context is a data structure maintained internally by GDI. A device context is associated with a particular display device, such as a video display or a printer. Some of the values in the device context are graphics "attributes." These attributes define some particulars of how GDI drawing functions work. With TextOut,  the color of the text,  the color of the text background,  font for the text to be displayed

The Device Context When a program needs to paint, it must first obtain a handle to a device context. Windows fills the internal device context structure with default attribute values. You can change these defaults by calling various GDI functions. After a program has finished painting its client area, it should release the device context handle.

Getting a Device Context Handle: You use this method when you process WM_PAINT messages. Two functions are involved: BeginPaint and EndPaint. These two functions require the handle to the window and the address of a structure variable of type PAINTSTRUCT PAINTSTRUCT ps ; While processing a WM_PAINT message, the window procedure first calls BeginPaint. The BeginPaint function generally causes the background of the invalid region to be erased in preparation for painting. The function also fills in the fields of the ps structure. The value returned from BeginPaint is the device context handle. HDC hdc ;

Getting a Device Context Handle: The HDC data type is defined as a 32-bit unsigned integer. The program may then use GDI functions, such as TextOut, that require the handle to the device context. A call to EndPaint releases the device context handle. case WM_PAINT: hdc = BeginPaint (hwnd, &ps) ; [use GDI functions] EndPaint (hwnd, &ps) ; return 0 ;

The Paint Information Structure Windows maintains a paint information structure for each window. typedef struct tagPAINTSTRUCT { HDC hdc ; BOOL fErase ; RECT rcPaint ; BOOL fRestore ; BOOL fIncUpdate ; BYTE rgbReserved[32] ; } PAINTSTRUCT ;

The Paint Information Structure Windows fills in the fields of this structure when your program calls BeginPaint. Program can use only the first three fields. The others are used internally by Windows. wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ;

The boundaries of the invalid rectangle.

Getting a Device Context Handle: Method Two To get a handle to the device context of the client area of the window, you call GetDC to obtain the handle and ReleaseDC after you're done with it hdc = GetDC (hwnd) ; [use GDI functions] ReleaseDC (hwnd, hdc) ;

TextOut: The Details TextOut is the most common GDI function for displaying text. Its syntax is TextOut (hdc, x, y, psText, iLength) ; The attributes of the device context control the characteristics of this displayed text. For instance, one attribute of the device context specifies the text color. The default color (we discover with some degree of comfort) is black. The default device context also defines a text background color, and this is white. When a program writes text to the display, Windows uses this background color to fill in the rectangular space surrounding each character, called the "character box."

The System Font The device context also defines the font that Windows uses when you call TextOut to display text. The default is a font called the "system font" or (using the identifier in the WINGDI.H header file) SYSTEM_FONT. The system font is the font that Windows uses by default for text strings in title bars, menus, and dialog boxes.

Text metrics Windows copies the various values of text metrics into a structure of type TEXTMETRIC defined in WINGDI.H. The TEXTMETRIC structure has 20 fields, but we're interested in only the first seven: typedef struct tagTEXTMETRIC { LONG tmHeight ; LONG tmAscent ; LONG tmDescent ; LONG tmInternalLeading ; LONG tmExternalLeading ; LONG tmAveCharWidth ; LONG tmMaxCharWidth ; [other structure fields] }TEXTMETRIC, * PTEXTMETRIC ;

Text metrics

Formatting Text case WM_CREATE: hdc = GetDC (hwnd) ; GetTextMetrics (hdc, &tm) ; cxChar = tm.tmAveCharWidth ; cyChar = tm.tmHeight + tm.tmExternalLeading ; ReleaseDC (hwnd, hdc) ; return 0 ;

Use of Textout int iLength ; TCHAR szBuffer [40] ; [ other program lines ] iLength = wsprintf (szBuffer, TEXT ("The sum of %i and %i is %i"), iA, iB, iA + iB) ; TextOut (hdc, x, y, szBuffer, iLength) ; Combine the two statements into one: TextOut (hdc, x, y, szBuffer, wsprintf (szBuffer, TEXT ("The sum of %i and %i is %i"),iA, iB, iA + iB)) ;