1 / 26

Introduction to Windows Programming

Introduction to Windows Programming. Jim Fawcett CSE 681 – Software Modeling and Analysis Fall 2005. References. Developing Professional Applications for Windows 95 and NT Using MFC, Marshall Brain and Lance Lovett, Prentice Hall, 1997.

jered
Download Presentation

Introduction to Windows Programming

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

  2. 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.

  3. 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 MessageBox • You will the program code, minwin.cpp, and project workspace, minwin.dsw in the folder MINWIN.www.ecs.syr.edu/faculty/fawcett/handouts/CoreTechnologies/WindowsProgramming/code/basicWindows/Minwin

  4. 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 MessageBox • You will the program code, mfcwin.cpp, and project workspace, mfcwin.dsw in the folder MINWIN.www.ecs.syr.edu/faculty/fawcett/handouts/CoreTechnologies/WindowsProgramming/code/basicWindows/MfcWin

  5. 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::GetDlgItem(…) and CDialog::SetDlgItem(…) member functions.

  6. Structure of MFC Dialog based Application

  7. 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.

  8. WinForms • WinForms 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.

  9. Simple Text Editing Demo • It is relatively easy to build Forms that: • open and save files using a FileDialog. • Read files from Streams and edit text in a TextBox. • The Stream and TextBox do almost all the work. • Uses menus to interact with files or set program behaviours. • www.ecs.syr.edu/faculty/fawcett/handouts/CSE681/code/project2HelperF05

  10. 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/CSE681/code/project2HelperF05

  11. An Example – Form with Browse Control • If our program needs more than a simple FileDialog 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/CoreTechnologies/WindowsProgramming/code/demoCppWinForm

  12. Frame Window based on Form • The next slide illustrates a WinForm 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/CoreTechnologies/WindowsProgramming/code/CSharpWinForm

  13. End of Presentation

More Related