COS220 Concepts of PLs
This presentation is the property of its rightful owner.
Sponsored Links
1 / 154

COS220 Concepts of PLs AUBG, COS dept PowerPoint PPT Presentation


  • 92 Views
  • Uploaded on
  • Presentation posted in: General

COS220 Concepts of PLs AUBG, COS dept. Lecture 30aa Alternate Ways of Developing Windows Based Applications Reference: MS Visual C++,Deitel, Chapter 2.7. Lecture Contents. Applications classified: Console applications Windows based applications Internet/Web based applications

Download Presentation

COS220 Concepts of PLs AUBG, COS dept

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.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript


Cos220 concepts of pls aubg cos dept

COS220 Concepts of PLs AUBG, COS dept

Lecture 30aa

Alternate Ways of Developing Windows Based Applications

Reference: MS Visual C++,Deitel, Chapter 2.7


Lecture contents

Lecture Contents

Applications classified:

Console applications

Windows based applications

Internet/Web based applications

Alternate ways to Build Windows based applications:

Using API programming model

Using MFC programming model

Using FCL /Framework Class Library/ and Win Forms

Using WPF /Windows Presentation Foundation/


Computer programs classified

Computer programs classified

When you begin creating a new program, you must choose the type of application you will be developing

Based on your choice, the IDE provides

the classes,

the tools,

the features

required for the selected type of application

3


Types of visual basic 2010 applications gshally pp25

Types of Visual Basic 2010 Applications, GShally,pp25

VB operates 5 major types of apps:

Windows applications

Mobile applications

Web site applications

Office applications

Database applications

4


Types of visual basic 2010 apps

Types of Visual Basic 2010 Apps

Windows application

Program will run on a computer or other device that supports the Windows GUI

Mobile application

Designed to run on mobile devices as smartphones, Pocket PCs and computers running the Windows CE OS or Windows Phone OS

5


Types of visual basic 2010 apps1

Types of Visual Basic 2010 Apps

Web site application

Uses ASP.NET. Runs on a Web server. Produces HTML code that is downloaded to the client computer where the browser interprets HTML and displays the contents of a Web page

Office application

Includes writing VBasic code to automate and manipulate documents created using Microsoft Office 2003/2007/2010

Database application

Written using ADO.NET to reference, access, display, and update data stored in a database

6


Types of visual basic 2010 apps2

Types of Visual Basic 2010 Apps

Other types of applications include:

Console applications

Classes for class libraries

Certain controls to use in Windows applications

Web services

Device-specific applications

7


Types of c apps

Types of C++ Apps

Application types you can create with C++

Console applications

Windows applications

Web applications – run on a Web server when a particular URL is loaded, and send HTML to a waiting browser.

Services – applications that run in the background and respond to requests, but do not have any visual interface

Class libraries – collections of code that can be called by other code.

Other

9/24/2014

Assoc. Prof. Stoyan Bonev

8


Types of c apps1

Types of C# Apps

Applications Developed with C#,

Web applications

Windows (GUI) applications

Console applications

Class libraries and stand-alone components (.dlls)

Smart device applications

Services

9


Types of java apps

Types of Java Apps

Java programs may be applications and applets(servlets).

Applications are standalone programs, similar to .NET Console applications and/or Windows based GUI applications.

Applets are similar to applications, but they do not run as standalone programs. Instead, applets adhere to a set of conventions that lets them run within a Java-compatible browser (client-side). You can only run an applet from an HTML page.

Servlets – applets that run on a server.

C# Programming: From Problem Analysis to Program Design

10

10


Computer programs classified summary

Computer programs classifiedSummary

Apps with Visual Interface

Apps with No Visual Interface

11


Computer programs classified summary1

Computer programs classifiedSummary

Apps with Visual Interface

Console apps

Input/Output data displayed in MSDOS window

Windowed Dlg Box apps (modified console apps)

Using dialog boxes for I/O

Windows based apps

Using visual components: labels, text fields, buttons etc

Web site apps

12


Computer programs classified summary2

Computer programs classifiedSummary

Apps with No Visual Interface that run in the background and respond to requests

Class libraries

Collections of code that can be called by other code

Windows services

No UI, Runs independently of any other user app

Starts automatically when the computer starts

Web services

No UI, It is code for other apps to call

13


Cos220 concepts of pls aubg cos dept

.

From

Console apps

To

Windows GUI apps

14


Intro to graphical user interface gui components

INTRO to Graphical User Interface (GUI) Components

Drawbacks/disadvantages of

Console applications

Dialog boxes based windowed applications

Suppose, the user/developer wants the program to display all input data and output data in one pane or window or dialog box

Such a dialog box is known as GUI or only UI

Java Programming: From Problem Analysis to Program Design, 4e

15

15


Graphical user interface gui components

Graphical User Interface (GUI) Components

Advantages of using GUI:

View inputs and outputs simultaneously

One graphical window

Input values in any order

Change input values in window

Click on buttons to get output

Java Programming: From Problem Analysis to Program Design, 4e

16

16


Graphical user interface gui components1

Graphical User Interface (GUI) Components

