Bitmap (Chapter 15).

Slides:



Advertisements
Similar presentations
Computer Basics Hit List of Items to Talk About ● What and when to use left, right, middle, double and triple click? What and when to use left, right,
Advertisements

Online Calculator Basic Word Processing Skills Computer Keyboard Skills Computer Mouse Skills Basic Computer Terminology Computer Mouse Skills “I really.
Region of Interest Ku-Yaw Chang Assistant Professor, Department of Computer Science and Information Engineering Da-Yeh University.
Week 3 C For Win Lecture :.  Mouse Message  Keyboard Message.
User Interface Programming in C#: Direct Manipulation Chris North CS 3724: HCI.
Office 2003 Post-Advanced Concepts and Techniques M i c r o s o f t Word Project 8 Working with Macros and Visual Basic for Applications (VBA)
Chapter 3 Introduction to Event Handling and Windows Forms Applications.
Chapter 3 Working with Symbols and Interactivity.
XP Tutorial 7 New Perspectives on Microsoft Windows XP 1 Microsoft Windows XP Working with Graphics Tutorial 7.
Hello World In C++ and Microsoft Visual C++. Directions to begin a project 1. Go to All Programs 2. Open Visual Studio C++ 3. Click on New Project 4.
Computer Programming and Basic Software Engineering 9 Building Graphical User Interface A Brief Introduction to GDI+ S.R.G. Fraser, Pro Visual C++/CLI.
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.
CIS—100 Chapter 15—Windows Vista 1. Parts of a Window 2.
1-1 OBJ Copyright 2003, Paradigm Publishing Inc. Dr. Joseph Otto Silvia Castaneda Christopher deCastro CSULA Macromedia Flash MX Introduction.
Visual C++ Lecture 11 Friday, 29 Aug Windows Graphic User Interface l Event driven programming environment l Windows graphic libraries (X11 on Unix,
© 2011 Delmar, Cengage Learning Chapter 3 Working with Symbols and Interactivity.
Overview of Previous Lesson(s) Over View  Visual C++ provides us with 3 basic ways of creating an interactive Windows application  Using the Windows.
Addison Wesley is an imprint of © 2010 Pearson Addison-Wesley. All rights reserved. Chapter 5 Working with Images Starting Out with Games & Graphics in.
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.
© 2010 Delmar, Cengage Learning Chapter 3: Working with Symbols and Interactivity.
© Paradigm Publishing Inc. MICROSOFT WINDOWS XP MAINTAINING FILES AND CUSTOMIZING WINDOWS Section 2.
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.
Chapter2: Drawing a Window. Drawing with the GDI.
BZUPAGES.COM Visual Programming Lecture – 2 Miss. SADAF MAJEED SIAL Computer Science Department Bahauddin Zakariya University Multan.
Laboratory Exercise # 9 – Inserting Graphics to Documents Office Productivity Tools 1 Laboratory Exercise # 9 Inserting Graphics to Documents Objectives:
RIGHT Mouse Button Formatting Cut Copy Paste Save LEFT Mouse Button MAIN BUTTON Single clicks Double clicks Drag Highlight.
In this activity, we are going to resize and move a window around the desktop with a mouse. 1Double-click the icon ‘My Computer’ to display its content.
Chapter 3 The mouse and the Keyboard. Getting input from the Mouse.
Microsoft Access 2010 Chapter 8 Advanced Form Techniques.
User Interface Programming in C#: Direct Manipulation Chris North CS 3724: HCI.
Chapter 7 Controls. Scroll bar control 3 Scroll bar control (1/3) Scroll bar codes (interfaces)
Presentation Outline Introduction Painting and Repainting GDI.
Lesson No: 6 Introduction to Windows XP CHBT-01 Basic Micro process & Computer Operation.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Tutorial 21 - “Cat and Mouse” Painter Application.
Object Oriented Programming Dr. Ennis-Cole CECS 5100.
Chapter2: Drawing a Window. Review: Introducing MFC.
Program 2 due 02/01  Be sure to document your program  program level doc  your name  what the program does  each function  describe the arguments.
Chapter 6: FILE I/O and Serialize CFile class. FILE I/O Serialization and the CArchive Class.
Chapter2: Drawing a Window
Microsoft Visual Basic 2010 CHAPTER TWO Program and Graphical User Interface Design.
Introduction to Word Processing.  Learn uses of word-processing software  Differentiate between typewriter and word- processing software  Explore various.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 3 Building an Application in the Visual Basic.NET Environment.
Chapter 6: FILE I/O and Serialize CFile class. FILE I/O Serialization and the CArchive Class.
Programming with Visual Studio MFC and OpenGL. Outline Creating a project Adding OpenGL initialization code and libraries Creating a mouse event Drawing.
Computer Science I Animations. Bouncing ball. The if statement. Classwork/homework: bouncing something. Compress and upload work to Moodle.
A lesson approach © 2011 The McGraw-Hill Companies, Inc. All rights reserved. a lesson approach Microsoft® Word 2010 © 2011 The McGraw-Hill Companies,
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.
PhotoShop Creative Suite 3 Chapter 1 The Work Area.
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.
 The clipboard is a temporary storage area  The cut or copy commands place information on the CLIPBOARD  There are two types of clipboards: – System.
Chapter 8. Copyright 2003, Paradigm Publishing Inc. CHAPTER 8 BACKNEXTEND 8-2 LINKS TO OBJECTIVES Delete, Move, Copy, and Paste Text Delete, Move, Copy,
Visual Info Processing Programming Guide
Chapter 16 (cont.) Drawing in a Window Using the Mouse
Steps to Build Frame Window Recipe Application
Chapter 17 Creating the Document and Improving the View
Visual Info Processing Programming Guide (More Details)
Windows Programming Lecture 09.
Jim Fawcett Derived from a presentation by Dmitri Volper Su ‘2001
An Introduction to Computers and Visual Basic
Chapter 5 The MFC Collection Classes
Windows Programming Lecture 13
DREAMWEAVER MX 2004 Chapter 3 Working with Tables
An Introduction to Computers and Visual Basic
Steps to Build Frame Window Recipe Application
Chapter 14 Drawing in a Window
Chapter 17 Creating the Document and Improving the View
Presentation transcript:

Bitmap (Chapter 15)

CBrush with bitmap A Brush defines how to fill a region Different kinds of the brush (by using different constructor) Various Brushes Example Solid brush: filling with a color CBrush brush(RGB(255, 0, 0)); Hatch brush: filling with a pattern CBrush brush(HS_DIAGCROSS, RGB(255, 0, 0)); Bitmap brush: filling with an image CBitmap bitmap; bitmap.LoadBitmap(IDB_BITMAP1); CBrush brush(&bitmap);

Bitmap? Represent an image as a set of dots(pixels)

How to use Bitmap in Visual studio Adding a bitmap in the resource view Include the header file “resource.h” before using #include "resource.h"

CBitmap CBitmap: a class for storing a bitmap Example: CBitmap bitmap; Resource ID CBitmap bitmap; bitmap.LoadBitmap(IDB_BITMAP1); CBrush brush(&bitmap); dc.SelectObject(&brush); dc.Rectangle(0,0,200,200);

CBitmap::GetBitmap( ) How to get the information about the bitmap: int CBitmap::GetBitmap (BITMAP* pBitMap) ; struct BITMAP { int bmType; int bmWidth; // width of the bitmap (pixel) int bmHeight; // height of the bitmap (pixel) int bmWidthBytes; BYTE bmPlanes; BYTE bmBitsPixel; LPVOID bmBits; };

CBitmap::GetBitmap( ) Example: CBitmap bitmap; bitmap.LoadBitmap(IDB_BITMAP1); BITMAP bmpinfo; bitmap.GetBitmap(&bmpinfo); CString str; str.Format(_T(“width = %d, height = %d\n”), bmpinfo.bmWidth, bmpinfo.bmHeight); dc.TextOut(100,100,str);

Display the bitmap directly Copy the image directly into the screen  Block Transfer Process: Original Device Context Preparing one more device context Draw image at the new DC Copy the new DC into the original DC

Display the bitmap directly Copy the image directly into the screen  Block Transfer Process: Original Device Context CPaintDC dc; Preparing one more device context CDC memDc; CDC::CreateCompatibleDC(..); Draw image at the new DC CDC::SelectObject(…); Copy the new DC into the original DC dc.BitBlt(…); Bit Block Transfer (BitBlt)

Example CPaintDC dc(this); CBitmap bitmap; bitmap.LoadBitmap(IDB_BITMAP1); BITMAP bmpInfo; bitmap.GetBitmap(&bmpInfo); CDC memDc; memDc.CreateCompatibleDC(&dc); memDc.SelectObject(&bitmap); dc.BitBlt(100, 100, bmpInfo.bmWidth, bmpInfo.bmHeight, &memDC, 0, 0, SRCCOPY);

(original device context) (new memory device context) Bit Block Transfer BitBlt Parameter for copy: SRCCOPY BOOL BitBlt (int x, int y, int nWidth, int nHeight, CDC* pSrcDC, int xSrc, int ySrc, DWORD dwRop) ; (original device context) pSrcDC (new memory device context) x y nWidth nHeight xSrc ySrc nWidth nHeight

Bit Block Transfer with stretching StretchBlt: BOOL StretchBlt (int x, int y, int nWidth, int nHeight, CDC* pSrcDC, int xSrc, int ySrc, int nSrcWidth, int nSrcHeight, DWORD dwRop) ; pSrcDC (new memory device context) ySrc nSrcWidth xSrc nSrcHeight (original device context) y nWidth x nHeight

More Advanced Drawing: Double Buffering

The Problems: Image displays while drawing Especially when using a slow computer It is blinking when redrawing When invalidating, it first erases the scene.

Double Buffering Using two Device Context 1. one for painting (Back Buffer) 2. the other for displaying (Front Screen Buffer)

Draw on Memory and Copy at once Process: 1. making a memory dc (CreateCompatibleDC) 2. preparing a bitmap for storing the image (CreateCompatibleBitmap) 3. Selecting bitmap (SelectObject) 4. Drawing 5. Copy the image into the original DC (BitBlt)  Draw on memory and Copy it at once: Double Buffering

Draw on Memory and Copy at once CPaintDC dc(this); CRect rect; GetClientRect(&rect); CDC memDC; memDC.CreateCompatibleDC(&dc); CBitmap bitmap; bitmap.CreateCompatibleBitmap(&dc,rect.Width(),rect.Height()); memDC.SelectObject(&bitmap); memDC.Rectangle(0,0,100,100); dc.BitBlt(0, 0, rect.Width(), rect.Height(), &memDC, 0, 0, SRCCOPY);

Double Buffering using bitmap Drawing is fast. Still blinking  Because it always erases when redrawing  Do nothing at the message handler “Erase background” Solution: Change the WM_ERASEBKGND message handler

WM_ERASEBKGND WM_ERASEBKGND: when erasing the screen

WM_ERASEBKGND handler WM_ERASEBKGND: when erasing the screen Do nothing here but return true BOOL CMainWindow::OnEraseBkgnd(CDC* pDC) { // TODO: Add your message handler code here and/or call default // return CWnd::OnEraseBkgnd(pDC); return true; }

Announcement Announcement about Homework #2 will be available at 9:00 PM TODAY Check the our homepage Due Date will be 2012/04/12 (Thursday)

Chapter 3 The mouse and the Keyboard

Getting input from the Mouse

Client-Area Mouse Messages Sent When WM_LBUTTONDOWN The left mouse button is pressed WM_LBUTTONUP The left mouse button is released WM_LBUTTONDBLCLK The left mouse button is double-clicked WM_MBUTTONDOWN The middle mouse button is pressed WM_MBUTTONUP The middle mouse button is released WM_MBUTTONDBLCLK The middle mouse button is double-clicked WM_RBUTTONDOWN The right mouse button is pressed WM_RBUTTONUP The right mouse button is released WM_RBUTTONDBLCLK The right mouse button is double-clicked WM_MOUSEMOVE The cursor is moved over the client area

Client-Area Mouse Messages Messages for Mouse Events When clicking Left button Clicking and Dragging When moving Double clicking WM_MOUSEMOVE WM_LBUTTONDOWN WM_LBUTTONDOWN WM_LBUTTONDOWN WM_MOUSEMOVE WM_LBUTTONUP WM_MOUSEMOVE WM_LBUTTONUP WM_MOUSEMOVE WM_MOUSEMOVE WM_LBUTTONDBLCLK WM_MOUSEMOVE WM_MOUSEMOVE WM_LBUTTONUP WM_MOUSEMOVE WM_LBUTTONUP

Client-Area Mouse Messages Message-map macros and Message handlers Message WM_LBUTTONDOWN WM_LBUTTONUP WM_LBUTTONDBLCLK WM_MBUTTONDOWN WM_MBUTTONUP WM_MBUTTONDBLCLK WM_RBUTTONDOWN WM_RBUTTONUP WM_RBUTTONDBLCLK WM_MOUSEMOVE Message-Map Macro ON_WM_LBUTTONDOWN() ON_WM_LBUTTONUP() ON_WM_LBUTTONDBLCLK() ON_WM_MBUTTONDOWN() ON_WM_MBUTTONUP() ON_WM_MBUTTONDBLCLK() ON_WM_RBUTTONDOWN() ON_WM_RBUTTONUP() ON_WM_RBUTTONDBLCLK() ON_WM_MOUSEMOVE() Handling function OnLButtonDown OnLButtonUp OnLButtonDblClk OnMButtonDown OnMButtonUp OnMButtonDblClk OnRButtonDown OnRButtonUp OnRButtonDblClk OnMouseMove

How to add the event handler Using “Properties” window of CMainWindow

Mouse Message Handler Prototype of the Handler function: nFlags Status of the mouse buttons and the Shift and Ct기 key at the time when the message was generated afx_msg void On##### (UINT nFlags, CPoint point) ; Bit Mask Meaning MK_CONTROL Ctrl key is pressed MK_SHIFT Shift key is pressed MK_LBUTTON Mouse left button is pressed MK_MBUTTON Mouse middle button is pressed MK_RBUTTON Mouse right button is pressed

Mouse Message Handler Prototype of the Handler function: nFlags afx_msg void On##### (UINT nFlags, CPoint point) ; void CChildView::OnLButtonDown(UINT nFlags, CPoint point) { if(nFlags & MK_SHIFT){ // if shift key is pressed } if(nFlags & MK_RBUTTON){ // if right button is pressed at the same time CWnd ::OnLButtonDown(nFlags, point);

Mouse Message Handler Prototype of the Handler function: point Location of the cursor afx_msg void On##### (UINT nFlags, CPoint point) ; void CChildView::OnLButtonDown(UINT nFlags, CPoint point) { CClientDC dc(this); CPoint pt = point; dc.Rectangle(pt.x-100, pt.y+100, pt.x+100, pt.y-100); CWnd ::OnLButtonDown(nFlags, point); }

Coding practice: Line drawing 1 Draw lines by using mouse Key Idea: Remembering the beginning and ending position When the mouse left button is down Set the position as the beginning point When the mouse left button is released Set the position as the ending point Drawing the line

Coding practice: Line drawing 2 Draw Lines by using Mouse Show the lines even when dragging the mouse (rubber band effect) Key Idea: Remembering the beginning and ending position When the mouse left button is down Set the position as the beginning point When dragging the mouse Set the position as the ending point Drawing the line When the mouse left button is released

Any problem? What happen when moving the mouse outside the window’s client area while dragging?

Capturing the mouse Mouse Capture: Related function: Receiving mouse messages no matter where the mouse goes on the screen while dragging Related function: Function Meaning SetCapture() Starting Mouse Capturing ReleaseCapture() Ending mouse Capturing GetCapture() Returns CWnd pointer that owns the capture

Nonclient-Area Mouse Messages When the mouse is clicked or moved in a window’s nonclient area: Message Sent When WM_NCLBUTTONDOWN The left mouse button is pressed. WM_NCLBUTTONUP The left mouse button is released. WM_NCLBUTTONDBLCLK The left mouse button is double-clicked. WM_NCMBUTTONDOWN The middle mouse button is pressed. WM_NCMBUTTONUP The middle mouse button is released. WM_NCMBUTTONDBLCLK The middle mouse button is double-clicked. WM_NCRBUTTONDOWN The right mouse button is pressed. WM_NCRBUTTONUP The right mouse button is released. WM_NCRBUTTONDBLCLK The right mouse button is double-clicked. WM_NCMOUSEMOVE The cursor is moved over the window's nonclient area.

Nonclient-Area Mouse handlers Massage-map Macros and Handlers Message Message-Map Macro Handling Function WM_NCLBUTTONDOWN ON_WM_NCLBUTTONDOWN OnNcLButtonDown WM_NCLBUTTONUP ON_WM_NCLBUTTONUP OnNcLButtonUp WM_NCLBUTTONDBLCLK ON_WM_NCLBUTTONDBLCLK OnNcLButtonDblClk WM_NCMBUTTONDOWN ON_WM_NCMBUTTONDOWN OnNcMButtonDown WM_NCMBUTTONUP ON_WM_NCMBUTTONUP OnNcMButtonUp WM_NCMBUTTONDBLCLK ON_WM_NCMBUTTONDBLCLK OnNcMButtonDblClk WM_NCRBUTTONDOWN ON_WM_NCRBUTTONDOWN OnNcRButtonDown WM_NCRBUTTONUP ON_WM_NCRBUTTONUP OnNcRButtonUp WM_NCRBUTTONDBLCLK ON_WM_NCRBUTTONDBLCLK OnNcRButtonDblClk WM_NCMOUSEMOVE ON_WM_NCMOUSEMOVE OnNcMouseMove

Nonclient-Area Mouse handlers Prototype of the handling function nHitTest A hit test code indicates where the event occurred. point Location at which the event occurred (in screen coordinate) Use CWnd::ScreenToClient() function to convert screen coord to client coord. afx_msg void OnNc* (UINT nHitTest, CPoint point) ;

Nonclient-Area Mouse Handlers nHitTest Value Corresponding Location HTCAPTION The title bar HTCLOSE The close button HTGROWBOX The restore button (same as HTSIZE) HTHSCROLL The window's horizontal scroll bar HTMENU The menu bar HTREDUCE The minimize button HTSIZE The restore button (same as HTGROWBOX) HTSYSMENU The system menu box HTVSCROLL The window's vertical scroll bar HTZOOM The maximize button