Copyright © 2007-2014 – Curt Hill Building Windows Applications in wxDev-C++

Slides:



Advertisements
Similar presentations
Using Macros and Visual Basic for Applications (VBA) with Excel
Advertisements

Access - Project 1 l What Is a Database? –A Collection of Data –Organized in a manner to allow: »Access »Retrieval »Use of That Data.
Guide to Oracle10G1 Introduction To Forms Builder Chapter 5.
CS320n –Visual Programming LabVIEW Foundations. Visual ProgrammingLabVIEW Foundations2 What We Will Do Today Hand back and review the midterm Look at.
Chapter 6 Graphical User Interface (GUI) and Object-Oriented Design (OOD)
Bellevue University CIS 205: Introduction to Programming Using C++ Lecture 3: Primitive Data Types.
Automating Tasks With Macros
A Guide to Oracle9i1 Introduction To Forms Builder Chapter 5.
Automating Tasks With Macros. 2 Design a switchboard and dialog box for a graphical user interface Database developers interact directly with Access.
1 Introduction to the Visual Studio.NET IDE Powerpoint slides modified from Deitel & Deitel.
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 6: Graphical User Interface (GUI) and Object-Oriented Design (OOD) J ava P rogramming: Program Design Including Data Structures Program Design.
Microsoft Visual Basic 2005 CHAPTER 8 Using Procedures and Exception Handling.
Saving and Loading Simple Text Files A sequential file stores characters one after the other like songs on a cassette tape. New characters are added to.
Visual Basic Chapter 1 Mr. Wangler.
Unit J: Creating a Database Microsoft Office Illustrated Fundamentals.
Microsoft Visual Basic 2012 Using Procedures and Exception Handling CHAPTER SEVEN.
by Chris Brown under Prof. Susan Rodger Duke University June 2012
XP New Perspectives on Microsoft Access 2002 Tutorial 51 Microsoft Access 2002 Tutorial 5 – Enhancing a Table’s Design, and Creating Advanced Queries and.
Introduction to Graphical User Interfaces. Objectives * Students should understand what a procedural program is. * Students should understand what an.
Microsoft Visual Basic 2008 CHAPTER 8 Using Procedures and Exception Handling.
Department of Mechanical Engineering, LSUSession VII MATLAB Tutorials Session VIII Graphical User Interface using MATLAB Rajeev Madazhy
Introduction to Visual Basic. Quick Links Windows Application Programming Event-Driven Application Becoming familiar with VB Control Objects Saving and.
IE 411/511: Visual Programming for Industrial Applications
Chapter 3 Introducing Visual Basic.NET. 3.1 Visual Basic.NET Windows Programming -Used to create Windows, Web, and Console applications -Uses predefined.
Multiple Forms, Container Controls, AddHandler This presentation is based on the Forms and ContainerControls VB Projects 1.
Creating a Web Site to Gather Data and Conduct Research.
Getting Started The structure of a simple wxWidgets program, Look at where and how a wxWidgets application starts and ends, how to show the main window,
Chapter 3: Using GUI Objects and the Visual Studio IDE.
Copyright © Curt Hill Java Looking at our first console application in Eclipse.
 Application – another name for a program.  Interface – is what appears on the screen when the application is running.  Program Code – is instructions.