Terminology:

Frame/Form

Title bar

System supported icons

Title

Content pane

Components – labels, text fields, buttons etc

Java Programming: From Problem Analysis to Program Design, 4e

17

17


Cos220 concepts of pls aubg cos dept

Win API

18


Introduction

Introduction

The Windows Operating System introduced changes in the structure, implementation and execution of the computer programs.

In line with the console applications, programs oriented towards Windows and Internet were developed.

Assoc. Prof. Stoyan Bonev

19

19


Windows based application structure and source code

Windows based Application – structure and source code:

  • A C++ program is composed to include:

    • definitions of global variables and

    • definitions of functions, one of which is the main function titled main().

  • The minimal console application does not include executable statements and is presented by sample source codes as on the next slide:

Assoc. Prof. Stoyan Bonev

20

20


Windows based application structure and source code1

Windows based Application – structure and source code:

Minimal console app:

int main(){ return0; }

More minimal console application:

void main() {return; }

Most minimal console application:

void main() { }

Assoc. Prof. Stoyan Bonev

21

21


Windows based application structure and source code2

Windows based Application – structure and source code:

  • The execution of a Windows program doesn't start in main--it starts in WinMain

  • Following the console apps analogy one may expect that

  • The minimal Windows Application is expected to be presented by one of the presented source codes:

    • int WinMain(){ return 0; }

    • void WinMain(){ return; }

    • void WinMain(){ }

Assoc. Prof. Stoyan Bonev

22

22


Minimal windows api application

Minimal Windows API application

The analogy with console applications dictates the same style

int WinMain( )

{

return 0;

}

But real story is quite different . .> next slide

Assoc. Prof. Stoyan Bonev

23


Minimal windows api application1

Minimal Windows API application

Includes two non-empty functions. look at next two slides:

int WinMain( . . . )

{

. . .

}

int WndProc( . . . )

{

. . .

}

Assoc. Prof. Stoyan Bonev

24


Minimal windows api application2

Minimal Windows API application

int WinMain( . . . )

{

WndClass wc;

RegisterClass(&wc);

CreateWindow(wc);

ShowWindow(wc);

UpdateWindow(wc);

while ( GetMessage( … ) != NULL )

{

TranslateMessage( );

DispatchMessage( );

}

}

Assoc. Prof. Stoyan Bonev

25


Minimal windows api application3

Minimal Windows API application

int WndProc(HWND hWnd, UINT message,...)

{

switch (message)

{

case WM_PAINT:/* stmts */

case WM_LBUTTONUP:. . .

case WM_RBUTTONDOWN:. . .

case WM_CLOSE:. . .

case WM_QUIT:. . .

};

}

Assoc. Prof. Stoyan Bonev

26


Windows based application structure and source code3

Windows based Application – structure and source code:

No, there is no analogy btw console app & Windows based app.

Windows Application totally differs.

It has different philosophy and is based on different principles like

Visual programming,

Component programming and

Event-driven programming

Assoc. Prof. Stoyan Bonev

27

27


Windows based application structure and source code4

Windows based Application – structure and source code:

Win app need an entity to locate its components (labels, text boxes, buttons etc)

Such an entity has to be visualized.

Win app needs a mechanism to respond to user actions, known as events.

To answer these requirements, Win app may not be empty, as the console app is.

Assoc. Prof. Stoyan Bonev

28

28


Windows based application structure and source code5

Windows based Application – structure and source code:

Win app need at least two program units:

One that creates a structure for the form/window and visualizes it

One that contains event handlers, i.e. User specified code to run as response to events/messages/ sent to the Win app by the user or by the OS.

Assoc. Prof. Stoyan Bonev

29

29


Windows based application structure and source code6

Windows based Application – structure and source code:

Assoc. Prof. Stoyan Bonev

30

30


Windows based application structure and source code7

Windows based Application – structure and source code:

As it was alredy discussed, Windows Application has a totally different composition.

It is structurally organized to include two components:

Source code component (.cpp file)

Resource component (.rc file)

Assoc. Prof. Stoyan Bonev

31

31


Source code component

Source code component

  • The .cpp file contains at least 2 functions:

    • WinMain()

      • To register, create, update, show app window

      • To use a loop to distribute events for processing at run time

    • WndProc()

      • To run code as response to fixed events at run time

Assoc. Prof. Stoyan Bonev

32

32


Resource component

Resource component

An additional feature of a Windows Application is the resource component structured as contents of a resource file.

Resource is any element of the user interface like icons, mouse pointers, menus etc.

Comprised in a separate resource file, compiled by a resource compiler and is bound to the executable file.

Assoc. Prof. Stoyan Bonev

33

33


Cos220 concepts of pls aubg cos dept

C++ source C++ compiler Object code Linker Executable file

Applic.cpp Applic.obj Applic.exe

Assoc. Prof. Stoyan Bonev

34


Cos220 concepts of pls aubg cos dept

C++ source C++ compiler Object code Linker Executable file

Applic.cpp Applic.obj

Applic.exe

Applic.rc Applic.res

ResourceRCcompiler ResourceRCcompiler

description in binary

