CS-360
Course Information
GUI & Windows Programming Dr. Richard R. Eckert Computer Science Department SUNY Binghamton Fall, 2003
MWF, 10:50-11:50 A.M. LH-13
Office: EB-N6 Phone: 777-4365 Office Hours: TBA Email:
[email protected] http://www.cs.binghamton.edu/~reckert/
CS-360
link for syllabus, notes, programs, assignments, etc.
Class Listserv:
TA Information: TBA
[email protected]
Text Book Information
Course Prerequisites CS-220, Computer Organization and Assembling Language Programming CS-240, Data Structures Some knowledge of C or C++ helpful
Not
essential
Required: Kate Gregory, “Special Edition Visual C++ 6 .NET” Que, 2002, ISBN 0-7887-2466-9. (For VC++ MFC & .NET programming with Visual Studio .NET) Recommended: Charles Petzold, "Programming Windows," Fifth Edition, Microsoft Press, 1999, ISBN 1-57231-995-X. (For Win32 API) Kruglinski, Shepherd, Wingo, "Programming Microsoft Viausl C++", Fifth Edition, Microsoft Press, 1998, ISBN 1-57231-857-0, (For VC++ MFC Programming-about 50% of course) Paul E. Kimball, "The X Tookit Cookbook," Prentice Hall PTR, 1995, ISBN 0-13-973132-6. (For XWindows Programming) Many Books on Reserve
Policies Evaluation
Assignments Individual
Programming Assignments Term Examinations (2) Final Project
Due
on due date, but can be turned in to CS-360 drop drawer in filing cabinet outside CS Department any time that day or night 5% off for every day late
45% 40% 15%
) Weekends
No
late
and holidays not included
assignments accepted more than one week
Originality Any
work found to be copied will be grounds for an F in the course
1
Course Schedule (weekly) 1. Intro to GUIs & Windows Programming 2. Using Visual Studio,Win32 API Programming 3. MFC Programming: App/Window Approach 4. MFC Programming: Doc/View Approach 5. Graphics, Animation, Bitmaps, Timers 6. Windows Controls, Dialog Boxes 7. Printing, Mapping modes, Serialization, File I/O, Dialog-based Apps, Windows Common Dialogs 8. Toolbars & Status Bars; Windows Clipboard; Multimedia Programming 9. ODBC & ADO Data Bases
Introduction To GUIs and Windows Programming
Course Schedule (continued) 10. COM, ActiveX, & ATL 11. Multitasking & Multithreading; DLLs 12. Network Programming with TCP/IP Sockets; Creating Web Services 13. .NET Managed Code & the Common Language Runtime 14. Program Integration: Multilanguage Apps, Mixing .NET Managed & Unmanaged Code 15. The X Window System 16. X Toolkit Intrinsics, OSF/Motif Toolkit
User Interfaces Connection
between the computer and
the user Two types: Command
Line
GUI--Graphical
Command Line Interfaces User
types commands ==> must remember Results scroll by Text-based “Interactive” but hard to use No direct interaction between user and screen
(Visual)
Visual (Graphical) Interfaces
Show graphical objects on screen e.g.,
images, icons, buttons, scroll bars
User interacts using pointing device Intuitive
Objects
can be dragged, buttons pushed, etc....
Better way of using screen space Panes
can overlap panes can be brought to forefront Desktop metaphor (like papers on a desk) Underlying ) Well,
not exactly!
2
Graphical Interfaces, Continued
Main Feature of GUIs: THE
Use graphics to organize user workspace Environment allows many tasks to be performed simultaneously Different tasks share screen space Visually rich way of conveying information WYSIWYG display of documents
Brief History of GUIs
Rectangular
area of screen onto which a program draws text and graphics. User interacts with program using pointer device to select objects inside. Some
title bar, client area, menu bar, tool bars, scroll bars, max/min/close buttons, etc.
Xerox PARC--Alto Computer
1968: ARPA-funded Stanford Research Center (Doug Engelbart) First windows (screen sliced up into overlapping panes) Only textual info Underlying windows could be popped to the top Selection done with light pen Invented the mouse
1977: Radio Shack TRS-80, Commodore Pet, Apple II 1981: IBM PC, DOS 1983: Apple Lisa (failure) 1984: Apple Macintosh--standard for GUIs 1985: Microsoft releases Windows 1.0 Difficult to program Prone to crashing Needed hardware not yet available 1987: Windows 2.0 (still real mode only) 1988: Windows/386 (Virtual 86 mode on 386==>multiple DOS sessions in windows)
window components:
) border,
1970s
Recent History (PCs)
WINDOW
First
GUI Cursor tracked position of mouse WYSIWYG Windows with precise text Displayed more than just text First interactive painting program Technology “acquired” by Apple
Recent History (Microsoft)
1990: Windows 3.0 80x86
protected mode, up to 16 Meg memory, cooperative multitasking
1992: Windows 3.1, Windows for Workgroups 3.11
TrueType fonts, multimedia, protected mode only; Networking
1993: Windows NT 32-bit
flat memory space, 16 MB, thread-based pre-emptive multitasking, separate from DOS, multi-platform, networking, secure)
3
Recent History (Microsoft)
1995: Windows 95 Runs
on 4 Meg, long file names, plug and play, new controls, new desktop/window style Hybrid 16/32 bit OS, depends on DOS, lacks security of NT, no portability to RISC
1998: Windows 98
2000-01: Windows 2000, ME, XP
Integrated
of 95-98-NT Home: for home use NT->2000->XP Professional: for businesses XP: 95->98->Me->XP
Microsoft Developer Studio (Visual Studio .NET) Win32 API Programming MFC Programming .NET Managed & Unmanaged Code Integrating Languages under .NET X-Windows Programming Example programs and notes online at: ) http://www.cs.binghamton.edu/~reckert/ ) “CS-360” link
MFC Programming
Swing Platform JDK
independent is free
The X Window System Developed
at MIT, late 1980s graphics programming interface Independent of machine architecture/OS (but most used under UNIX) Networked
Win32 API Programming
Microsoft Windows Visual C++ Using
AWT
fancier user interface; latest multimedia (DVD); upgraded web & network capabilities; improved help (remote); improved performance & security
Course Content
IBM OS/2: Presentation Manager Sun Microsystems: Java
Web functionality
Upgrades
)
Other GUI-Windowing Systems
The MFC Class Hierarchy The Application/Window Approach The Document/View Approach Using “AppWizard” & “ClassWizard” Drawing, Menus, & Dialog Boxes with MFC File Handling and Printing Dialog-Based MFC Applications & Common Dialog Boxes DLLs; Windows Multimedia Multitasking and Multithreading COM, ActiveX, ATL Using Data Bases with ODBC & ADO Network Programming (TCP/IP) Web Services using Microsoft IIS
Event-Driven Programming (Messages) Menus and other Resources Text and Graphics Mouse and Keyboard Bitmaps, Animation, Timers Child Window Controls Child and Popup Windows Dialog Boxes The Clipboard
Introduction to Windows Programming in Visual Basic A
Quick Introduction
4
Microsoft .NET Framework Unmanaged
vs. Managed Code Web Services Integrating with other .NET Languages
X-Windows Programming Client/Server X
Model
Display Servers
XLIB
Programming Toolkits and Widgets Xt
Intrinsics OSF/Motif
Windowing Systems Features Consistent user interface Display within a window Menus to initiate program functions Make use of child window “controls”:
Consistent User Interface, continued
) predefined
windows used with main program window ) examples: buttons, scroll bars, edit controls, list boxes, drop-down list boxes, combo boxes ) Dialog box--popup window containing several controls
Multitasking Every program acts like a RAM-resident popup Programs run “simultaneously” Each program occupies its own window
User
Windows Multitasking Features
Cooperative (Windows 3.xx) Programs Programs
give up control so others can run coexist with other programs
Preemptive (Windows NT, 95, 98, XP) Thread-based:
System timer allocates time slices to running program threads
interacts with program in its window
User can switch between programs
Programs have same look and feel Same built-in logic to: draw text/graphics display menus receive user input controls, dialog boxes, use of mouse
Under both systems, code is moved or swapped into and out of memory as needed
5
Windows Object Orientation
Windows Memory Management
Older versions: 16-bit, segmented memory Dictated
A window is handled like a C++ object Has
a user-defined type (Windows class) of class created at run time Messages sent to windows affect their behavior
Hard
Instances
by processor architecture to program
Newer versions: 32-bit, flat memory model Easier
to program
As old programs terminate, new ones start Code
swapped into and out of memory
Fragmentation can occur Windows must consolidate memory space Moves blocks of code/data continually
Memory Management, continued
Static vs. Dynamic Linking
Programs can share code located in other files (Dynamic linking)
Static Linking ) Code
time
incorporated into executable at link
Dynamic Linking Code
is put into separate modules
) These
Linker ) Only
are loaded at run time
generates relocation information that info is put into the executable programs
) Smaller
DLL
loaded when needed info used to get DLL function code as needed
Relocation
6
Pros/Cons of Dynamic Linking
Device Independent Graphics Interface
Smaller programs (code is not in program) DLL can be used by many programs with no memory penalty
Only
loaded once!
Updates to DLLs don’t require recompilation of programs using them Disadvantage--DLL must be present at run time ==> no standalone programs
Device Independent Graphics Interface
May use device drivers (HW control programs)
Program
GDI
Driver
Hardware
Thus graphics I/O done in a “standard” way Programs will run unaltered on other HW platforms
Classical Win32 API Windows programming Use C to access raw API functions directly No C++ class library wrappers to hide API Hard way to go, but most basic Faster executables Provides understanding of how Windows and application program interact Establishes a firm foundation for MFC programming We will try to do both
Windows programs don’t access hardware devices directly Make calls to generic functions within the Windows ‘Graphics Device Interface’ (GDI) The GDI translates these into HW commands
Program
GDI
Hardware
Windows API The interface between an application and Windows A library of functions Windows programs can call Several versions
Win16
(16 bit apps for Windows 3.xx) Win32 (32 bit apps for Windows NT/95 & successors) Win32s (patches Win16 to create 32 bit apps that run under Windows 3.xx)
Class-based MFC Windows Programming
Microsoft’s MFC Library Borland’s OWL Library Characteristics:
Encapsulate
the API functions into classes a logical framework for building Windows applications Reusable code Provide
7
MFC Library Microsoft’s C++ Interface to Windows API O-O Approach to Windows Programming Some 200 classes API functions encapsulated in the MFC Classes derived from MFC do grunt work Just add data/functions to customize app Provides a uniform application framework
Microsoft Visual C++
Developer Studio IDE 3 Windows application development systems C
programs using Win32 API programs using MFC .NET Framework Class Library & the CLR C++
Some Developer Studio IDE Components Editors C/C++, Resource Compilers Linker Debugger Wizards On-line Help
Some MFC Characteristics Reusable code Compact executables Faster program development
But
Text/Resource
Microsoft .NET
platform to run code on A class library of code that can be used from any language New programming interactive development environment New versions of some programming languages A set of server products New way of designing & creating applications that share work between components (local and distributed over the internet)
Programs must be written in C++ Require the use of classes==> Programmer
must know OOP
.NET Framework
What is it? A
a steep learning curve is required there is less flexibility
And
Platform for developing distributed applications for the Internet Design Goals: Provide
high degree of language interoperability a managed runtime environment Provide simple software deployment & versioning Provide high-level code security through code access security & strong type checking Provide consistent object-oriented programming model Facilitate application communication by using industry standards such as SOAP & XML Simplify Web application development Provide
8
Components of .NET
The .NET Framework Class Library (FCL)` Organized
into namespaces (like packages) Handle things like: Data, IO (simple & file), Windows & Web Forms, Windows Controls, User Interfaces, Drawing, Threading, Exceptions, Networking, Web Services, Data Bases, XML, ASP, Security, Collections, … lots of others
Common Type System (CTS) Common Language Specification (CLS) Common Language Runtime (CLR)
Common Language Runtime
Compilation in the .NET Framework
Some Types of VC++ .NET Applications
Sequential Programming (Console Applications) Standard programming--program solicits input (polling loop) Approach follows a structured sequence of events Example--averaging grades:
name Input first grade Input second grade Input third grade, etc. Calculate average Output average
Automatic garbage collection Elimination of memory leaks Code access security Simplified versioning Simple & reliable deployment Deep cross-language integration & inheritance Debugging/profiling across different languages Performance Scalability
Windows Console applications Win32 API Applications MFC applications MFC ActiveX Control projects MFC ISAPI projects ATL, ATL Server, & ATL Server Web projects Managed C++ applications Managed C++ Web services
Event-Driven Programming
Input
Designed to avoid limitations of sequential, procedure-driven methodologies Process user actions (events) as they happen: nonsequential Program doesn’t solicit input OS detects an event has happened (e.g.., there’s input) and sends a message to the program Program then acts on the message Messages can occur in any order
9
Sequential vs. Event-Driven Programming
Standard Sequential programming: Program Program
does something & user responds controls user (the tail wags the dog)
Event-Driven Programming: Used
by Windows does something and program responds User can act at any time User controls program (the dog wags the tail) OS really is in control (coordinates message flow to different applications) Good for apps with lots of user intervention User
10