1.54k likes | 1.74k Views
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
E N D
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 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 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 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 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 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 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 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# 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 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 classifiedSummary Apps with Visual Interface Apps with No Visual Interface 11
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 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
. From Console apps To Windows GUI apps 14
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 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) 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
Win API 18
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: • 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 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 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 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 application Includes two non-empty functions. look at next two slides: int WinMain( . . . ) { . . . } int WndProc( . . . ) { . . . } Assoc. Prof. Stoyan Bonev 24
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 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 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 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 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 code: Assoc. Prof. Stoyan Bonev 30 30
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 • 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 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
C++ source C++ compiler Object code Linker Executable file Applic.cpp Applic.obj Applic.exe Assoc. Prof. Stoyan Bonev 34
C++ source C++ compiler Object code Linker Executable file Applic.cpp Applic.obj Applic.exe Applic.rc Applic.res Resource RCcompiler Resource RCcompiler description in binary Assoc. Prof. Stoyan Bonev 35
How to build standard (unmanaged) .exe for console application? Processing stages: Compiling Linking Assoc. Prof. Stoyan Bonev 36
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? Processing stages: Compiling Compiling resources Linking Binding resources Assoc. Prof. Stoyan Bonev 38
C++ source C++ compiler Object code Linker Executable file Applic.cpp Applic.obj Applic.exe Applic.rc Applic.res Resource RCcompiler Resource RCcompiler description in binary Assoc. Prof. Stoyan Bonev 39
! The presentation demonstrates the API programming model through two versions of an application: Standard Minimal Assoc. Prof. Stoyan Bonev 40
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
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 Assoc. Prof. Stoyan Bonev 43
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 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 onA P Iprogramming model Assoc. Prof. Stoyan Bonev 46
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 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 model The standard API application window view: Assoc. Prof. Stoyan Bonev 49
Building Windows Application using Windows API program model The minimal API application window view: Assoc. Prof. Stoyan Bonev 50