Assoc. Prof. Stoyan Bonev

35


How to build standard unmanaged exe for console application

How to build standard (unmanaged) .exe for console application?

Processing stages:

Compiling

Linking

Assoc. Prof. Stoyan Bonev

36


Cos220 concepts of pls aubg cos dept

C++ source C++ compiler Object code Linker Executable file

Applic.cpp Applic.obj Applic.exe

Assoc. Prof. Stoyan Bonev

37


How to build exe for windows based application

How to build .exe for Windows based application?

Processing stages:

Compiling

Compiling resources

Linking

Binding resources

Assoc. Prof. Stoyan Bonev

38


Cos220 concepts of pls aubg cos dept

C++ source C++ compiler Object code Linker Executable file

Applic.cpp Applic.obj

Applic.exe

Applic.rc Applic.res

ResourceRCcompiler ResourceRCcompiler

description in binary

Assoc. Prof. Stoyan Bonev

39


Cos220 concepts of pls aubg cos dept

!

The presentation demonstrates the API programming model through two versions of an application:

Standard

Minimal

Assoc. Prof. Stoyan Bonev

40


Cos220 concepts of pls aubg cos dept

My understanding of a Standard application:

Standard – represents a window form with attributes and resources generated automatically by the IDE without any developer interference.

Assoc. Prof. Stoyan Bonev

41


Cos220 concepts of pls aubg cos dept

My understanding of a Minimal application:

Minimal – represents a window form free of resources, displayed as an empty window with a greeting message “Hello, AUBG!”.

Assoc. Prof. Stoyan Bonev

42


The difference btw debug and release version

The difference btw debug and release version

Assoc. Prof. Stoyan Bonev

43


Comparative efforts analysis

Comparative Efforts Analysis

API Model:

Advantages

Minimal program size;

No need of extra libraries, except Windows dll’s.

Disadvantages

Huge number of API base functions.

Assoc. Prof. Stoyan Bonev

44


Comparative efforts analysis1

Comparative Efforts Analysis

MFC and .NET Model:

Advantages

No need to know the set of API base functions;

User friendly techniques for developing applications.

Disadvantages

Greater size of the executable file;

Need for additional class libraries (dll or static).

Assoc. Prof. Stoyan Bonev

45


Applications based on a p i programming model

Applications based onA P Iprogramming model

Assoc. Prof. Stoyan Bonev

46


Building windows application using windows api program model

Building Windows Application using Windows API program model

Select:

Project typeVisualC++ >> Win32

Project templateWin32 Project:

Assoc. Prof. Stoyan Bonev

47


Building windows application using windows api program model1

Building Windows Application using Windows API program model

Select:

Standard application settings

Build:

Debug application version

Release application version

How?

Build > Configur Manager > select Dbg/Rlse

Compare:

The .exe file sizes

Assoc. Prof. Stoyan Bonev

48


Building windows application using windows api program model2

Building Windows Application using Windows API program model

The standard API application window view:

Assoc. Prof. Stoyan Bonev

49


Building windows application using windows api program model3

Building Windows Application using Windows API program model

The minimal API application window view:

Assoc. Prof. Stoyan Bonev

50


Cos220 concepts of pls aubg cos dept

MFC

51


Examples using different techniques

Examples using different techniques:

  • Example of a Windows Application using Windows MFC programming model.

    • standard (Dynamic)minimal (Dynamic)

    • standard (Static)minimal (Static)

Assoc. Prof. Stoyan Bonev

52

52


The difference btw statically linked and dynamically linked application

The difference btw statically linked and dynamically linked application

Assoc. Prof. Stoyan Bonev

53


Applications based on m f c programming model

Applications based onM F Cprogramming model

Assoc. Prof. Stoyan Bonev

54


Building windows application using windows mfc program model

Building Windows Application using Windows MFC program model

Select:

Project typeVisualC++ >> MFC

Project templateMFC Application:

Assoc. Prof. Stoyan Bonev

55


Building windows application using windows mfc program model1

Building Windows Application using Windows MFC program model

Select:

Standard application settings:

SDI as alternate to MDI or DIALOG based

MFC with Shared DLL

MFC with Static Lib

Build:

Debug application version

Release application version

Compare:

The .exe file sizes

Assoc. Prof. Stoyan Bonev

56


Building windows application using windows mfc program model2

Building Windows Application using Windows MFC program model

The standard MFC application window view:

Assoc. Prof. Stoyan Bonev

57


Building windows application using windows mfc program model3

Building Windows Application using Windows MFC program model

The minimal MFC application window view:

Assoc. Prof. Stoyan Bonev

58


Cos220 concepts of pls aubg cos dept

OOP DOTNET FCL

.NET & FCL

9/24/2014

assoc. prof. Stoyan Bonev

59


C visual c and managed c

C++,Visual C++andManaged C++


C visual c and managed c1

C++, Visual C++ and Managed C++

The Managed Extensions to C++

Developers are offered a series of extension keywords, also known as Managed Extensions to C++, to generate code that targets the .NET Framework, also called managed code.

__gc

__value

__property

9/24/2014

