Copyright © 2004-2013 - Curt Hill Common Dialogs Easily Obtaining File Names in DevC++ Windows Programs.

Slides:



Advertisements
Similar presentations
* 1 Common Dialog Control. * 2 You want your user to set property or provide your application with some information easily? How do you do it? The Common.
Advertisements

CSCI 6962: Server-side Design and Programming Input Validation and Error Handling.
What is a Dialog box? A Dialog box is a window or “form” that contains other child windows or “controls” that have a specific appearances and pre-defined.
Copyright © – Curt Hill Windows Files to Hand-In And other things you should know.
Copyright © – Curt Hill Files to Hand-In And other things you should know.
Access - Project 1 l What Is a Database? –A Collection of Data –Organized in a manner to allow: »Access »Retrieval »Use of That Data.
© The McGraw-Hill Companies, 2006 Chapter 18 Advanced graphics programming.
Chapter 8: I/O Streams and Data Files. In this chapter, you will learn about: – I/O file stream objects and functions – Reading and writing character-based.
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.
Printing and Page Formatting ITSW 1401, Intro to Word Processing Instructor: Glenda H. Easter.
MIS 3200 – Unit 6.2 Learning Objectives How to move data between pages – Using Query Strings How to control errors on web pages – Using Try-catch.
XP New Perspectives on Browser and Basics Tutorial 1 1 Browser and Basics Tutorial 1.
GUI’s Part Two wxWidgets components. Resources for wxWidgets Sample code on course website wxWidgets web site.
PMS /134/182 HEX 0886B6 PMS /39/80 HEX 5E2750 PMS /168/180 HEX 00A8B4 PMS /190/40 HEX 66CC33 By Adrian Gardener Date 9 July 2012.
General Programming Introduction to Computing Science and Programming I.
© The McGraw-Hill Companies, 2006 Chapter 4 Implementing methods.
1 Functions 1 Parameter, 1 Return-Value 1. The problem 2. Recall the layout 3. Create the definition 4. "Flow" of data 5. Testing 6. Projects 1 and 2.
1 ADVANCED MICROSOFT EXCEL Lesson 9 Applying Advanced Worksheets and Charts Options.
Java Programming, Second Edition Chapter Five Input and Selection.
Copyright © 2009 Curt Hill The Picture Object Getting and displaying.
1 The EDIT Program The Edit program is a full screen text editor that allows you to: Create text files Create text files Edit an existing text files Edit.
Chapter 2 - More Controls More controls – Text boxes - used for user input – Frames - containers to group items – check boxes - user select an option -
Copyright © Curt Hill Stored Procedures In Transact-SQL.
Copyright © Curt Hill First Window Builder Program Easy GUIs in Eclipse.
Lecture Set 12 Sequential Files and Structures Part A – Dialog Boxes, Filters, Directories.
COMPUTER PROGRAMMING. A Typical C++ Environment Phases of C++ Programs: 1- Edit 2- Preprocess 3- Compile 4- Link 5- Load 6- Execute Loader Primary Memory.
Chapter 9 I/O Streams and Data Files
Copyright © Curt Hill Generic Classes Template Classes or Container Classes.
Working With Files. Sources of Data Adding data to a spreadsheet can be done in several ways, including: – Type it in piece by piece – Read it from a.
XP New Perspectives on Microsoft Office FrontPage 2003 Tutorial 7 1 Microsoft Office FrontPage 2003 Tutorial 7 – Creating and Using Templates in a Web.
Introduction to Database using Microsoft Access 2013 Part 6.1 November 18, 2014.
Disk Files for I/O your variable (of type ifstream) your variable (of type ofstream) disk file “myInfile.dat” disk file “myOut.dat” executing program input.
Copyright © Curt Hill More Components Varying the input of Dev-C++ Windows Programs.
Common Dialogs.  What is a Common Dialog/Why use them?  Open Dialog  Save File As Dialog  Color Dialog  Font Dialog  Print Dialog.
Dialog Boxes.
Copyright Curt Hill The C/C++ switch Statement A multi-path decision statement.
Copyright © Curt Hill Formatting Reals Outputs other than normal.
1 Chapter 3 – Examples The examples from chapter 3, combining the data types, variables, expressions, assignments, functions and methods with Windows controls.
A First Program CSE 1310 – Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington Credits: a significant part of.
Copyright © Curt Hill Applets A different type of program.
Introduction to Files in VB Chapter 9.1, 9.3. Overview u Data Files  random access  sequential u Working with sequential files  open, read, write,
JOptionPane Class JOptionPane makes it easy to pop up a standard dialog box that prompts users for a value or informs them of something. While the JOptionPane.
Copyright © Curt Hill Error Handling in Java Throwing and catching exceptions.
Input Boxes, List Boxes, and Loops Chapter 5. 2 Input Boxes Method for getting user’s attention to obtain input. InputBox() for obtaining input MessageBox()
Creating and Using Dialogs ● A dialog is a box that pops up and prompts the user for a value or informs them of something ● One way: directly create objects.
Copyright © – Curt Hill Building Windows Applications in wxDev-C++
Copyright © Curt Hill Simple I/O Input and Output using the System and Scanner Objects.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Scanner Review Java Foundations: Introduction to Programming and Data Structures.
Batch Files More flow of control Copyright © by Curt Hill.
L071 Introduction to C Topics Compilation Using the gcc Compiler The Anatomy of a C Program Reading Sections
FILES AND EXCEPTIONS Topics Introduction to File Input and Output Using Loops to Process Files Processing Records Exceptions.
C++ for Everyone by Cay Horstmann Copyright © 2012 by John Wiley & Sons. All rights reserved Chapter Eight: Streams Slides by Evan Gallagher.
File I/O. I/O Flags Flags are passed to give some information about how the file is to be used. – Read only file – flag=0x0 – Write only file – flag=0x1.
Getting and displaying
Introduction to Computing Science and Programming I
Windows Files to Hand-In
Data Validation and Protecting Workbook
Introduction to C Topics Compilation Using the gcc Compiler
Organizing common actions
Predefined Dialog Boxes
Lecture 5A File processing Richard Gesick.
Topics Introduction to File Input and Output
WEB PROGRAMMING JavaScript.
Part A – Doing Your Own Input Validation with Simple VB Tools
New Perspectives on Windows XP
Cmdlets “Command-lets”
Copyright © – Curt Hill Bash Flow of Control Copyright © – Curt Hill.
Using Lists and Functions to Create Dialogue
Topics Introduction to File Input and Output
Presentation transcript:

Copyright © Curt Hill Common Dialogs Easily Obtaining File Names in DevC++ Windows Programs

Programs that Use Files Some programs use exactly the same file each time –Usually an initialization file in the same place every time Most programs can use any file of the proper format Typing the file name into a text box is awkward and error prone Let Windows show us where it is with a common dialog box Copyright © Curt Hill

Common File Dialog Box What is it? –This is the Windows standard way to select a file name –There are two flavors: open existing or create new one Where: Dialogs tab There are two of importance today: –wxOpenFileDialog and wxSaveFileDialog Neither will open a file –But they will obtain a file name Copyright © Curt Hill

What you can do A common dialog box allows the user to avoid typing and Change directory or disk Choose a file Change the filter Accept the chosen file or cancel Copyright © Curt Hill

Example from PowerPoint Copyright © Curt Hill

General Unlike most components they are non-visual They can be seen on the form during design time Invisible at execution time They are not seen until executed Copyright © Curt Hill

DevC++ Design Time Copyright © Curt Hill

After Drop Copyright © Curt Hill

Using Once put on form we still have to use it General process is: Display box Determine if open or cancel was done If Open get the file name Convert this file to a C style string pass it to the file Copyright © Curt Hill

Modal Dialog Boxes In Windows there are two styles of dialog box: –Modal –Non-modal A non-modal may be displayed, but it does not interfere with the parent window A Modal dialog box prevents any input to the parent –It must be dismissed before the parent is usable Copyright © Curt Hill

ShowModal Method The ShowModal method takes no parameters and shows the dialog ShowModal returns an integer that tells what happened If this is equal to wxID_OK then the user approved the file name –Otherwise they cancelled –All file processing should be done only if a wxID_OK was returned Copyright © Curt Hill

Design Properties Message – The contents of the title bar when Common dialog is displayed Name – The name of the component –This will always be referenced from code Most other things need to be referenced using methods Copyright © Curt Hill

GetPath Method This is used to obtain the filename –It also contains the entire directory path –GetFilename only gives the file name without the path It returns a wxString ifstreams and ofstreams need a C style string This needs to be converted in order to pass to a constructor or open method How? Copyright © Curt Hill

String Conversion This is relatively easy Use the wxString method: c_str() –ifstream inf( OpenDialog1-> GetPath ().c_str()); You may do in two steps: –wxString name = OpenDialog->GetPath(); –ifstream inf(name.c_str()); Copyright © Curt Hill

Sample Code Suppose that OpenDial is the object The following code will open a file: int ret = OpenDialog- >ShowModal(); if(ret == wxID_OK){ ifstream inf( OpenDial->GetPath().c_str()); while(inf) { … } } // end of if Copyright © Curt Hill

Executed Copyright © Curt Hill

Filters By default a common dialog box will show every file in the current directory –The directory may be changed Often we are not interested in every kind of file –A filter allows us to only observe the files of interest DevC++ does not allow the filter to be set at design time –Done with SetWildcard method Copyright © Curt Hill

Filter Pairs Each pair consists of two pieces –A name to be displayed –An expression that describes what to show The two are separated by a vertical bar The expression may include ? or * –? any one character –* any number of any characters Copyright © Curt Hill

Format Thus we set: OpenDialog1->SetWildcard( "Data|*.dat|All|*.* "); The odd entries are display The even entries are the actual filters See next screen for image Copyright © Curt Hill

Show Filters Copyright © Curt Hill

Last Thoughts There are many other options –Most of these we do not need The FileName is persistent It will show as the last one used in subsequent executions Copyright © Curt Hill