Chapter One An Introduction to Visual Basic 2010 Programming with Microsoft Visual Basic th Edition.
Copyright © Curt Hill Turtles The beginning of media computation.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved. 1 3 Welcome Application Introduction to Visual Programming.
Copyright © Curt Hill First Window Builder Program Easy GUIs in Eclipse.
Working with the VB IDE. Running a Program u Clicking the”start” tool begins the program u The “break” tool pauses a program in mid-execution u The “end”
Copyright © Curt Hill First Windows Program GUIs in Eclipse.
Microsoft Access 2010 Chapter 8 Advanced Form Techniques.
Chapter 2 – Introduction to the Visual Studio .NET IDE
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.
Basic & Advanced Reporting in TIMSNT ** Part Three **
Copyright © Curt Hill More Components Varying the input of Dev-C++ Windows Programs.
Java Programming: From Problem Analysis to Program Design, 3e Chapter 6 Graphical User Interface (GUI) and Object-Oriented Design (OOD)
Visual Basic for Application - Microsoft Access 2003 Programming applications using Objects.
Java Programming: From Problem Analysis to Program Design, Second Edition1 Lecture 5 Objectives  Learn about basic GUI components.  Explore how the GUI.
Copyright © Curt Hill Formatting Reals Outputs other than normal.
Copyright (c) 2003 by Prentice Hall Provided By: Qasim Al-ajmi Chapter 2 Introduction to Visual Basic Programming Visual Basic.NET.
Chapter 3 I Need a Tour Guide (Introduction to Visual Basic 2010) Clearly Visual Basic: Programming with Visual Basic nd Edition.
Microsoft Visual Basic 2012 CHAPTER FOUR Variables and Arithmetic Operations.
Copyright © Curt Hill Common Dialogs Easily Obtaining File Names in DevC++ Windows Programs.
Chapter 6 Graphical User Interface (GUI) and Object-Oriented Design (OOD)
 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.
Chapter 4.  Variables – named memory location that stores a value.  Variables allows the use of meaningful names which makes the code easier to read.
Chapter 3: I Need a Tour Guide (Introduction to Visual Basic 2012)
Chapter 2 – Introduction to the Visual Studio .NET IDE
Console and GUI Programs
3.01 Apply Controls Associated With Visual Studio Form
Using Procedures and Exception Handling
Chapter 7 Advanced Form Techniques
Organizing common actions
Variables and Arithmetic Operations
Predefined Dialog Boxes
Using Templates and Library Items
Java IDE Dwight Deugo Nesa Matic Portions of the notes for this lecture include excerpts from.
First Window Builder Program
Java Looking at our first console application in Eclipse
Unit J: Creating a Database
The beginning of media computation Followed by a demo
Presentation transcript:

Copyright © – Curt Hill Building Windows Applications in wxDev-C++

Introduction The wxDev system is a very powerful code generator It comes with a framework: a library of visual components A framework is a large collection of objects that are integrated together Copyright © – Curt Hill

Windows programming Levels of code (recall from previous presentation): –First is Windows –Second is the WinMain - yours –Third is back to Windows –Fourth is your event handlers Source code files –There are several files that are generated –There are two (or three) that you actually modify Copyright © – Curt Hill

Picture of Code Levels Copyright © – Curt Hill Operating System WinMain Event Handler

Background A component is an object that encapsulates a particular window thing such as: –Menu item –Dialog box –Radio button –Check box –Edit box –Button Copyright © – Curt Hill

Characteristics of Components Components are objects, instances of a class Each component may have three kinds of things: –Properties –Methods –Events Copyright © – Curt Hill

Properties Variables that belong to an object –Properties determine most of the behavior of the item –There is almost always a reasonable default –We may change them using the property inspector or through code –The most important property is the name –Some are modifiable at design time, others at run time, most at both –EG the height of a window is a property Copyright © – Curt Hill

Methods Methods are object member functions They allow us to initiate and move along the process They usually have simple parameters –The member data does most of the data transfer Copyright © – Curt Hill

Events Events are reactions to user actions on the interface Events are unpredictable –Unlike the console interface For example what do you do when they click a menu? This is an event, which starts a method or member function Copyright © – Curt Hill

Using Properties The properties (variables) and methods (functions) belong to the object or component We cannot access these directly –Must use a dereferencing item So you use a pointer plus field notation x->y –Where x is the name of the component and y is the name of either the property or method Copyright © – Curt Hill

