Chapter2: Drawing a Window

Slides:



Advertisements
Similar presentations
Windows Basics An Introduction to the Windows Operating System.
Advertisements

Chapter 3 Creating a Business Letter with a Letterhead and Table
Using Macros and Visual Basic for Applications (VBA) with Excel
Programs/Algorithms.  Computer Architecture  What is a computer program?  Flow chart  Data states  Data  Variables  History – Why VB?  Procedural.
User Interface Programming in C#: Graphics
Lab 5 Signal Analyzer/Generator. Introduction  Create a client MFC application that samples a signal and displays wave using Windows GDI, Open GL, or.
Chapter 13: Advanced GUIs and Graphics J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design, Second Edition.
Chapter 3 Introduction to Event Handling and Windows Forms Applications.
1 Windows Printing. 2 Objectives You will be able to Output text and graphics to a printer. Print multipage documents. Use the standard Windows print.
Slide 1 Chapter 2 Visual Basic Interface. Slide 2 Chapter 2 Windows GUI  A GUI is a graphical user interface.  The interface is what appears on the.
Section 2.1 Identify hardware Describe processing components Compare and contrast input and output devices Compare and contrast storage devices Section.
Computer Programming and Basic Software Engineering 9 Building Graphical User Interface A Brief Introduction to GDI+ S.R.G. Fraser, Pro Visual C++/CLI.
Chapter 13 Advanced GUIs and Graphics. Chapter Objectives Learn about applets Explore the class Graphics Learn about the class Font Explore the class.
Bertrand Bellenot ROOT Users Workshop Mar ROOT GUI Builder Status & Plans ROOT & External GUI World MFC, FOX, Qt, PVSS… Snapshot of the Future.
1 Chapter 15 Drawing in a Window. 2 The Window Client Area  A coordinate system that is local to the window.  It always uses the upper-left corner of.
Building an MFC Application Using the Wizard. Terms Solution – A container for related projects – An executable or DLL – May be constructed from multiple.
© 2006 Lawrenceville Press Slide 1 Chapter 3 Visual Basic Interface.
CSC 298 Windows Forms.
Visual C++ Lecture 11 Friday, 29 Aug Windows Graphic User Interface l Event driven programming environment l Windows graphic libraries (X11 on Unix,
Java Programming: From Problem Analysis to Program Design, 4e Chapter 12 Advanced GUIs and Graphics.
Visual Basic 2005 CHAPTER 2 Program and Graphical User Interface Design.
Developing the Game User Interface (UI) Lesson 5.
Macromedia Dreamweaver 4.0 INTERFACE This presentation will run automatically.
Chapter 1: Hello, MFC Your first MFC Application Department of Digital Contents Sang Il Park.
MFC Windows Programming: Document/View Approach More detailed notes at: 360/notes-html/class15.htm.
Microsoft Foundation Classes. What is MFC? Set of C++ classes written by MS Simplifies writing complex programs Covers many areas: – GUI – I/O – O/S interfaces.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved CheckWriter Application Introducing Graphics and Printing.
Chapter2: Drawing a Window. Drawing with the GDI.
1 Windows GDI Programming CIS 487/587 Bruce R. Maxim UM-Dearborn.
Chapter 3 The mouse and the Keyboard. Getting input from the Mouse.
Assign one variable to each group of radio buttons To do this, assign one integer variable to the first radio button in each group. All the subsequent.
Microsoft Access 2010 Chapter 8 Advanced Form Techniques.
User Interface Programming in C#: Direct Manipulation Chris North CS 3724: HCI.
Presentation Outline Introduction Painting and Repainting GDI.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Tutorial 21 - “Cat and Mouse” Painter Application.
Bitmap (Chapter 15).
The Abstract Window Toolkit (AWT) supports Graphical User Interface (GUI) programming. AWT features include: a rich set of user interface components; a.
Visual Basic CDA College Limassol Campus Lecture:Pelekanou Olga Semester C Week - 1.
Chapter2: Drawing a Window. Review: Introducing MFC.
Chapter 8 Dialog Boxes and Property Sheet. 2 Two kinds of dialog boxes Dialog boxes –Modal dialog When appear, it takes all ownership of input. It disables.
Microsoft Visual Basic 2010 CHAPTER TWO Program and Graphical User Interface Design.
Chapter 7 Controls. 2 Introduction (1/4) Control –Special kind of window –Designed to convey information to the user or to acquire input –Reduce the tedium.
School of Computing and Information Systems RIA Animation, part I.
Chapter 6: FILE I/O and Serialize CFile class. FILE I/O Serialization and the CArchive Class.
Chapter 7 Controls. List box control 3 List Box Control(1/8) Listbox control: –Display lists of text strings called items –Optionally sort the items.
Chapter 14 Timers and Idle Processing Department of Digital Contents Sang Il Park.
 2002 Prentice Hall. All rights reserved. 1 Introduction to the Visual Studio.NET IDE Outline Introduction Visual Studio.NET Integrated Development Environment.
Chapter2: Drawing a Window. Drawing with the GDI.
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.
Section 2.1 Section 2.2 Identify hardware
Programming windows with MFC Chapter 2 - Drawing in a Window
Presentation Outline Introduction Painting and Repainting GDI.
Steps to Build Frame Window Recipe Application
PYGAME.
Keyboard Input.
Chapter 13: Advanced GUIs and Graphics
Chapter 2 Visual Basic Interface
Queued and Nonqueued Messages
Windows Controls & Concepts
Made by Aistė Augustinaitė Software Engineering 3 group
Graphic Device Interface
Windows Programming Lecture 13
Extend Text Editor to Draw shapes
Steps to Build Frame Window Recipe Application
Chapter 14 Drawing in a Window
Advanced GUIs and Graphics
Chapter 16 Drawing in a Window
An Introduction to the Windows Operating System
Presentation transcript:

Chapter2: Drawing a Window

Chapter 2: Drawing a Window The Windows GDI

The Windows GDI GDI(Graphics Device Interface) A part of the Operating System. Translate the applications’ signals into the hardwares’ signal. Determine whether it is shown or not. Devide- Independent Applications GDI Output Hardwares (Monitor or printer) Device- Dependent

≒ A canvas and tools ready to draw GDI and Device Context Device Context (DC) Data structure for information about displaying It determines how to display in Multi-tasking GUI environment. CDC: MFC Device Context Class A package for displaying: (physical hardware information, Many functions for drawing) ≒ A canvas and tools ready to draw

How to draw in Windows Procedure (step-by-Step) Application: Requires Device Context Windows(GDI): Creates a DC and returns its handle Application: Draws on the DC Windows(GDI): Checks the availability and displays the drawing if possible Using pointer CDC* pDC = GetDC (); // require DC // Do some drawing ReleaseDC (pDC); // release D C or Using class CDC DC(this); // require DC // Do some drawing

Various kinds of Device Context Class Name Description CPaintDC For drawing in a window's client area (OnPaint handlers only) CClientDC For drawing in a window's client area (anywhere but OnPaint) CWindowDC For drawing anywhere in a window, including the nonclient area CMetaFileDC For drawing to a GDI metafile Class Hierarchy

Drawing test using PaintDC Where you should put your drawing code? In the WM_PAINT message handler == OnPaint() void CMainWindow::OnPaint() { CPaintDC dc(this); dc.Rectangle(50,50,250,250); dc.Ellipse(100,100,200,200); }

WM_PAINT?? WM: Windows Message WM_PAINT A set of the basic messages predefined by MFC Usually regarding to the creation/changing of the windows, mouse controlling, and keyboard typing WM_PAINT A signal from windows that it is time to update the screen: an “invalid region” happens When: A windows is popping up (when creating or maximizing) Another window which blocked the window is moving out. The user (or application) demands it

WM_PAINT – Invalid Region When it is no longer valid:

WM_PAINT from yourself You may need to update the screen when the contents change You can make Windows to send WM_PAINT message to your application Make the screen invalid == Invalidate void CWnd::Invalidate (BOOL bErase = TRUE);

Chapter 2: Drawing a Window Drawing with the GDI

Member functions of the CDC Drawing shapes Function name function Rectangle() Drawing a rectangle Ellipse() Drawing an ellipse (x1, y1) dc.Rectangle (x1, y1, x2, y2); dc.Ellipse (x1, y1, x2, y2); (x2, y2)

Code Practice When the left mouse button is clicked, Draw a rectangle at the position of the mouse click

How to add Windows Event Handler Using CMainWindow’s Properties window: Adding Window Messages

Drawing Functions of CDC (1/3) Point Same with the SetPixel, but it does not return the original color value. So it is more efficient. SetPixelV Set the given color value at the position and return the original color value at the position SetPixel Get the color value at the given position. GetPixel Description Name COLORREF color = dc.GetPixel (x,y); dc.SetPixelV(x,y, RGB(r,g,b));

COLORREF A data type for storing a color value 32 bit as 0x00rrggbb Macro function easy to use: COLORREF color = RGB(r,g,b); r = GetRValue (color); g = GetGValue (color); b = GetBValue (color); 16

Drawing test:

Drawing Functions of CDC (2/3) Drawing shapes Function name Description Rectangle() Drawing a rectangle Ellipse() Drawing an ellipse (x1, y1) dc.Rectangle (x1, y1, x2, y2); dc.Ellipse (x1, y1, x2, y2); (x2, y2)

void GetClientRect(CRect) How to get the window size? CRect : a class for storing a rectangle information member variables: bottom top right left CRect rect; GetClientRect(rect); (left, top) (right, top) (left, bottom) (right, bottom) http://msdn2.microsoft.com/ko-kr/library/zzs00fs6(VS.80).aspx

void GetClientRect(CRect) Practice: draw an ellipse fit to the client area CRect rect; GetClientRect(rect);

Drawing Functions of CDC (3/3) Drawing a Line Drawing a line from the original position to the given position LineTo() Move your pen to the given position MoveTo() Description Name (x1,y1) dc.MoveTo(x1,y1); dc.LineTo(x2,y2); (x2,y2)

Coding practice

Drawing a Text by using CDC Text-related functions Sets alignment parameters SetTextAlign() Sets the background color SetBkColor() Sets the text output color SetTextColor() Draws text in a formatting rectangle DrawText() Outputs a line of test at the position TextOut() Description Function Name dc.SetTextColor(RGB(255,0,0)); dc.SetBkColor(RGB(0,255,0)); dc.SetTextAlign(TA_CENTER); dc.TextOut(300,200,_T(“Sejong University”)); http://msdn2.microsoft.com/ko-kr/library/e37h9k5s(VS.80).aspx

Coding Test CRect rect; GetClientRect(rect); dc.SetTextColor(RGB(255,0,0)); dc.SetBkColor(RGB(255,255,0)); dc.DrawText(CString(_T(“Draw Text Test”)), &rect, DT_CENTER|DT_VCENTER|DT_SINGLELINE); dc.SetTextAlign(TA_CENTER); dc.TextOut(300,200,CString(_T("Welcome“)));

Coding Test CRect rect; GetClientRect(rect); dc.SetTextColor(RGB(255,0,0)); dc.SetBkColor(RGB(255,255,0)); dc.DrawText(CString(_T(“Draw Text Test”)), &rect, DT_CENTER|DT_VCENTER|DT_SINGLELINE); dc.SetTextAlign(TA_CENTER); dc.TextOut(300,200,CString(_T("Welcome“))); Output text Text Alignment The text will be placed in the rectangle x y Output text