Graphical User Interface Programming
CPSC-355 Chapman University Danny Lamb
http://www.ProfessorDan.com Cpsc355@ProfessorDan.com Dan@ProfessorDan.com W 619 464-8252 H 619 267-2207
Catalog Description
Prerequisite, CompSci 231 or equivalent. Students gain experience in designing applications for different Graphical User Interfaces. Students investigate various application frameworks using objectoriented component reuse techniques. Several windowing systems are explored and evaluated. 3 credits.
17-Nov-09
Dan Lamb Chapman University CPSC-355
2
Course Objectives
The course has the following objectives:
To develop a basic understanding of C++ application frameworks, To develop a general knowledge of Graphical User interface components, To develop a detailed knowledge of different windowing systems.
17-Nov-09
Dan Lamb Chapman University CPSC-355
3
Major Study Units
Introduction to C++ Application Frameworks Graphical User Interface Components Labels, Buttons, Toolbars,Menus Dialog Boxes and Forms User Input and Error Handling Window classes Graphic classes OLE Designing Help systems
17-Nov-09
Dan Lamb Chapman University CPSC-355
4
Instructional Strategies
Traditional lectures as well as hands-on computer experience. Laboratories should be designed to reinforce the textual material presented in class. At least one group project should be assigned during the semester. Students will be expected to provide extensive documentation for all computer projects assigned in class. Methods of Evaluation: Programming assignments and at least one in-class midterm and a final exam should be given.
17-Nov-09
Dan Lamb Chapman University CPSC-355
5
The Text
Newest Version of Visual C++ .NET is Covered
The Old Book (a good Ref)
17-Nov-09
Dan Lamb Chapman University CPSC-355
6
Additional References
Visual C++ 6 Programming Blue Book
Coriolis ISBN 1-57610-324-2
Wrox ISBN 1-861000-88-X
Beginning Visual C++ 6
17-Nov-09
Dan Lamb Chapman University CPSC-355
7
C++ Review
Why C++
oop
Member Functions Data Over-Riding Functions
Classes
Inheritance
Constructor Destructor
Dan Lamb Chapman University CPSC-355 8
17-Nov-09
Windows vs Other
Main()
Single Entry Point Single Exit Point Functions Called from main() Common to:DOS, UNIX, Embedded Systems Make Files
Starting point Creates Window and Processes Messages
Dan Lamb Chapman University CPSC-355 9
WinMain()
17-Nov-09
What Is MFC
MFC
Microsoft Foundation Class Using MFC will simplify programming by hiding the WinMain function and structuring the messagehandling process. Provides a Library of Classes as a starting point for your Windows Applications
17-Nov-09
Dan Lamb Chapman University CPSC-355
10
The Development Environment
17-Nov-09
Dan Lamb Chapman University CPSC-355
11
The Tools
The Resource Editors—Workspace ResourceView The C/C++ Compiler The Source Code Editor
The Resource Compiler
The Linker The Debugger
17-Nov-09
Dan Lamb Chapman University CPSC-355
12
Tools Cont.
AppWizard
ClassWizard
The Source Browser Online Help
Windows Diagnostic Tools
Source Code Control The Gallery
17-Nov-09
Dan Lamb Chapman University CPSC-355
13
The Developer Studio
17-Nov-09
Dan Lamb Chapman University CPSC-355
14
Files Used by the Developer Studio
File Extension APS BSC Description
Supports Resource View Browser information file
IDL
NCB SLN
IDLInterface Definition Language file
Supports Class View Solution File *
SUO
VCPRO
17-Nov-09
Holds solution options and configuration
Project File *
Dan Lamb Chapman University CPSC-355 15
Application Framework
CH2
Standard Structure
Visual C++ tools reduce coding drudgery
MFC library
17-Nov-09
Dan Lamb Chapman University CPSC-355
16
MFC Library
A C++ interface to the Windows API
General-purpose (non-Windows-specific) classes, including:
Collection classes for lists, arrays, and maps A useful and efficient string class Time, time span, and date classes File access classes for operating system independence Support for systematic object storage and retrieval to and from disk
A "common root object" class hierarchy Streamlined Multiple Document Interface (MDI) application support
Dan Lamb Chapman University CPSC-355 17
17-Nov-09
The Cwin and Document Interface
17-Nov-09
Dan Lamb Chapman University CPSC-355
18
Documents and Views
17-Nov-09
Dan Lamb Chapman University CPSC-355
19
MFC Library Application Types
And Views
SDI
Single Document Interface
Multiple Document Interface Multiple Top-Level Windows Interface
MDI
MTI
17-Nov-09
Dan Lamb Chapman University CPSC-355
20
“Do-Nothing” Application—EX03A
LAB Use AppWizard Modify the example (edit the OnDraw function)
void CEx03aView::OnDraw(CDC* pDC) { pDC->TextOut(0, 0, "Hello, world!");
// prints in default font // & size, top left corner circle interior 100 units in diameter
pDC->SelectStockObject(GRAY_BRUSH);
pDC->Ellipse(CRect(0, 20, 100, 120)); }
// selects a brush for the
// // // draws a gray circle
17-Nov-09
Dan Lamb Chapman University CPSC-355
21
Resource Editor
All of your projects will create a Help About dialog box which will include:
Name Project number (WEEK) Date Version Other Optional
Picture etc.
17-Nov-09
Dan Lamb Chapman University CPSC-355
22
Diagnostic Macros
TRACER will insert the statement TraceEnabled = 1 Other debug tools
17-Nov-09
Dan Lamb Chapman University CPSC-355
23
Basic Event Handling
CH4
Where do events come from
Key Press mouse move left click Example Function void CMyView::OnLButtonDown(…) afx_msg
Message Map
17-Nov-09
Dan Lamb Chapman University CPSC-355
24
Message Handling In MFC and Windows
17-Nov-09
Dan Lamb Chapman University CPSC-355
25
The Message Map
WM_LBUTTONDOWN
void CMyView::OnLButtonDown(UINT nFlags, CPoint point) { // event processing code here }
In the Header file afx_msg void OnLButtonDown(UINT nFlags, CPoint point); Application
BEGIN_MESSAGE_MAP(CMyView, CView)
ON_WM_LBUTTONDOWN() // entry specifically for OnLButtonDown
// other message map entries
END_MESSAGE_MAP()
17-Nov-09 Dan Lamb Chapman University CPSC-355 26
Mapping Modes
Coordinates
17-Nov-09
Dan Lamb Chapman University CPSC-355
27
Mapping Modes
Coordinates cont.
Mapping Mode
MM_LOENGLISH
MM_HIENGLISH MM_LOMETRIC MM_HIMETRIC MM_TWIPS
Logical Unit
0.01 inch
0.001 inch 0.1 mm 0.01 mm
1/ 1440
inch
17-Nov-09
Dan Lamb Chapman University CPSC-355
28
Mapping Modes
Coordinates cont.
void CMyView::OnDraw(CDC* pDC) { CRect rectClient; GetClientRect(rectClient); pDC->SetMapMode(MM_ANISOTROPIC); pDC->SetWindowExt(1000, 1000); pDC->SetViewportExt(rectClient.right, rectClient.bottom); pDC->SetViewportOrg(rectClient.right / 2, rectClient.bottom / 2); pDC->Ellipse(CRect(-500, -500, 500, 500)); }
17-Nov-09 Dan Lamb Chapman University CPSC-355 29
void CEx05aView::OnLButtonDown(UINT nFlags, CPoint point)
{ if (m_rectEllipse.PtInRect(point)) { if (m_nColor == GRAY_BRUSH) m_nColor = WHITE_BRUSH; else
m_nColor = GRAY_BRUSH;
InvalidateRect(m_rectEllipse); } }
17-Nov-09
Dan Lamb Chapman University CPSC-355
30
Look at Mapping Modes
Look at examples 5a, 5b, 5c
17-Nov-09
Dan Lamb Chapman University CPSC-355
31
Computer Lab Reserved
For CPSC-355 GUI Programming On Thursday Night 5:30 to 9:45 PM During this Term