The process of building a Windows program Create a new project, an application Save it under a new name –Create a directory just for this project Name after the goalie –Save the unit and project under different names –There are two C++ files, so must have different names Next screens show this for wxDev C++ Copyright © – Curt Hill

New Project Copyright © – Curt Hill

Choose wxWidgets Frame Copyright © – Curt Hill

Creating New wxFrame This gives a project with an wxFrame –Do not use any of the others Fill in the project name on the bottom When you save it you get the following dialog –Directory should have same name as project Copyright © – Curt Hill

Save Project Copyright © – Curt Hill

Create a new directory Each project should be in its own directory When you click on new button you get the following screen Prefer that the directory name is the goalie name Copyright © – Curt Hill

Naming Directory Copyright © – Curt Hill

After rename Move into this new directory by clicking on it If you lose the opportunity to rename, just right click Copyright © – Curt Hill

Save Project Copyright © – Curt Hill

New wxFrame Dialog Copyright © – Curt Hill

Finally Copyright © – Curt Hill

Project Files There are many –FirstGUIApp.cpp –FirstGUIApp.h –FirstGUIApp.rc –FirstGUIFrm.cpp –FirstGUIFrm.h –FirstGUIFrm.wxfrm Because of the multitude we will zip entire directories to hand these in –Discuss this later Copyright © – Curt Hill

Demo Program For the duration of the demonstration we need the program to do something This program will read in a Fahrenheit temperature and output the equivalent Celsius temperature We will need: –Two Labels, one Edit, three buttons Copyright © – Curt Hill

Add components Pull the component from the palette –Click the component –Drag the place where it should be on the form Some give you a choice –Labels and buttons must be positioned and sized –A menu always is in the menu position, upper left part of window –A common file dialog box can be put anywhere because it does not show Copyright © – Curt Hill

Add components (continued) Customize it by changing needed properties –Start with the property inspector –Most of this will be done here –The second tab of the property inspector is events Test it –Run and see how it looks –Even before any actions Copyright © – Curt Hill

Important components Button Label Edit MessageBox Others will be seen later Copyright © – Curt Hill

Static Text wxStaticText is component name What is it? –Just text that adorns your window –Usually labeling that does not change, but you can change it in the code Where: Common Controls Copyright © – Curt Hill

Common Controls Copyright © – Curt Hill

Static Text properties: Label –Usually will generate LabelN, where N is the number of these that you currently have done –The contents of the text box –The caption is a String field Name –Usually it will generate WxStaticTextN –This is fine if you do not reference from code Copyright © – Curt Hill

Static Text properties: Alignment –Left or right or center Font –Most things that display have the font property positioning –Height –Left –Top –Width Copyright © – Curt Hill

Dragging a Label Copyright © – Curt Hill

Once in Place Copyright © – Curt Hill

Customization Copyright © – Curt Hill

Frame The Frame (main window) is also an object Its Title property is the Title Bar text This is also changed with the Property Inspector –Select the entire frame –Type in Title Default value for Captions and Texts is the variable name Copyright © – Curt Hill

Edit box What is it? –The windows way to enter pieces of text or numeric data through the screen –Contains one line of text –It allows the user to type new things, edit old things or combination of both –Class name is wxTextCtrl Where: Common Controls Copyright © – Curt Hill

Edit principal properties: Name: what you will call it in code Text: Its current contents –This can be set by Property Inspector at design time –At runtime we use GetValue() or SetValue(string) If it is numeric there is one more step –Converting to a numeric value –This requires a String method Copyright © – Curt Hill

Conversion We have two problems that need handling Even if an edit contains a single digit it is not numeric Thus we need to be able to: –Convert a string to a number –Convert a number to a string We will need to see wxString to start to solve these problems Copyright © – Curt Hill

wxString Not a visual component It is the type used in Text or Label objects A variable length string object The two methods we want today are: ToInt() ToDouble() These are separated by a dot rather than the -> we usually see Copyright © – Curt Hill

