Chapter2: Drawing a Window. Review: Introducing MFC.

Slides:



Advertisements
Similar presentations
Windows Test Review.
Advertisements

Microsoft® Small Basic
The Operating System. What is an Operating System? The program that is loaded first and manages the hardware resources like main memory, backing storage.
C HAPTER 12 A Very Graphic Story. O VERVIEW Simple GUI Getting User Input Creating a Listener ActionEvents Displaying Graphics Drawing Multiple Buttons.
Lecture 2Slide 1 Event Driven Computing Basic Interaction Handling –Interactive programs - must pay attention to the user interface.
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 1- Visual Basic Schneider 1 Chapter 1 An Introduction to Computers and Visual Basic.
Introduction to Microsoft Windows MFC Programming: the Application/Window Approach Lecture 4.
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.
Lesson 4 Computer Software
Section 2.1 Identify hardware Describe processing components Compare and contrast input and output devices Compare and contrast storage devices Section.
Chapter Three Software and Operating Systems What is software? How software is developed (Analysis, Design, Programming, and Testing) What are software.
Operating Systems What do you have left on your computer after you strip away all of the games and application programs you bought and installed? Name.
© Paradigm Publishing Inc. 4-1 Chapter 4 System Software.
Lesson 6 Operating Systems and Software
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.
CS 0004 –Lecture 1 Wednesday, Jan 5 th, 2011 Roxana Gheorghiu.
Chapter 4 System Software.
Building an MFC Application Using the Wizard. Terms Solution – A container for related projects – An executable or DLL – May be constructed from multiple.
11.10 Human Computer Interface www. ICT-Teacher.com.
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.
Java Programming: From Problem Analysis to Program Design, Second Edition1  Learn about basic GUI components.  Explore how the GUI components JFrame,
Developing the Game User Interface (UI) Lesson 5.
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.
XP New Perspectives on Windows XP Tutorial 1 Exploring the Basics.
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.
Lab 6: event & input intro User Interface Lab: GUI Lab Oct. 2 nd, 2013.
Chapter2: Drawing a Window. Drawing with the GDI.
Introducing… Microsoft Windows VISTA Introducing… Microsoft Windows VISTA.
BIM211 – Visual Programming Interacting with Users Graphics 1.
OPERATING SYSTEM - program that is loaded into the computer and coordinates all the activities among computer hardware devices. -controls the hardware.
Presentation Outline Introduction Painting and Repainting GDI.
X-WindowsP.K.K.Thambi The X Window System Module 5.
Bitmap (Chapter 15).
© Paradigm Publishing, Inc. 4-1 Chapter 4 System Software Chapter 4 System Software.
Chapter2: Drawing a Window
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 4: Events Programming with Alice and Java First Edition by John Lewis.
Computer Parts There are many parts that work together to make a computer work.
The desktop (overview) Working with desktop icons The desktop is the main screen area that you see after you turn on your computer and log on to Windows.
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.
Hardware/Software Basics Test Get out your DIY Test Review.
Chapter 6 Graphical User Interface (GUI) and Object-Oriented Design (OOD)
Chapter2: Drawing a Window. Drawing with the GDI.
12-Jun-16 Event loops. 2 Programming in prehistoric times Earliest programs were all “batch” processing There was no interaction with the user Input Output.
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.
Microsoft Foundation Classes MFC
Section 2.1 Section 2.2 Identify hardware
Presentation Outline Introduction Painting and Repainting GDI.
Event Loops and GUI Intro2CS – weeks
Event-driven programming
Event loops 16-Jun-18.
Event Driven Programming
Windows Development Dynadata Copyright, 2014 © DynaData S.A. 1/10.
Queued and Nonqueued Messages
Windows Controls & Concepts
Event loops.
Windows Programming Lecture 13
Event loops 17-Jan-19.
Event loops 17-Jan-19.
Event loops 8-Apr-19.
Event loops.
Chapter 14 Drawing in a Window
Event loops.
Event loops 19-Aug-19.
Presentation transcript:

Chapter2: Drawing a Window

Review: Introducing MFC

Look into the codes classes

Our Simple Code Structure myApp (CMyApp : CWinApp) m_pMainFrame (CMainWindow : CFrameWnd) Program itself Running message loop “Look” of the application Taking care of the user interactions

The big picture The Main function is hidden in MFC. CMyApp is the program which initializes the windows and runs the message loop. CMinWindow is included in CMyApp which is the “look” of the window and processes the messages regarding to Input/Output. MFC simplifies the coding work.

Chapter 2: Drawing a Window

Before Windows… In 1980s, before the birth of the “windows 95” –MS-DOS (Disk Operating System) –Graphics Card: CGA(4colors)/EGA(16colors)/VGA(256colors) A game using CGA graphics cardCGA graphics card DOS did not take care of graphics A game company took care of the graphics drivers

Before Windows… In 1980s, before the birth of the “windows 95” –MS-DOS (Disk Operating System) –Graphics Card: DOS does not take care of graphics A game company took care of the graphics drivers Too complicated, so people started to think about “Device-Independent”

9 Two big things of Windows TM Changes after windows –Multi-tasking We can run Multiple applications at the same time Windows controls and distributes its resources to the application. –Device-independent Windows controls the input and outputs. Applications only communicate with Windows and do not directly access to the actual hardwares.

10 Issues when drawing Because of the multi-tasking –An application takes just a part of the window: the position and the size of the window can change –Multiple applications can run at the same time: There will be overlapping. One is hiding the other

Chapter 2: Drawing a Window The Windows GDI

12 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. ApplicationsGDI Output Hardwares (Monitor or printer) Devide- Independent Device- Dependent

13 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) CDC: MFC Device Context Class A package for displaying: (physical hardware information, Many functions for drawing) ≒ A canvas and tools ready to draw

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

15 Various kinds of Device Context Class NameDescription CPaintDCFor drawing in a window's client area (OnPaint handlers only) CClientDCFor drawing in a window's client area (anywhere but OnPaint) CWindowDCFor drawing anywhere in a window, including the nonclient area CMetaFileDCFor 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); } void CMainWindow::OnPaint() { CPaintDC dc(this); dc.Rectangle(50,50,250,250); dc.Ellipse(100,100,200,200); }

WM_PAINT?? WM: Windows Message –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

18 WM_PAINT – Invalid Region When it is no longer valid:

19 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);

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

CPaintDC Practice Draw rectangles:

Code Practice 1 1.Draw a small rectangle 2.Enlarge the size of the rectangle when the left mouse button is clicked 3.Reduce the size of the rectangle when the right mouse button is clicked

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

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