Assoc. Prof. Stoyan Bonev

61


Applications that run directly under windows

Applications that run directly under Windows

When you develop an application using Visual C++ .NET it will be either

managed application or

unmanaged application.

In either case, it will be built to run on Windows machine.

An unmanaged application runs directly under Windows.

A managed application runs in the .NET runtime.

9/24/2014

Assoc. Prof. Stoyan Bonev

62


Managed and unmanaged code

Managed and Unmanaged Code

A compiler that emits unmanaged code or native code compiles source code to machine code which then just runs under Windows.

A compiler that emits managed code does not compile source code to machine code but rather to Intermediate Language (IL). Managed code runs in the Common Language Runtime (CLR), not directly under Windows.

Compilers Visual C++ 2002 and later emit both unmanaged code and managed code

9/24/2014

Assoc. Prof. Stoyan Bonev

63


Managed and unmanaged code1

Managed and Unmanaged Code

Using :

Visual C++ .NET 2010/2012

You have a choice of whether you build a managed or unmanaged application.

Visual C++ .NET is the only language provided with Visual Studio .NET that can emit either managed code or unmanaged code.

9/24/2014

Assoc. Prof. Stoyan Bonev

64


Managed and unmanaged code2

Managed and Unmanaged Code

When you build a managed application, your code is compiled to IL in a file called an assembly, along with metadata that describes the classes, methods and attributes of the code you’ve created. This assembly is the unit of deployment in the .NET world. You copy it to another server to deploy the assembly there – and often that copying is the only step required in the deployment.

9/24/2014

Assoc. Prof. Stoyan Bonev

65


Managed and unmanaged code3

Managed and Unmanaged Code

Managed code runs in the CLR. The runtime offers a variety of services to your running code:

It first loads and verifies the assembly to make sure the IL is OK.

Then, just in time, as methods are called, the runtime arranges for them to be compiled to machine code for the machine the assembly is running on, and caches this machine code to be used the next time the method is called. (This is known as Just In Time or JIT compiling, or just jitting).

As the assembly runs, the runtime continues to provide services such as security, memory management, threading, etc

The application is managed by the runtime.

9/24/2014

Assoc. Prof. Stoyan Bonev

66


Application in unmanaged c

Application in unmanaged C++

// UnmanagedCPPApplication.cpp

#include <iostream>

using namespace std;

class ArithmeticClass// Remark: class with no data members

{

public:double Add( double n1, double n2)

{

return n1 + n2;

}

};

void main()

{

ArithmeticClass arith;cout << endl << arith.Add(1.1, 2.2);

double answer;

answer = arith.Add(4.4, 5.5);cout << endl << answer;

}

9/24/2014

Assoc. Prof. Stoyan Bonev

67


Application in managed c

Application in managed C++

#include "stdafx.h“// ManagedCPPApplication.cpp : main project file

using namespace System;

class ArithmeticClass

{

public:double Add( double n1, double n2)

{

return n1 + n2;

}

};

void main( )

{

ArithmeticClass arith;Console::WriteLine( arith.Add(1.1, 2.2) );

double answer;

answer = arith.Add(4.4, 5.5);Console::WriteLine(answer);

}

9/24/2014

Assoc. Prof. Stoyan Bonev

68


Managed and unmanaged data

Managed and Unmanaged Data

When you write unmanaged application, you have only unmanaged data.

When you write managed application in VB or C#, you have only managed data.

When you write a managed C++ application, you control whether your data is managed or unmanaged.

9/24/2014

Assoc. Prof. Stoyan Bonev

69


Unmanaged data

Unmanaged Data

This term is a way to describe how data has always been handled in C++.

Given a class

You create an instance of the class on the stack

You create an instance of the class on the heap and use it through a pointer

See next slide

9/24/2014

Assoc. Prof. Stoyan Bonev

70


Unmanaged data1

Unmanaged Data

class ArithmeticClass{

public:double Add( double num1, double num2)

{return num1 + num2;}

};

void main()

{

ArithmeticClass arith;cout << endl << arith.Add(1.1, 2.2);

ArithmeticClass *pArith = new ArithmeticClass();

cout << endl << pArith->Add(2., 2.);

}

9/24/2014

Assoc. Prof. Stoyan Bonev

71


Unmanaged data2

Unmanaged Data

No problems with the stack variable arith.

The heap variable must be explicitly cleared away:

delete pArith;

So, memory management is your job in classic C++.

What you create with new, you must clean up with delete.

If you forget, you can suffer a memory leak.

9/24/2014

Assoc. Prof. Stoyan Bonev

72


Garbage collected classes

Garbage-Collected Classes

If you create a GCC ( __gc … ), the runtime will manage the memory for you.

In exchange:

you give up capability to create an instance on the stack

You have to follow some rules when designing your class

Inheritance Restrictions

Single Inheritance

You cannot override operator & or operator new

You cannot implement a copy constructor.

9/24/2014

Assoc. Prof. Stoyan Bonev

73


Garbage collected classes1

Garbage-Collected Classes

// you set garbage collection class-by-class, not object-by-object

__gc class Sample

