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.

Slides:



Advertisements
Similar presentations
Office 2003 Post-Advanced Concepts and Techniques M i c r o s o f t Excel Project 7 Using Macros and Visual Basic for Applications (VBA) with Excel.
Advertisements

Using Macros and Visual Basic for Applications (VBA) with Excel
Using Eclipse. Getting Started There are three ways to create a Java project: 1:Select File > New > Project, 2 Select the arrow of the button in the upper.
Introduction to MFC. Motivation Abstract the Windows API Provides additional GUI options Insert Open Inventor into existing MFC application Document /
Fundamentals of Programming in Visual Basic 3.1 Visual basic Objects Visual Basic programs display a Windows style screen (called a form) with boxes into.
Chapter 3 Introduction to Event Handling and Windows Forms Applications.
Microsoft Visual Basic 2012 CHAPTER TWO Program and Graphical User Interface Design.
Microsoft Visual Basic 2005 CHAPTER 8 Using Procedures and Exception Handling.
Microsoft Visual Basic 2012 Using Procedures and Exception Handling CHAPTER SEVEN.
Introduction to Graphical User Interfaces. Objectives * Students should understand what a procedural program is. * Students should understand what an.
Department of Mechanical Engineering, LSUSession VII MATLAB Tutorials Session VIII Graphical User Interface using MATLAB Rajeev Madazhy
Chapter 8: Writing Graphical User Interfaces
Java Software Solutions Lewis and Loftus Chapter 10 1 Copyright 1997 by John Lewis and William Loftus. All rights reserved. Graphical User Interfaces --
Java Programming: From Problem Analysis to Program Design, 4e Chapter 12 Advanced GUIs and Graphics.
BZUPAGES.COM Visual Programming Lecture – 5 Miss. SADAF MAJEED SIAL Computer Science Department Bahauddin Zakariya University Multan.
Chapter 8: Writing Graphical User Interfaces Visual Basic.NET Programming: From Problem Analysis to Program Design.
Visual Basic 2005 CHAPTER 2 Program and Graphical User Interface Design.
Tutorial 7 Creating Forms. Objectives Session 7.1 – Create an HTML form – Insert fields for text – Add labels for form elements – Create radio buttons.
Basic Controls & Properties Chapter 2. Overview u VB-IDE u Basic Controls  Command Button  Label  Text Box  Picture Box u Program Editor  Setting.
Chapter One An Introduction to Visual Basic 2010 Programming with Microsoft Visual Basic th Edition.
Classic Controls Trần Anh Tuấn A. Week 1 How to create a MFC project in VS 6.0 How to create a MFC project in VS 6.0 Introduction to Classic Controls.
Chapter 7 Controls.
BZUPAGES.COM Visual Programming Lecture – 6- 7 Miss. SADAF MAJEED SIAL Computer Science Department Bahauddin Zakariya University Multan.
Microsoft Access 2010 Chapter 8 Advanced Form Techniques.
Visual Basic 2005 CHAPTER 2 Program and Graphical User Interface Design.
1 Creating Windows GUIs with Visual Studio. 2 Creating the Project New Project Visual C++ Projects Windows Forms Application Give the Project a Name and.
Lecture 7 Menu, controls, scroll bars. Menu Menu item sends WM_COMMAND message to the application window Menu is attached to window when the window is.
Chapter 7 Controls. Scroll bar control 3 Scroll bar control (1/3) Scroll bar codes (interfaces)
GUI Programming using NetBeans. RHS – SOC 2 GUI construction We have previously talked about elements in a (simple) GUI –Frames, Panes and Dialogs –Text.
Chapter2: Drawing a Window. Review: Introducing MFC.
Copyright © Curt Hill More Components Varying the input of Dev-C++ Windows Programs.
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.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design Second Edition by Tony Gaddis.
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.
Chapter2: Drawing a Window
Microsoft Visual Basic 2010 CHAPTER TWO Program and Graphical User Interface Design.
CMPF114 Computer Literacy Chapter 3 The Visual Basic Environment 1.
Introduction to Technology. Parts of MSWord Screen Title Bar Quick Access Toolbar Button Ribbon Status Bar (views and zoom)
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 3 Building an Application in the Visual Basic.NET Environment.
Chapter 5 Introduction To Form Builder. Lesson C Objectives  Use sequences to automatically generate primary key values in a form  Create lists of values.
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.
 2002 Prentice Hall. All rights reserved. 1 Introduction to the Visual Studio.NET IDE Outline Introduction Visual Studio.NET Integrated Development Environment.
