Introduction to Windows Programming Jim Fawcett CSE 681

  • Slides: 26
Download presentation
Introduction to Windows Programming Jim Fawcett CSE 681 – Software Modeling and Analysis Fall

Introduction to Windows Programming Jim Fawcett CSE 681 – Software Modeling and Analysis Fall 2005 Basic Windows Programming Page 1

References · Developing Professional Applications for Windows 95 and NT Using MFC, Marshall Brain

References · Developing Professional Applications for Windows 95 and NT Using MFC, Marshall Brain and Lance Lovett, Prentice Hall, 1997. – Now out of print, but some copies still available on-line. · Practical Visual C++ 6, Jon Bates and Tim Tompkins, Que, 1999. – Currently available through Barnes & Noble, Borders, and Amazon. com. · Programming Windows with MFC, Jeff Prosise, Microsoft Press, 1999. – This is a large, effective book, used in CSE 778 – Advanced Windows Programming, but overkill for this course. · Windows Forms Programming in C#, Chris Sells, Addison-Wesley, 2004 – Comprehensive and very well written. Basic Windows Programming Page 2

Basic Windows Programming Page 3

Basic Windows Programming Page 3

The Simplest Classical Windows Program · Output from the MINWIN program is shown on

The Simplest Classical Windows Program · Output from the MINWIN program is shown on the next slide. The program: – Creates a frame window – Paints a fixed text message in the window – Reacts to left mouse button clicks by creating a Message. Box · You will the program code, minwin. cpp, and project workspace, minwin. dsw in the folder MINWIN. www. ecs. syr. edu/faculty/fawcett/handouts/Core. Technologies/Windows Programming/code/basic. Windows/Minwin Basic Windows Programming Page 4

Basic Windows Programming Page 5

Basic Windows Programming Page 5

Basic Windows Programming Page 6

Basic Windows Programming Page 6

Basic Windows Programming Page 7

Basic Windows Programming Page 7

The Simplest MFC based Program · Output from the MFCWIN program is shown on

The Simplest MFC based Program · Output from the MFCWIN program is shown on the next slide. The program: – Creates a frame window – Paints a fixed text message in the window – Reacts to left mouse button clicks by creating a Message. Box · You will the program code, mfcwin. cpp, and project workspace, mfcwin. dsw in the folder MINWIN. www. ecs. syr. edu/faculty/fawcett/handouts/Core. Technologies/Windows Programming/code/basic. Windows/Mfc. Win Basic Windows Programming Page 8

Basic Windows Programming Page 9

Basic Windows Programming Page 9

Dialog Based Applications · A dialog is an opaque window, called a form, on

Dialog Based Applications · A dialog is an opaque window, called a form, on which are embedded a collection of smaller windows called controls. – The main dialog form is wrapped in a dialog class, derived from MFC’s CDialog class. – Each control is a window with a self contained set of functionality that dialog designers use “as-is”, or modify in limited ways. – Controls are placed on the dialog form by dragging from a palette in the dialog resource editor. – Controls are hooked into the application processing by providing message handlers in the main dialog class that access the controls using CDialog: : Get. Dlg. Item(…) and CDialog: : Set. Dlg. Item(…) member functions. Basic Windows Programming Page 10

Basic Windows Programming Page 11

Basic Windows Programming Page 11

Structure of MFC Dialog based Application Basic Windows Programming Page 12

Structure of MFC Dialog based Application Basic Windows Programming Page 12

Frame Window Applications · A frame window application consists of a window that supports

Frame Window Applications · A frame window application consists of a window that supports a large client area in which text and graphics are displayed, embedded in a frame that supports menus and perhaps some controls. – All text and drawing in the client area are supported by the Graphics Device Interface Object (CGDIObject) and Device Context (CDC) classes. – Most frame window applications use the Single Document Interface (SDI) or Multiple Document Interface (MDI) architectures. These follow document/view architecture structure: • Documents provide all the support for managing the program’s data, including reading and writing from persistent storage. • Views provide all the support for displaying one or more views of the data and most user interactions with the program. Basic Windows Programming Page 13

Basic Windows Programming Page 14

Basic Windows Programming Page 14

Basic Windows Programming Page 15

Basic Windows Programming Page 15

Basic Windows Programming Page 16

Basic Windows Programming Page 16

Win. Forms · · Win. Forms were introduced with. Net and are very similar

Win. Forms · · Win. Forms were introduced with. Net and are very similar to Visual Basic RAD Forms in Visual Studio, version 6. 0. Forms are used for both Frame Window and Dialog Applications. – You get a dialog application by pulling lot’s of controls onto a form and setting the Form properties to have dialog behavior. – You get a Frame Window by painting the Form your self, with the help of the. Net Graphics Device Interface (GDI++) · Forms are quite easy to build with the Visual Studio Designers – Lots of controls are available in the toolbox – Intellisense and the Object Browser make learning very fast. Basic Windows Programming Page 17

Simple Text Editing Demo · It is relatively easy to build Forms that: –

Simple Text Editing Demo · It is relatively easy to build Forms that: – open and save files using a File. Dialog. – Read files from Streams and edit text in a Text. Box. • The Stream and Text. Box do almost all the work. – Uses menus to interact with files or set program behaviours. · www. ecs. syr. edu/faculty/fawcett/handouts/CSE 681/code/project 2 Helper. F 05 Basic Windows Programming Page 18

Basic Windows Programming Page 19

Basic Windows Programming Page 19

Programs with Communicating Forms · Often we want to use more than one Form

Programs with Communicating Forms · Often we want to use more than one Form in a program. – That means that we have to provide a way for them to communicate. – Each Form that needs to contact another must have a reference to it. – That happens automatically for the parent. The parent creates a Child Form attached to a reference it holds onto for later use. – For the Child to talk back, the Parent must pass it a reference to itself, usually in the Childs constructor. – For these conversations to be useful, both Parent and Child must provide functions for the other to call. · www. ecs. syr. edu/faculty/fawcett/handouts/CSE 681/code/project 2 Helper. F 05 Basic Windows Programming Page 20

Basic Windows Programming Page 21

Basic Windows Programming Page 21

An Example – Form with Browse Control · If our program needs more than

An Example – Form with Browse Control · If our program needs more than a simple File. Dialog provides, we may wish to build a more sophisticated or specialized control. · On the next page you will see an example of a Form, written in managed C++ invoking the services of a Browse Control, written in C#. · www. ecs. syr. edu/faculty/fawcett/handouts/Core. Technologies/Windows Programming/code/demo. Cpp. Win. Form Basic Windows Programming Page 22

Basic Windows Programming Page 23

Basic Windows Programming Page 23

Frame Window based on Form · The next slide illustrates a Win. Form application

Frame Window based on Form · The next slide illustrates a Win. Form application that behaves like a Frame Window: – It paints is client area with: • An image • A drawn text caption • A line – But it also has inserted a control, showing mouse coordinates. This illustrates that controls can be used on Frame Windows: • They paint their own surfaces • They can react to event messages from their parent window. · www. ecs. syr. edu/faculty/fawcett/handouts/Core. Technologies/Windows Programming/code/CSharp. Win. Form Basic Windows Programming Page 24

Basic Windows Programming Page 25

Basic Windows Programming Page 25

End of Presentation Basic Windows Programming Page 26

End of Presentation Basic Windows Programming Page 26