{

private: double number;

public:

Sample (double num): number(num) {}

};

void main( )

{

Sample a(5.0); // Error

Sample* pa = new Sample(6.0); // OK,no need of delete operator

}

9/24/2014

Assoc. Prof. Stoyan Bonev

74


Value classes

Value Classes

Programmers feel uncomfortable when they are told they cannot create instances of GCC /managed data/ on the stack.

The fundamental types, such as int, float, are referred as value types, because they are allocated on the stack.

You can define a class of yours to be a value class ( __value …)

9/24/2014

Assoc. Prof. Stoyan Bonev

75


Value classes1

Value Classes

__value class Sample

{

private: double number;

public:

Sample (double num): number(num){}

};

void main( )

{

Sample a(5.0);// OK

Sample* pa = __nogc new Sample(6); // OK

}

9/24/2014

Assoc. Prof. Stoyan Bonev

76


Value classes2

Value Classes

These value classes are still managed, but are not garbage-collected.

9/24/2014

Assoc. Prof. Stoyan Bonev

77


Boxing

Boxing

When you use/mix managed and unmanaged data, you need to use the following .NET concept :

Boxing

9/24/2014

Assoc. Prof. Stoyan Bonev

78


Boxing a fundamental type

Boxing a Fundamental Type

If you try to pass a piece of unmanaged data to a method that is expecting managed data, the compiler will reject your attempt.

The way to get a pointer to garbage-collected data (i.e managed data) is to use the __box extension.

This is referred as boxing. See next slide.

9/24/2014

Assoc. Prof. Stoyan Bonev

79


Boxing a fundamental type1

Boxing a Fundamental Type

int i=3;

System::Console::Write(“ i is =“);

System::Console::WriteLine(i);

System::Console::WriteLine( __box(i) );

9/24/2014

Assoc. Prof. Stoyan Bonev

80


Properties

Properties

Managed classes have properties.

class Employee

{

private: int salary;

. . . // remaining member variables

public: int getSalary() { return salary; }

void setSalary(int s) {salary=s;}

. . . // remaining public methods

};

9/24/2014

Assoc. Prof. Stoyan Bonev

81


Properties1

Properties

Basic concept: class Employee has data member salary

It’s a private variable

With public get and set functions

Many classes follow this “get and set” paradigm.

Benefit is encapsulation.

Downside is the way your code looks when you’re using get and set functions.

9/24/2014

Assoc. Prof. Stoyan Bonev

82


Properties2

Properties

Managed classes have properties.

If you have a pointer to an instance of class Employee, say pe and you want to give that Employee’s $5000.00 raise, here is the code

Employee *pe = new Employee;

pe->setSalary(40000);

pe->setSalary(pe->getSalary() + 5000);

9/24/2014

Assoc. Prof. Stoyan Bonev

83


Properties3

Properties

In order to simplify the last line code

__gc class Employee

{

private: int salary;

public:

__property int get_Salary() { return salary; }

__property void set_Salary(int s) {salary=s;}

};

9/24/2014

Assoc. Prof. Stoyan Bonev

84


Properties4

Properties

Now the Employee class has a Salary property. It is directly tied to salary member variable.

The property name is what appears to follow get_ and set_ of the function names.

To use the property, you write code that treats the Salary property as a public member variable:

pe->Salary = 40000;

pe->Salary = pe->Salary + 5000;

or

pe->Salary += 5000;

9/24/2014

Assoc. Prof. Stoyan Bonev

85


Digression on properties in vbasic read or skip 8 coming slides

Digression on Properties in VBasic(read or skip 8 coming slides)


Cos220 concepts of pls aubg cos dept

Class Counter

Private m_count As Integer

. . .

Public Sub New()

m_count = 0

End Sub

Public Sub New(ByVal val As Integer)

m_count = val

End Sub

. . .

End Class

9/24/2014

Assoc. Prof. Stoyan Bonev

87


Cos220 concepts of pls aubg cos dept

Dim b, c As Counter

b = New Counter

b.ShowData()

c = New Counter(20)

c.ShowData()

9/24/2014

Assoc. Prof. Stoyan Bonev

88


Cos220 concepts of pls aubg cos dept

Class Distance

Private m_feet As Integer, m_inches As Single

. . .

Public Sub New()

m_feet = 0 : m_inches = 0.0

End Sub

Public Sub New(ByVal valft As Integer, ByVal valin As Single)

m_feet = valft

m_inches = valin

End Sub

. . .

End Class

9/24/2014

Assoc. Prof. Stoyan Bonev

89


Cos220 concepts of pls aubg cos dept

Dim aa, bb, cc As Distance

aa = New Distance(3, 3.0)

bb = New Distance(6, 6.0)

cc = New Distance

aa.ShowData() : bb.ShowData() : cc.ShowData()

9/24/2014

Assoc. Prof. Stoyan Bonev

90


Cos220 concepts of pls aubg cos dept

Example class Counter with property block

Class Counter

Private m_count As Integer

. . .

Public Property Count() As Integer

Get

Return m_count' read value of property

End Get

Set(ByVal Value As Integer)

m_count = Value' write value of property