Microsoft Visual C# 2010 Fourth Edition Chapter 3 Using GUI Objects and the Visual Studio IDE.
Problem: Take Two Numbers, Add Them Together And Display The Results. Now To Build The Flowchart… We Probably Need One Like This… Let’s Add The Routines…
Chapter 10 Using Macros, Controls and Visual Basic for Applications (VBA) with Excel Microsoft Excel 2013.
This is an introduction to configuring Microsoft Outlook for Office 2010: Forwarding FAMIS work order opening and closing s to other users or alternate.
Chapter 3: I Need a Tour Guide (Introduction to Visual Basic 2012)
Excel Tutorial 8 Developing an Excel Application
Message Handling in MFC
Steps to Build Frame Window Recipe Application
Chapter 1: An Introduction to Visual Basic 2015
Chapter Topics 15.1 Graphical User Interfaces
Chapter 2 – Introduction to the Visual Studio .NET IDE
Program and Graphical User Interface Design
1. Introduction to Visual Basic
Working with Dialogs and Controls
MFC Dialog Application
Using Procedures and Exception Handling
Chap 7. Building Java Graphical User Interfaces
Graphical User Interfaces -- Introduction
Program and Graphical User Interface Design
Chapter 7 Advanced Form Techniques
CIS16 Application Development Programming with Visual Basic
Visual programming Chapter 2: Events and Event Handling
Chapter 15: GUI Applications & Event-Driven Programming
Khongorzul D Window Programming CBNU,
Steps to Build Frame Window Recipe Application
Chapter 4 Enhancing the Graphical User Interface
Presentation transcript:

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 of windows programming and promote a consistent user interface

Introduction Example: push button control –Don’t need to draw a rectangle on the screen –Don’t need to process the mouse message –Everything is almost done. Just add it!!! –Notification will be given when clicked.

4 Introduction MFC Classic Controls Control TypeWNDCLASSMFC Class Buttons"BUTTON"CButton List boxes"LISTBOX"CListBox Edit controls"EDIT"CEdit Combo boxes"COMBOBOX"CComboBox Scroll bars"SCROLLBAR"CScrollBar Static controls"STATIC"CStatic

5 How it works Controls and its parent window –Notification Message When its states change Example) A button is being clicked –Member Functions of the control Change or get the state of the control. Example) Change a button to be inactive Controls (Child Window) Controls (Child Window) Parent Window ① Notification ② function call

6 MFC Class Hierarchy A control is also a window!

7 Button Control (1/8) Various kinds of the Button Control

8 Button Control Two ways of creating a control ① Create one by hand (coding) ② Create one using the dialog edit window

9 Button control by hand Procedure: –1. Adding CButton object as a member variable –2. Call CButton‘s Create(..) member function to create Ex) Call it inside CChildView::OnCreate() function m_button.Create( _T(“Push Here!“), WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON, CRect(100, 100, 200, 130), this, 101); In CChildView class : ChildView.h CButton m_button; // adding CButton object

10 Button Control CButton::Create() member function –Caption : title string –Style : Style as a button and as a window Ex) WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON –Rect : position and size –pParentWnd : pointer to parent window –UINT nID : ID of the control (ex, 101, 102…) BOOL CButton::Create (Caption, Style, rect, pParentWindow, ID) ; Windows styleCButton style

11 Styles of CButton StyleDescription BS_PUSHBUTTONCreates a standard push button control BS_DEFPUSHBUTTONCreates a default push button; used in dialog boxes to identify the push button that's clicked if Enter is pressed BS_CHECKBOXCreates a check box control BS_AUTOCHECKBOXCreates a check box control that checks and unchecks itself when clicked BS_3STATECreates a three-state check box control BS_AUTO3STATECreates a three-state check box control that cycles through three states—checked, unchecked, and indetermin ate—when clicked BS_RADIOBUTTONCreates a radio button control BS_AUTORADIOBUTTO N Creates a radio button control that, when clicked, checks itself and unchecks other radio buttons in the group BS_GROUPBOXCreates a group box control

Additional Styles of CButton StyleDescription BS_LEFTTEXTMoves the text accompanying a radio button or check box c ontrol from the button's right (the default) to its left BS_RIGHTBUTTONSame as BS_LEFTTEXT BS_LEFTLeft justifies the button text in the control rectangle BS_CENTERCenters the button text in the control rectangle BS_RIGHTRight justifies the button text in the control rectangle BS_TOPPositions the button text at the top of the control rectangle BS_VCENTERPositions the button text in the center of the control rectangl e vertically BS_BOTTOMPositions the button text at the bottom of the control rectangl e BS_MULTILINEAllows text too long to fit on one line to be broken into two or more lines

When clicking a button Windows sends Notification Message Message Handler for the notification 1.Add message handler MACRO in massage map 2.Implement the message handler function Controls (Child Window) Controls (Child Window) Parent Window Notification