An Example Suppose that we have: –An Edit box named Edit1 Extract the value from Edit1 double d = Edit1-> GetValue().ToDouble(); An error will occur if the value is not numeric Copyright © – Curt Hill

Creating a String A wxString may be created by a cast wxString str = wxString(“Hi”); You may concatenate with the put to Thus: str = str << x << “ ” << y; Remember, comma does not do what you want This may be done without declaring a variable Copyright © – Curt Hill

The One Step You may set a label and create the label in one statement Suppose lab is a static text item: lab-> SetLabelText( wxString("Fahrenheit: ") <<f<<", Celcius: "<<c); Copyright © – Curt Hill

Once more on String It will not accept the concatenation of a string and number Thus Edit->SetLabelText(“x: ”<<x); will not work The quoted string is constant text and << is not overloaded for it Instead use C++ cast to make constant into String: Edit1->SetLabelText( wxString(“x: “)<<x); Copyright © – Curt Hill

Button What is it? –A control which may be clicked –Usually labeling that does not change, but you can change it in the code Where: Common Controls The principal properties: –Label: text of button –Name: Your name instead of Button1 –Event: Onclick Copyright © – Curt Hill

Next Adding Edits and Buttons is mostly the same as Labels A button must have an event handler Let consider the creation of this Copyright © – Curt Hill

Button has been drug Copyright © – Curt Hill

Caption Changed Copyright © – Curt Hill

Select Event Tab Copyright © – Curt Hill

Select New Function Copyright © – Curt Hill

Code Pane Copyright © – Curt Hill

Event Handler When you allow DevC++ to build a new event handler, it creates a blank method We now need to type in the code for this Our process is as follows: –Get the data –Do calculations –Display the result Copyright © – Curt Hill

The Code Copyright © – Curt Hill

Good Practice Every good Windows program should have three options –In menu or buttons These are: –Do the calculation –Exit the program –Show who is responsible Lets now do the last two Copyright © – Curt Hill

Exit We will need a button In the event handler is the single statement: Destroy(); If Destroy is executed it will end the program Copyright © – Curt Hill

About Every good windows needs either a Help menu with an About sub-menu or a button that does the same We will use a MessageBox for this Copyright © – Curt Hill

MessageBoxW Displays a UniCode string in a predefind dialog box Quick dialog box with very limited controls Only allow some static text and several pre-labeled buttons There are four parameters Copyright © – Curt Hill

Example MessageBoxW(NULL,,,MB_OK) Four parameters: –NULL, all in caps –Text in the box –Caption of dialog box –ID which indicates type of buttons: MB_OK Several other as well MB_OKCANCEL This function returns something based on button pressed Copyright © – Curt Hill

UniCode and Windows MessageBoxes in recent versions of Windows use UniCode but before this used ASCII –They were just in quotes –Now need a L prefixing the string These are long character strings –Two bytes per character Prefix the quote with a L MessageBoxW(NULL, L”You have done wrong”, L”Error”, MB_OK); Copyright © – Curt Hill

More Code The IDE generates lots of code in our program Our code generally starts at about line 70 Do not change the generated code! –You have to understand what it does to be able to modify it Copyright © – Curt Hill

So Far Copyright © – Curt Hill

Inheritance Our programs will use a variety of existing components These contain substantial behavior that we did nothing to provide For example our main window is a wxFrame component We did nothing to make it have a kill button Rather it inherited that functionality Copyright © – Curt Hill

Other Thoughts You may name components any legal C++ name If the code will reference the component it is a good idea Avoid names that you will use for other things, such as Destroy Copyright © – Curt Hill

Now Do This It is time for you to write this exact program We will write a program that will convert Fahrenheit temperatures and convert to Celsius using following formula Copyright © – Curt Hill

What Did We Learn? How to make the IDE generate a Windows program Several components: –Labels, Edits, Buttons MessageBox New notation –-> and. Copyright © – Curt Hill