End Set

End Property

. . .

End Class

9/24/2014

Assoc. Prof. Stoyan Bonev

91


Cos220 concepts of pls aubg cos dept

Example class Counter with property block

Dim d As New Counter

d.Count = 880

Console.WriteLine _

("Counter data displayed through property = {0}",d.Count)

Dim var As Integer

var = d.Count

Console.WriteLine _

("Counter data displayed through assignment = {0}", var)

9/24/2014

Assoc. Prof. Stoyan Bonev

92


Cos220 concepts of pls aubg cos dept

Example class Distance with property block

Class Distance

Private m_feet As Integer, m_inches As Single

. . .

Public Property Feet() As Integer

Get

Return m_feet' read value of property

End Get

Set(ByVal Value As Integer)

m_feet = Value' write value of property

End Set

End Property

Public Property Inches() As Single

Get

Return m_inches' read value of property

End Get

Set(ByVal Value As Single)

m_inches = Value' write value of property

End Set

End Property

. . .

End Class

9/24/2014

Assoc. Prof. Stoyan Bonev

93


Cos220 concepts of pls aubg cos dept

Example class Distance with property block

Dim aaAs Distance

aa = New Distance

aa.Feet = 5

aa.Inches = 5.0

Console.WriteLine _

("Distance displayed through property Feet={0} Inches={1}", aa.Feet,aa.Inches)

Dim varft As Integer, varin As Single

varft = aa.Feet

varin = aa.Inches

Console.WriteLine _

("Distance displayed through assignment: {0} feet, {1} inches", varft, varin)

9/24/2014

Assoc. Prof. Stoyan Bonev

94


Application types you can create with visual c

Application types you can create with Visual C++

Console applications

Windows applications

Web applications – run on a Web server when a particular URL is loaded, and send HTML to a waiting browser.

Services – are applications that run in the background and respond to requests, but do not have any visual interface

Class libraries – are collections of code that can be called by other code.

Other

9/24/2014

Assoc. Prof. Stoyan Bonev

95


Creating unmanaged c application

Creating unmanaged C++ Application

Open Visual Studio .NET IDE

On the main menu choose File , New , Project

Select Visual C++ projects, Win32

9/24/2014

Assoc. Prof. Stoyan Bonev

96


Creating managed c application

Creating managed C++ Application

Open Visual Studio .NET IDE

On the main menu choose File , New , Project

Select Visual C++ projects, CLR

9/24/2014

Assoc. Prof. Stoyan Bonev

97


The net base class libraries

The .NET Base Class Libraries


The net base class libraries1

The .NET Base Class Libraries

Libraries Shared Across Languages

When you write managed C++, you have access to all of the managed code libraries that come with the .NET Framework:

The Base Class Libraries

ASP.NET

ADO.NET

These libraries are modern and powerful. They provide services, as XML processing, that weren’t even thought of when libraries such as MFC and ATL were first written.

9/24/2014

Assoc. Prof. Stoyan Bonev

99


Digression on namespaces read or skip 8 coming slides

Digression on Namespaces(read or skip 8 coming slides)


Namespaces in c

Namespaces in C++

Namespaces are a C++ feature designed to eliminate name conflicts, such as having two classes, each in different libraries, called the same name, e.g. String.

Before namespaces, library developers made their names unique by adding letters to them: GCString, CString, TKString. This approach reduces, but doesn’t prevent name conflicts.

With namespaces, classes can have simple names.

Name conflicts are much less likely, because in addition to a short or local name, classes have a fully qualified name that includes their namespace.

9/24/2014

Assoc. Prof. Stoyan Bonev

101


Namespaces in c1

Namespaces in C++

namespace One

{

class Common { . . . };

void Do() { … }

}

namespace Two

{

class Common { . . . };

void Do() { … }

}

9/24/2014

Assoc. Prof. Stoyan Bonev

102


Namespaces in c2

Namespaces in C++

void main()

{

Common c(3);// ambiguous

One::Common c1(3);// OK

Two::Common c2(3);// OK

Do();// ambiguous

One::Do();// OK

Two::Do();// OK

}

9/24/2014

Assoc. Prof. Stoyan Bonev

103


Namespaces in c3

Namespaces in C++

using namespace One;

void main()

{

Common c1(3);// OK

Two::Common c2(3);// OK

Do(); // OK

Two::Do(); // OK

}

9/24/2014

Assoc. Prof. Stoyan Bonev

104


Namespaces in c4

Namespaces in C++

using namespace Two;

void main()

{

One::Common c1(3);// OK

Common c2(3);// OK

One::Do(); // OK

Do(); // OK

}

9/24/2014

Assoc. Prof. Stoyan Bonev

105


Namespaces in c5

Namespaces in C++

Modern class libraries are each in their own namespace.

For example, the templates in the Standard Template Library STL are in the namespace std.

using namespace std;

9/24/2014

Assoc. Prof. Stoyan Bonev

106


Namespaces in c6

Namespaces in C++

To use a class in a namespace, you have two choices:

Call the class by its full name

x = System::Math::PI / 4;

Add a using statement at the top of the file and then call the class by its name within the namespace:

using namespace System;

. . .

x = Math::PI / 4;

9/24/2014

Assoc. Prof. Stoyan Bonev

107


The net base class libraries2

The .NET Base Class Libraries

The System Namespace

All the data types are represented.

Two classes deserve special mention

System::Console Class

System::String Class

Other components

System::DateTimestructure

Other useful namespaces

System::IOnamespace

System::Textnamespace

System::Collections namespace

System::Threading namespace

9/24/2014

Assoc. Prof. Stoyan Bonev

108


Building simple user interfaces with windows forms

Building Simple User Interfaces with Windows Forms


Building simple user interfaces with windows forms1

Building Simple User Interfaces with Windows Forms

A Managed C++ Windows Forms App

9/24/2014

Assoc. Prof. Stoyan Bonev

110


Building simple user interfaces with windows forms2

Building Simple User Interfaces with Windows Forms

The project wizard creates a blank form for you, and later you’ll drag controls onto it.

It also generates a file full of code, which will be edited as you add controls and set properties.

To see the code, right-click the form in the designer and choose View Code.

9/24/2014

Assoc. Prof. Stoyan Bonev

111


Building simple user interfaces with windows forms3

Building Simple User Interfaces with Windows Forms

9/24/2014

Assoc. Prof. Stoyan Bonev

112


Building simple user interfaces with windows forms4

Building Simple User Interfaces with Windows Forms

9/24/2014

Assoc. Prof. Stoyan Bonev

113


Cos220 concepts of pls aubg cos dept

namespace SimpleForm2 {

using namespace System;

using namespace System::ComponentModel;

using namespace System::Collections;

using namespace System::Windows::Forms;

using namespace System::Data;

using namespace System::Drawing;

public ref class Form1 : public System::Windows::Forms::Form

{

public:

Form1(void)

{

InitializeComponent();

//

//TODO: Add the constructor code here

//

}

protected:

~Form1()

{

if (components)

{

delete components;

}

}

private:

/// <summary>

/// Required designer variable.

/// </summary>

System::ComponentModel::Container ^components;

#pragma region Windows Form Designer generated code

/// <summary>

/// Required method for Designer support - do not modify

/// the contents of this method with the code editor.

/// </summary>

void InitializeComponent(void)

{

this->components = gcnew System::ComponentModel::Container();

this->Size = System::Drawing::Size(300,300);

this->Text = L"Form1";

this->Padding = System::Windows::Forms::Padding(0);

this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;

}

#pragma endregion

};

}

9/24/2014

Assoc. Prof. Stoyan Bonev

114


Using the toolbox to build the user interface

Using the Toolbox to build the user interface

The Toolbox is a tabbed window that appears on the editing screen.

When you are working with the designer on Windows Forms, you can drag typical Windows controls onto your form

9/24/2014

Assoc. Prof. Stoyan Bonev

115


Using the toolbox to build the user interface1

Using the Toolbox to build the user interface

9/24/2014

Assoc. Prof. Stoyan Bonev

116


Using the toolbox to build the user interface2

Using the Toolbox to build the user interface

Popular controls:

Label

Text box

Button

Check box

Radio buttons

Group box

Picture box

DateTime picker

9/24/2014

Assoc. Prof. Stoyan Bonev

117


Using the toolbox to build the user interface3

Using the Toolbox to build the user interface

The form and the controls are designed and implemented as classes with properties.

The properties pane may be displayed in a way similar to toolbox pane.

Right click on the control and select Properties.

9/24/2014

Assoc. Prof. Stoyan Bonev

118


Using the toolbox to build the user interface4

Using the Toolbox to build the user interface

9/24/2014

Assoc. Prof. Stoyan Bonev

119


Using the toolbox to build the user interface5

Using the Toolbox to build the user interface

9/24/2014

Assoc. Prof. Stoyan Bonev

120


Demo application

Demo Application

Form and two controls:

Picture Box

DateTime picker

9/24/2014

Assoc. Prof. Stoyan Bonev

121


Demo application1

Demo Application

9/24/2014

Assoc. Prof. Stoyan Bonev

122


Demo application2

Demo Application

9/24/2014

Assoc. Prof. Stoyan Bonev

123


Demo application3

Demo Application

9/24/2014

Assoc. Prof. Stoyan Bonev

124


Writing event handlers

Writing Event Handlers

There are two ways to add a handler to an event

The simplest is to double-click the control in the designer. This adds a handler to the default event, which varies from control to control.

To add a handler for another event, use the Properties window: at the top a toolbar with 5 tabs: the 4th is Events. When this tab is pressed, it displays all the events that can occur for this particular control.

9/24/2014

Assoc. Prof. Stoyan Bonev

125


Cos220 concepts of pls aubg cos dept

WPF

126


What is wpf

What is WPF?

Windows Presentation Foundation (WPF) is a next-generation presentation system for building Windows client applications with visually stunning user experiences. –Official Microsoft Definition

Based on:

  • .NET platform

  • Extensible Application Markup Language (XAML)


Advantages of wpf

Advantages of WPF

Easy to create stunning design