14 Adding Message Handler 1. Add message handler MACRO in massage map 2. Implement the message handler function ON_BN_CLICKED( ID, function name) Ex) ON_BN_CLICKED( 101, OnButtonClicked) // in massage map void CChildView::OnButtonClicked( ) // message handler { AfxMessageBox(_T(“Button is clicked.")); }

When changing state of CButton Call member functions of CButton –Change(Set) the current state –Acquire(Get) the current state Controls (Child Window) Controls (Child Window) Parent Window function call

16 Member functions of CButton 1.Change the state of the check box 2.Check the state of the check box m_button.SetCheck(BST_CHECKED); m_button.SetCheck(BST_UNCHECKED); if ( m_button.GetCheck() == BST_CHECKED ) AfxMessageBox(_T(“Button is checked”));

Radio button Only one at a time is checked. They are connected. You can make it manually // Radio Button Manual Creation Example void CChildView::OnRadioButton1Clicked () { m_wndRadioButton1.SetCheck (BST_CHECKED); m_wndRadioButton2.SetCheck (BST_UNCHECKED); m_wndRadioButton3.SetCheck (BST_UNCHECKED); } // Radio Button Manual Creation Example void CChildView::OnRadioButton1Clicked () { m_wndRadioButton1.SetCheck (BST_CHECKED); m_wndRadioButton2.SetCheck (BST_UNCHECKED); m_wndRadioButton3.SetCheck (BST_UNCHECKED); }

Auto Radio Button WS_GROUP connects Radio buttons m_RadioButton1.Create (_T ("COM1"), WS_CHILD ¦ WS_VISIBLE ¦ WS_GROUP ¦ BS_AUTORADIOBUTTON, rect1, this, IDC_COM1); m_RadioButton2.Create (_T ("COM2"), WS_CHILD ¦ WS_VISIBLE ¦ BS_AUTORADIOBUTTON, rect2, this, IDC_COM2); m_RadioButton3.Create (_T ("COM3"), WS_CHILD ¦ WS_VISIBLE ¦ BS_AUTORADIOBUTTON, rect3, this, IDC_COM3); m_RadioButton4.Create (_T (“Student1"), WS_CHILD ¦ WS_VISIBLE ¦ WS_GROUP ¦ BS_AUTORADIOBUTTON, rect4, this, IDC_COM1); m_RadioButton5.Create (_T (" Student2"), WS_CHILD ¦ WS_VISIBLE ¦ BS_AUTORADIOBUTTON, rect5, this, IDC_COM2); m_RadioButton1.Create (_T ("COM1"), WS_CHILD ¦ WS_VISIBLE ¦ WS_GROUP ¦ BS_AUTORADIOBUTTON, rect1, this, IDC_COM1); m_RadioButton2.Create (_T ("COM2"), WS_CHILD ¦ WS_VISIBLE ¦ BS_AUTORADIOBUTTON, rect2, this, IDC_COM2); m_RadioButton3.Create (_T ("COM3"), WS_CHILD ¦ WS_VISIBLE ¦ BS_AUTORADIOBUTTON, rect3, this, IDC_COM3); m_RadioButton4.Create (_T (“Student1"), WS_CHILD ¦ WS_VISIBLE ¦ WS_GROUP ¦ BS_AUTORADIOBUTTON, rect4, this, IDC_COM1); m_RadioButton5.Create (_T (" Student2"), WS_CHILD ¦ WS_VISIBLE ¦ BS_AUTORADIOBUTTON, rect5, this, IDC_COM2);

Coding Practice Creating the following program using CButtons

20 Button Control Two ways of creating a control ① Create one by hand (coding) ② Create one using the dialog edit window

21 Dialog Edit Window Resource View -> Edit “Dialog” –Creating and designing controls using toolbox Control variables –Each control can be connected with a control variable. –Call the member functions of the control variable to change/get the state of the control

Coding Practice Make a new project of Dialog Based Application Design the dialog using Dialog Edit Window and tool box

Adding Event Message Handler Use Properties window to add message handlers

Adding Event Message Handler Alternative way In dialog edit window, mouse right button click on a control  Add Event Handler

25 Creating control variables mouse right button click on a control  Add variables

26 Creating control variables Added things: // In Header file class CTestDlg::public CDiglog {... CButton m_button; } // In Source file void CTestDlg::DoDataExchange(CDataExchange* pDX) { CFormView::DoDataExchange(pDX); //{{AFX_DATA_MAP(CExButtonView) DDX_Control(pDX, IDC_BUTTON1, m_button); //}}AFX_DATA_MAP }

Coding Practice Creating the following program using Dialog based application template When pushing the button, show the information