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.

Slides:



Advertisements
Similar presentations
MS-Word XP Lesson 7.
Advertisements

Benchmark Series Microsoft Access 2010 Level 1
Objectives © Paradigm Publishing, Inc. 1 Objectives.
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.
Using Macros and Visual Basic for Applications (VBA) with Excel
Chapter 3 Designing a Newsletter
XP Tutorial 4 New Perspectives on Microsoft Windows XP 1 Microsoft Windows XP Personalizing Your Windows Environment Tutorial 4.
Advanced Microsoft Word Hosted by Jared Hoffman Topics Keyboard Shortcuts Customizing Toolbars and Menus Auto Format & Auto Correct Tabs Inserting Pictures.
Visual Basic 2010 How to Program. © by Pearson Education, Inc. All Rights Reserved.2.
Guide to Oracle10G1 Introduction To Forms Builder Chapter 5.
Introduction to MFC. Motivation Abstract the Windows API Provides additional GUI options Insert Open Inventor into existing MFC application Document /
A Guide to Oracle9i1 Introduction To Forms Builder Chapter 5.
Microsoft Windows Vista Chapter 6 Customizing Your Computer Using the Control Panel.
Creating, Formatting, and Editing a Word Document with a Picture
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 5 Using Business Information Sets
Tran Anh Tuan A.  Help to modify a control’s behavior by deriving classes of your own from the MFC control classes  Help to build reusable, self-contained.
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)
Printing and Page Formatting ITSW 1401, Intro to Word Processing Instructor: Glenda H. Easter.
COMPREHENSIVE Excel Tutorial 8 Developing an Excel Application.
Chapter 3 Introduction to Event Handling and Windows Forms Applications.
WORKING WITH MACROS CHAPTER 10 WORKING WITH MACROS.
Chapter 3 Maintaining a Database
BIM313 – Advanced Programming Simple Controls 1. Contents Traditional Controls – Labels, Text Boxes, Buttons, Check Boxes, List Boxes, Combo Boxes Advanced.
© 2008 The McGraw-Hill Companies, Inc. All rights reserved. WORD 2007 M I C R O S O F T ® THE PROFESSIONAL APPROACH S E R I E S Lesson 22 Macros.
Chapter 2 Creating a Research Paper with References and Sources Microsoft Word 2013.
XP New Perspectives on Microsoft Office FrontPage 2003 Tutorial 4 1 Microsoft Office FrontPage 2003 Tutorial 4 – Using Shared Borders and Themes.
Tutorial 1: An Introduction to Visual Basic.NET1 Tutorial 1 An Introduction to Visual Basic.NET.
Chapter 3: Using GUI Objects and the Visual Studio IDE.
Chapter 5 Menus, Common Dialog Boxes, and Methods Programming in C#.NET © 2003 by The McGraw-Hill Companies, Inc. All rights reserved.
Advanced Project Plan Formatting Lesson 14. Skills Matrix SkillsMatrix Skill Customize the calendar view Format bar styles for tasks in the Calendar view.
Chapter 2 - More Controls More controls – Text boxes - used for user input – Frames - containers to group items – check boxes - user select an option -
1. Chapter 4 Customizing Paragraphs 3 More Paragraph Changes Highlight a paragraph in Word by applying borders and shading. Sort paragraphs to control.
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.
IC 3 BASICS, Internet and Computing Core Certification Key Applications Lesson 11 Organizing the Worksheet.
Chapter 7 Controls.
BZUPAGES.COM Visual Programming Lecture – 6- 7 Miss. SADAF MAJEED SIAL Computer Science Department Bahauddin Zakariya University Multan.
© 2008 The McGraw-Hill Companies, Inc. All rights reserved. WORD 2007 M I C R O S O F T ® THE PROFESSIONAL APPROACH S E R I E S Lesson 15 Advanced Tables.
Office 2003 Post-Advanced Concepts and Techniques M i c r o s o f t Access Project 7 Advanced Report and Form Techniques.
Microsoft Outlook 2010 Chapter 3 Managing Contacts and Personal Contact Information with Outlook.
Microsoft Access 2010 Chapter 8 Advanced Form Techniques.
Microsoft Publisher 2010 Chapter 1 Creating a Flyer.
Chapter 7 Controls. Scroll bar control 3 Scroll bar control (1/3) Scroll bar codes (interfaces)
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.
Dialog boxes Modal and modeless dialog boxes Displaying about dialog box: case WM_COMMAND : switch (LOWORD (wParam)) { case IDM_APP_ABOUT : DialogBox (hInstance,
XP Tutorial 8 New Perspectives on Microsoft Windows XP 1 Microsoft Windows XP Object Linking and Embedding Tutorial 8.
Chapter 3 Automating Your Work. It is frustrating when you have to type the same passage of text repeatedly. For example your name and address. Word includes.
Customizing Reports Adding a Date to a Report Reference Window Adding a Date to a Report Display the report in the design view Click the Text Box Tool.
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.
Chapter 8 Dialog Boxes and Property Sheet
Creating and Editing a Web Page
Creating Menus Menu Bar – behaves like standard Windows menus Can be used in place of or in addition to buttons to execute a procedure Menu items are controls.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 3 Building an Application in the Visual Basic.NET Environment.
COMPUTER PROGRAMMING I 3.01 Apply Controls Associated With Visual Studio Form.
Creating and Editing a Web Page Using Inline Styles
Prepared by the Academic Faculty Members of IT. Tables Creating Tables. Merging Cells. Splitting Cells. Sorting Tables. Performing Calculations.
Chapter 6: FILE I/O and Serialize CFile class. FILE I/O Serialization and the CArchive Class.
Chapter 28. Copyright 2003, Paradigm Publishing Inc. CHAPTER 28 BACKNEXTEND 28-2 LINKS TO OBJECTIVES Table Calculations Table Properties Fields in a Table.
Customizing Menus and Toolbars CHAPTER 12 Customizing Menus and Toolbars.
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.
PowerPoint Chapter 1 Creating and Editing a Presentation with Clip Art Discovering Computers & Microsoft Office 2010.
Chapter 11 Enhancing an Online Form and Using Macros Microsoft Word 2013.
Dialog Boxes and Property Sheets
Excel Tutorial 8 Developing an Excel Application
Chapter 1: An Introduction to Visual Basic 2015
Working with Dialogs and Controls
Dialog Boxes and Property Sheets
Presentation transcript:

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 and have scroll bar Properties Single Selection List box Multiple Selection List box

CListBox Class CListBox class encapsulates list box controls Creating a List Box –Use CListBox::Create member function m_ListBox.Create (WS_CHILD ¦ WS_VISIBLE ¦ LBS_STANDARD, rect, this, ID); m_ListBox.Create (WS_CHILD ¦ WS_VISIBLE ¦ LBS_STANDARD, rect, this, ID);

List Box Styles StyleDescription LBS_STANDARDCreates a "standard" list box that has a border and a vertical scroll bar, notifies its parent window when th e selection changes or an item is double-clicked, and sorts items alphabetically. LBS_SORTSorts items that are added to the list box. LBS_NOSELCreates a list box whose items can be viewed but not selected. LBS_NOTIFYCreates a list box that notifies its parent when the selection changes or an item is double-clicked. LBS_DISABLENOSCROL L Disables the list box's scroll bar when it isn't needed. Without this style, an unneeded scroll bar is hidden r ather than disabled. LBS_MULTIPLESELCreates a multiple-selection list box. LBS_EXTENDEDSELAdds extended selection support to a multiple-selection list box. LBS_MULTICOLUMNCreates a multicolumn list box. LBS_OWNERDRAWVARI ABLE Creates an owner-draw list box whose items can vary in height. LBS_OWNERDRAWFIXE D Creates an owner-draw list box whose items are the same height. LBS_USETABSTOPSConfigures the list box to expand tab characters in item text. LBS_NOREDRAWCreates a list box that doesn't automatically redraw itself when an item is added or removed. LBS_HASSTRINGSCreates a list box that "remembers" the strings added to it. Conventional list boxes have this style by defa ult; owner-draw list boxes don't. LBS_WANTKEYBOARDI NPUT Creates a list box that sends its parent a WM_VKEYTOITEM or WM_CHARTOITEM message when a ke y is pressed. This style is used to customize the list box's response to keyboard input. LBS_NOINTEGRALHEIG HT Allows a list box to assume any height. By default, Windows sets a list box's height to a multiple of the ite m height to prevent items from being partially clipped.

6 List Box Notifications –LBN_DBLCLK, LBN_SELCHANGE and LBN_SELCANCEL messages require LBS_NOTIFY style setting NotificationSent WhenMessage-Map MacroLBS_NOTIFY Required? LBN_SETFOCUSThe list box gains the input foc us. ON_LBN_SETFOCUSNo LBN_KILLFOCUSThe list box loses the input foc us. ON_LBN_KILLFOCUSNo LBN_ERRSPACEAn operation failed because of insufficient memory. ON_LBN_ERRSPACENo LBN_DBLCLKAn item is double-clicked.ON_LBN_DBLCLKYes LBN_SELCHANG E The selection changes.ON_LBN_SELCHANGEYes LBN_SELCANCELThe selection is canceled.ON_LBN_SELCANCELYes

7 Editing items Add and Delete Items Select items m_list.AddString(_T(“apple”)); m_list.DeleteString(3); // For a single selection list box m_list.SetCurSel(2); // For a multiple selection list box m_list.SetSel(2); m_list.SetSel(3, FALSE);

8 Get selected items // For a single selection list box int nIndex = m_list.GetCurSel(); if(nIndex != LB_ERR){ CString str; m_list.GetText(nIndex, str); } // For a multiple selection list box int nIndex = m_list.GetCaretIndex(); if(nIndex != LB_ERR){ CString str; m_list.GetText(nIndex, str); }

Coding Practice Add buttons, edit box and List box to a dialog application Add and delete an item in the list box using button controls

Chapter 8 Dialog Boxes and Property Sheet

11 Dialog Box ? Dialog box –Window that pops up to solicit input from the user –Ex) file menu, print menu

12 Dialog based application: Dialog box itself is the main program (frame)

13 Today’s topic 1. How can design a dialog box 2. How to show or close any dialog box when necessary 3. How to give or take any value to or from the dialog box

14 Two kinds of dialog boxes Dialog boxes –Modal dialog When appear, it takes all ownership of input. It disables the window until the dialog box is dismissed. –Modeless dialog It behaves more like a conventional window. It activates together with other windows.

15 How to create dialog box Design a dialog template by using dialog box edit tool in the resource view Edit resource file by your self. –Edit Resource script(*.RC) manually

16 A dialog box template Using a resource view to design a new dialog box

17 A dialog box template Add or delete controls –Using Toolbox menu

18 A dialog box template Align templates –Use dialog editor tool bar –Or use Format menu

19 A dialog box Template Tab order –Determine the order of the focus changing when tab key is pressed –Use [Format]->[Tab Order] menu

20 Two kinds of dialog boxes Dialog boxes –Modal dialog When appear, it takes all ownership of input. It disables the window until the dialog box is dismissed. –Modeless dialog It behaves more like a conventional window. It activates together with other windows.

21 Modal Dialog box MFC Class Heirarchy

22 Modal dialog box How to create and show it ① Design a dialog box template  Resource View ② Create a CDialog derived class using the template  Use [Project] [add class] menu ③ Call CDialog::DoModal() function to show the dialog box

23 Modal dialog box Main Virtual functions of CDialog class –WM_INITDIALOG message handler –When initializes the dialog box –Good place for initializing other controls –IDOK message handler (when pressing OK button) –Good place for updating variables before closing the dialog box, virtual BOOL CDialog::OnInitDialog ( ); virtual void CDialog::OnOK ( );

24 Modal dialog box Main Virtual functions of CDialog class –IDCANCEL message handler (when pressing cancel button) –Close the dialog box virtual void CDialog::OnCancel ( );

25 OnOK() and OnCancel() function Call EndDialog function to close the dialog box void CDialog::OnOK() { UpdateData(TRUE);// update the variables EndDialog(IDOK); } void CDialog::OnCancel() { EndDialog(IDCANCEL); }

26 DDX/DDV (1/8) How to connect your variables in the parent window with a dialog box: –Add the same variables and connect them to the controls Ex) create two variables and change them using a dialog box class CMyDialog : public CDialog {... CString m_str ; int m_color ;... }

27 DDX/DDV (2/8) What you have to: IDC_STR IDC_COLOR ①② Dialog box m_str m_color Dialog variables m_str m_color Parent variables IDC_STR IDC_COLOR ③ ④ Dialog box m_str m_color Dialog variables m_str m_color Parent variables When showing dialog box When pressing OK button

28 DDX/DDV (3/8) How to implement it: BOOL CMyDialog::OnInitDialog() { CDialog::OnInitDialog(); SetDlgItemText(IDC_STR, m_str); SetDlgItemInt(IDC_COLOR, m_color); return TRUE; } void CMyDialog::OnOK() { GetDlgItemText(IDC_STR, m_str); m_color = GetDlgItemInt(IDC_COLOR); CDialog::OnOK(); }

29 DDX/DDV (4/8) An automatic way: –DDX(Dialog Data eXchange) IDC_STR IDC_COLOR ①② 대화상자 m_str m_color 대화상자 객체 m_str m_color 뷰 객체 IDC_STR IDC_COLOR ③ ④ 대화상자 m_str m_color 대화상자 객체 m_str m_color 뷰 객체 Automation?

30 DDX/DDV (5/8) OnInitDialog(), OnOK() implementation BOOL CDialog::OnInitDialog() {... UpdateData(FALSE);// Give the values to the controls... } void CDialog::OnOK() {... UpdateData(TRUE);// Retrieve the values // from the controls... }

31 DDX/DDV (6/8) What is CWnd::UpdateData() function? BOOL CWnd::UpdateData(BOOL bSaveAndValidate) {... CDataExchange dx(this, bSaveAndValidate); DoDataExchange(&dx);... }

32 DDX/DDV (7/8) Implementation of DDX –Connecting a variable with a control Use DDX_* MACRO void CMyDialog::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CMyDialog) DDX_Text(pDX, IDC_STR, m_str); DDX_Text(pDX, IDC_COLOR, m_color); //}}AFX_DATA_MAP }

33 DDX/DDV (8/8) DDV(Dialog Data Validation) –Automation of the validation of the data Check the range of the data Use DDV_* MACRO void CMyDialog::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CMyDialog) DDX_Text(pDX, IDC_STR, m_str); DDV_MaxChars(pDX, m_str, 10); DDX_Text(pDX, IDC_COLOR, m_color); DDV_MinMaxInt(pDX, m_color, 0, 255); //}}AFX_DATA_MAP }

Coding Practice Create a dialog box as shown below and show it when pressing mouse left button Type on the edit control and choose a text color value from the radio buttons