Technology for developing future windows applications

Reuse of existing code

Advanced Data-Binding

Supported by Microsoft


Disadvantages of wpf

Disadvantages of WPF

Requires .NET Framework 3.0 or higher

Comparatively slower than Windows Forms

Requires DirectX9 compatible video card for graphics


Microsoft visual studio net framework 3 0 or higher and wpf technology for building applications

Microsoft Visual Studio &.NET Framework 3.0 or higherandWPF technology for building applications


Building wpf applications

Building WPF applications

WPF approach may apply for C# and VBasic.

UI is described using XAML /Extensible Application Markup Language/.

Resource definition language and .rc file(s) as well as resource compiler replaced with XAML.


Creating wpf graphical applications

Creating WPF graphical applications

You design the form-based UI of a Windows-based app interactively

IDE generates code to implement UI that you designed

IDE provides two views of a graphical app:

The design view

The code view

Code and Text Editor window used to modify code and logic for a graphical app

Design View window used to layout UI

Easy to switch between the two views whenever user wants


Cos220 concepts of pls aubg cos dept

Note

  • As with WinForms, drag and drop controls from the Toolbox onto the window


Building c wpf applications

Building C# WPF applications

.


Creating wpf graphical applications1

Creating WPF graphical applications

VS displays an empty WPF form in the Design View window, together with another window containing the XAML description of the form, as shown next slide

XAML is used by WPF applications to define the layout of a form and its contents.


Building c wpf applications1

Building C# WPF applications

.

Assoc. Prof. Stoyan Bonev


Building c wpf applications2

Building C# WPF applications

.

Assoc. Prof. Stoyan Bonev


Building c wpf applications3

Building C# WPF applications

.

Assoc. Prof. Stoyan Bonev


Building c wpf applications4

Building C# WPF applications

.

Assoc. Prof. Stoyan Bonev


Cos220 concepts of pls aubg cos dept

Demo

One more comprehensive example

140


Windows presentation foundation

Windows Presentation Foundation

Figure 10-19 WPF design


My first wpf application

My first WPF application

Write a program to display an elementary simple form containing 3 controls:

a label

a text box where you can enter your name and

a button that displays a personalized greeting in a message box

Try to Solve task using your skills from Win Forms technology

142


My first wpf application1

My first WPF application

Create your WPF project, named sbWPFHello.

Create the UI

Click the Toolbox tab

Select/click Label, click visible part of the form

Reposition and resize the label,

On the View menu, click Properties window, change Text property. Another way to modify Text property is through XAML pane <Label> tag, Content attribute

143


My first wpf application2

My first WPF application

Click the Toolbox tab

Select/click TextBox, click visible part of the form

Reposition and resize the textbox,

On the View menu, click Properties window, change Text property. Another way to modify Text property is through XAML pane <TextBox> tag, Content attribute

144


My first wpf application3

My first WPF application

Click the Toolbox tab

Select/click Button, click visible part of the form

Reposition and resize the button,

On the View menu, click Properties window, change Text property. Another way to modify Text property is through XAML pane <Button> tag, Content attribute

145


My first wpf application4

My first WPF application

Build Solution to verify the project builds successfully

Click Start without Debugging

Form gets displayed

You type your name

Nothing happens

You managed a C# application without writing any line of C# source code

146


My first wpf application5

My first WPF application

You managed a C# application without writing any line of C# source code

IDE generates a lot of code. Examine the .cs files attached to the project

You need to add the EvH code associated with the button control

147


My first wpf application6

My first WPF application

Before we include EvH code, examine what IDE generated as C# source code:

The generated code handles routine tasks that all graphical apps must perform such as

Starting up an application

Displaying the form etc.

148


My first wpf application7

My first WPF application

In Solution explorer click ‘+’ beside the file MainWindow.xaml

The MainWindow.xaml.cs file appears.

Open the ….cs file. ..

You see a lot of using namespace stmts

You see definition of a class MainWindow : Window

You see a constructor that calls method

InitializeComponent();

The purpose of code you see is that you can add your own methods to handle the logic for your application, such as what happens when the user clicks a button

149


My first wpf application8

My first WPF application

Now you may be wondering

Where is the Main() method

How the form gets displayed when the app runs

In Solution explorer you can see one more XAML file, App.xaml

150


My first wpf application9

My first WPF application

In Solution explorer click ‘+’ beside the file App.xaml

The App.xaml.cs file appears.

Open the App.xaml.cs file

You see a lot of using namespace stmts.

You see not a lot else (there is a lot of hidden code)

The Main() method is hidden as well. But its code is generated based on settings of the App.xaml file

Main() method will create and display the form by the StartupURI property.

151


My first wpf application10

My first WPF application

Now, it’s time to start writing C# source code, i.e. the EvH associated with the Button.

152


My first wpf application11

My first WPF application

Double click on the button control

Source code window opens

You have to fill the body of the EVH andler method

MessageBox.Show(“Hello, “+textBox1.Text);

Rebuild the solution

Click the button

The program works.

153


Thank you for your attention any questions

Thank You

For

Your attention!

Any questions?


  • Login