Page 1 :
VISUAL PROGRAMMING, , Introduction to Visual C++ Programming: Objects, and Classes, Visual C++ Programming: Objects-Classes-VC++Components – Resources-Event, Handling – Menus – Dialog Boxes – Importing VBX Controls – Files – MFC File, Handling – Document View Architecture – Serialization. Interfacing Other, Applications – Multiple Document Interface (MDI) – Splitter Windows – Exception, Handling – Debugging – Object Linking and Embedding (OLE) – Database Application, – DLL- ODBC., , Department of Computer Science, GFGC,, Malur
Page 2 :
Object-Oriented Programming, • Object-Oriented Programming popularly called OOPs is an, approach to program organization and development that attempts, to eliminate some of the pitfalls of conversational programming, methods ., • Object –oriented programming as a paradigm is playing an, increasingly significant role in analysis, design and implementation, of software systems, • Features of object-oriented programming, • Emphasis is on data rather than procedure, • Programs are divided into objects, • Functions that operate on data of an object are tied together in, the data structure, • Data is hidden and cannot b accessed by external functions, • New data and functions can be easily added whenever necessary, Department of Computer Science, GFGC,, Malur
Page 3 :
objects, • Objects oriented programming is a programming, technique in while the programmer views concepts as, variety of objects, • By using objects you can represent the tasks to be, performed their interactions and any given condition, that must be observed, • Normally a data structure forms the basis of an object, in c and c++ the struct type forms an elementary object, • Communication through objects is done through, messages, Department of Computer Science, GFGC,, Malur
Page 4 :
objects, • Using messages is similar to calling a function, in a procedure oriented program, • When an object receives ,methods within the, object respond it, • Methods which are also known as member, functions act similar to functions in procedure, oriented programming, , Department of Computer Science, GFGC,, Malur
Page 6 :
classes, • A class is collection of similar type of objects, • Object is an instance of a class, • Once a class is created any number of objects, belonging to this class can be created, • Microsoft Visual C++ compiler provides a 32-bit, foundation class library containing a new set of object, oriented programming tools, , Department of Computer Science, GFGC,, Malur
Page 7 :
classes, • Microsoft, Foundation, class, (MFC), library, encapsulates all the procedure oriented windows, functions and provides support for control, bars,property pages,OLE,Activex controls., • Database support is provided for a wide range of, database sources including DAO,ODBC, • The MFC library users with easy to use objects, , Department of Computer Science, GFGC,, Malur
Page 8 :
Classes can be noted as, • A class is a template that unites data and, operations, • A class is an abstraction of real world entities, with similar properties, • A class identifies a set of similar objects, • The class is an implementation of abstract, data type, , Department of Computer Science, GFGC,, Malur
Page 9 :
Advantages of MFC classes, • Elimination of function and variable name, collision., • Encapsulation of code and data within class, • Inheritance concepts, • Reduction of code size due to well designed, class libraries, , Department of Computer Science, GFGC,, Malur
Page 11 :
VC++ COMPONENTS, , Microsoft Visual C++ 6.0 and the Build Process., Visual Studio 6.0 is a suite of developer tools, that includes Visual C++ 6.0. ..., • The Resource Editors—Workspace, ResourceView. ..., • The C/C++ Compiler. ..., • The Source Code Editor. ..., • The Resource Compiler. ..., • The Linker. ..., • The Debugger. ..., • AppWizard., • ClassWizard, , Department of Computer Science, GFGC,, Malur
Page 12 :
The Resource Editors—Workspace ResourceView, When we click on the ResourceView tab in the Visual C++ Workspace window, we can, select a resource for editing., Each project usually has one text-format resource script (RC) file that describes the, project's menu, dialog, string, and accelerator resources. The RC file also has #include, statements to bring in resources from other subdirectories. These resources include, project-specific items, such as bitmap (BMP) and icon (ICO) files, and resources common, to all Visual C++ programs, such as error message strings., The C/C++ Compiler, The Visual C++ compiler can process both C source code and C++ source code. It, determines the language by looking at the source code's filename extension., The Source Code Editor:, Visual C++ 6.0 includes a sophisticated source code editor that supports many features, such as dynamic syntax coloring, auto-tabbing, keyboard bindings for a variety of popular, editors (such as VI and EMACS), and pretty printing., The Resource Compiler, The Visual C++ resource compiler reads an ASCII resource script (RC) file from the resource, editors and writes a binary RES file for the linker., Department of Computer Science, GFGC,, Malur
Page 13 :
The Linker, The linker reads the OBJ and RES files produced by the C/C++ compiler and the resource, compiler, and it accesses LIB files for MFC code, runtime library code, and Windows code. It then, writes the project's EXE file., The Debugger, If your program works the first time, you don't need the debugger. The rest of us might need, one from time to time., , Department of Computer Science, GFGC,, Malur
Page 14 :
AppWizard, AppWizard is a code generator that creates a working skeleton of a Windows application, with features, class names, and source code filenames that you specify through dialog, boxes., ClassWizard, ClassWizard is a program (implemented as a DLL) that's accessible from Visual C++'s View, menu., , The Source Browser, If you write an application from scratch, you probably have a good mental picture of your, source code files, classes, and member functions. The browser has the following viewing, modes:, •, •, •, •, , Definitions and References, Call Graph/Callers Graph, Derived Classes and Members/Base Classes and Members, File Outline, , Department of Computer Science, GFGC,, Malur
Page 15 :
Online Help, In Visual C++ 6.0, the help system has been moved to a separate application named the, MSDN Library Viewer., Windows Diagnostic Tools, Visual C++ 6.0 contains a number of useful diagnostic tools., Source Code Control, During development of Visual C++ 5.0, Microsoft bought the rights to an established source, code control product named SourceSafe., , The Gallery, The Visual C++ Components and Controls Gallery lets you share software components among, different projects. The Gallery manages three types of modules:, , ActiveX controls, C++ source modules, Visual C++ components., The Microsoft Foundation Class Library Version 6.0, , The Microsoft Active TemplateDepartment, Library of Computer Science, GFGC,, • ATL is a tool, separate from MFC, for building, ActiveX controls., Malur
Page 16 :
Event Handling, • An event is a signal that informs an application, that something important has occurred, • Example when user clicks on the form ,the form, can raise a click event, Message, Description, and call a procedure, that handles the event., WM_KEYDOWN, A key has been pressed, • WM_KEYUP, Following are Keyboard, events, A key has been released, , Department of Computer Science, GFGC,, Malur
Page 17 :
Mouse event messages, • Mouse events occur with mouse movements, in forms and Description, controls, Message, The left mouse button is pressed, • WM_LBUTTONDOWN, Following, are, mouse events, WM_LBUTTONUP, The left mouse button is released, WM_LBUTTONDBLCLK, , The right mouse button has been double clicked, , WM_RBUTTONDOWN, , The right mouse button has been pressed, , Department of Computer Science, GFGC,, Malur
Page 18 :
The Example shows usage of Mouse, Events, Step 1, •, •, •, •, , click Start on the TaskBar, select programs ,Microsoft Visual Studio 6.0, select ,Microsoft Visual C++ 6.0, select File-> NEW from menu. The new dialog box will appear, , Department of Computer Science, GFGC,, Malur
Page 19 :
Step2, • Launch your Visual C++, click the File menu, and click the New… sub menu. Click the, Projects tab for the AppWizard as shown, below. Select the MFC AppWizard (exe), type, your project name and set the project, location as needed. Leave other setting as, default and click the OK button., Department of Computer Science, GFGC,, Malur
Page 20 :
step3, Select ok to set up the project ,select Dialog based document application, from the MFC App Wizard and click Finish as shown in below, , Department of Computer Science, GFGC,, Malur
Page 21 :
Step4, open the class wizard select WM_MOUSEMOVE from the list of messages and add, a function by clicking the add Function button., click the ok button to accept the suggested function name, , Department of Computer Science, GFGC,, Malur
Page 24 :
MENUS, •A menu is a list of actions the user can perform on an, application., •Each item of the list is primarily a word or a group of, words on a line., •Different menu items are used for different reasons., •For example, some menu items simply display a word, or a group of words., • Some other items display a check mark. This indicates, that the item toggles the availability or disappearance, of an object., Department of Computer Science, GFGC,, Malur
Page 25 :
Menu Styles, There are three categories of menu, • The Pull-Down- It is also called a drop=down menu of, commands or options that appear when you select an, item with a mouse., • The Cascading Menus – A menu system that displays, submenus off to the side when selected. This submenu is, similar to pull-down menu, with a number of entries that, trigger application functions, • The Pop-up – It is also called context ,contextual ,shortcut, and pop-up menu ,it is GUI that appears upon userinteractions, Department of Computer Science, GFGC,, Malur
Page 26 :
Creating a Menu, • The Following steps are required to create a menu., • Step 1:open Microsoft Visual C++ 6.0 ., • select File-> New from menu .the New dialog box will, appear., • Step 2: From the project list select MFCAppWizard. Type in, name for the project in the textbox Project Name as shown, below, , Department of Computer Science, GFGC,, Malur
Page 27 :
Creating a Main Menu, • On the main menu, click Project -> Add Resource..., • On the Add Resource dialog box, double-click Menu, • In the Resource View, click IDR_MENU1 to select it and, change its identifier to IDR_MENU_RES, • In the main window, click the top box (in MSVC .Net, it, displays Type Here),, , Department of Computer Science, GFGC,, Malur
Page 28 :
Menu, •, •, •, •, , Type Family and press Enter, Click the item under Family., Type Father and press Enter, Type Mother and press Enter, , Department of Computer Science, GFGC,, Malur
Page 29 :
Menu, •To add a separator, click the item under mother, type - and, press Enter, •Complete the menu as follows (remember to add the lower, separator, , Department of Computer Science, GFGC,, Malur
Page 30 :
Menu, • To move the Grand-Child item and position it under, the lower separator, click and hold the mouse on, Grand-Child, then drag in the bottom direction until, the selection is in the desired position, , Department of Computer Science, GFGC,, Malur
Page 31 :
Menu, • Release the mouse., • To create another main menu item, click the box on the, right side of Family, type, • Category and press Enter, • Click the item under Category, type Parent and press Enter., • Type Child and press Enter, • To move the Category menu and position it to the left side, of Family, click and drag, • Category in the left direction, , Department of Computer Science, GFGC,, Malur
Page 32 :
Dialog Boxes, • A dialog box is a rectangular window whose, main role is to host or hold other Windows, • controls. For this reason, a dialog box is, referred to as a container. It is the primary, interface of user interaction with the, computer., • The controls it hosts accomplish the role of, dialog between the user and the machine., • Here is an example of a dialog box:, Department of Computer Science, GFGC,, Malur
Page 33 :
Characteristics of Dialog boxes, • A dialog box has the following characteristics:, • It is equipped with the system Close button ., • As the only system button, this button allows the user, to dismiss the dialog and ignore whatever the user, would have done on the dialog box., • It cannot be minimized, maximized, or restored. A, dialog box does not have any other system button but, Close., • It is usually modal, in which case the user is not, allowed to continue any other operation until the dialog, box is dismissed., Department of Computer Science, GFGC,, Malur
Page 34 :
Characteristics of Dialog boxes, • It provides a way for the user to close or dismiss the dialog., Most dialog boxes have the OK and the Cancel buttons,, although this depends on the application developer., • When the dialog has the OK and the Cancel buttons, the, OK button is configured to behave as if the user had, pressed Enter., • whatever the user had done would be acknowledged and, transferred to the hosting dialog box, window, or, application., • Pressing Esc applies the same behavior as if the user had, clicked Cancel., Department of Computer Science, GFGC,, Malur
Page 35 :
Steps to create dialog boxes, • 1. Start Microsoft Visual C++ or Microsoft, Visual Studio, • 2. Create a new Win32 Application or Win32, Project named ExoDialog1, , Department of Computer Science, GFGC,, Malur
Page 36 :
Steps to create dialog boxes, • 3. Make sure you create the Windows Application, in An Empty Project and click OK or Finish, • 4. If you are using MSVC 6, on the main menu,, click Project -> Settings…, • If you are using MSVC 7, in the Solution Explorer,, right-click ExoDialog1 and click Properties..., • 5. In the Property Pages, specify that you want to, Use MFC in a Shared DLL, Department of Computer Science, GFGC,, Malur
Page 37 :
Steps to create dialog boxes, , Department of Computer Science, GFGC,, Malur
Page 38 :
• 6. Click OK, • 7. To create the application class of the project, on the, main menu, click File -> New or Project -> Add New, Item..., • 8. In the Files property page or int the Templates, section, click C++ (Source) File. Set the File Name to, Exercise and click OK or Open., • 9. To create the application, change the file as follows:, • #include <afxwin.h>, • class CExerciseApp : public CWinApp, • {, • public:, • BOOL InitInstance();, Department of Computer Science, GFGC,, Malur
Page 41 :
Files – MFC File Handling, File is a collection of related records stored in secondary, device i.e. disk ,A record is composed of several fields in, group of characters., Win32, , MFC, , When using Win32 file I/O functions ,you When using MFC file I/O are performed in, create a file handle and manipulate the a more object –oriented manner using, file handle with functions such as Read CFILE and Archive classes., File and write file ., , Department of Computer Science, GFGC,, Malur
Page 43 :
MFC File Handling, • CFile is a general file class , the other classes are used for, more specialized types of files., • CStdio File wraps a standard C stream file handle like the, standard output handle with a CFile derived class., • CMemFile manages a file that is hosted in memory rather, than on disk., • CSharedFile allows for files to be shared in memory., • Colestream File provides CFile access to component object, Model (COM) compound files, • CSocketFile wraps a windows socket with a Cfile derived, class, Department of Computer Science, GFGC,, Malur
Page 44 :
Opening Files, • There are 2 ways to open a file using Cfile:, • The simplest method is to pass the name of the file to be, opened as a parameter to the constructor, • Alternatively you can create a Cfile instance using the, default constructor and explicitly open a file using the open, member function., , • Example Cfile file;, • BOOL bOpened =file.open(“C:\Myfile”,Cfile::modeRead);, , Department of Computer Science, GFGC,, Malur
Page 45 :
File Modes(Flags), , • The second parameter passed to the Cfile constructor is, used to hold one or more flags,That indicates how the file, will be opened., Modes, , Description, , modeRead, , Opens the file for reading only, , modeWrite, , Opens the file for writing only, , modeReadWrite, , Opens the file for reading and writing, , modeCreate, , Creates the file if it doesn’t already exists, , shareDenyNone, , Give other processes read and write access to the file, , shareDenyRead, , Prevents other process from reading the file, , shareDenyWrite, , Prevents, other process from writing to the file, Department of Computer Science, GFGC,, Malur
Page 47 :
Writing to a CFile object, • Write takes 2 parameter, • The address of a buffer to be written to the Cfile, instance, • The number of bytes to be written to the file, • Write has no return value, if an error occurs an, exception is raised, , Department of Computer Science, GFGC,, Malur
Page 59 :
Serialization, • Serialization is the ability to store data on a drive., • Therefore, to actually save a file,the CObject class, provides the Serialize() method to its children., • To store data of the file, its information is held by a, class called CArchive., • When saving a file, a CArchive object is passed to the, Serialize method as reference, which modifies its, value., , Department of Computer Science, GFGC,, Malur
Page 60 :
Serialization, • CArchive is used to either save the current document, or open an existing one. To take care of each, it uses, two methods (ReadObject() and WriteObject())., • These methods are actually implemented using the, extraction operators (>> and <<)., • Whenever you need to perform serialization in an, application, add a method called Serialize() to your, document class and pass it a CArchive object, reference., • The syntax of this method is: virtual void, Serialize(CArchive& ar); The implementation of this, method may depend on the document, Department of Computer Science, GFGC,, Malur
Page 61 :
Serialization, •A CFile object encapsulates the binary file handle that you get, through the Win32 function CreateFile., •This is not the buffered FILE pointer that you'd get with a call to, the C runtime fopen function; rather, it's a handle to a binary, file. The application framework uses this file handle for Win32, ReadFile, WriteFile, and SetFilePointer calls., , Serialization process, , Department of Computer Science, GFGC,, Malur
Page 62 :
Serialization, • If your application does no direct disk I/O but instead relies, on the serialization process, you can avoid direct use of, CFile objects., • The CArchive object buffers data for the CFile object, and it, maintains an internal flag that indicates whether the, archive is storing (writing to disk) or loading (reading from, disk). Only one active archive is associated with a file at, any one time., • The application framework takes care of constructing the, CFile and CArchive objects, opening the disk file for the, CFile object and associating the archive object with the file., • All you have to do (in your Serialize function) is load data, from or store data in the archive object. The application, framework calls the document's Serialize function during, the File Open and File Save processes., Department of Computer Science, GFGC,, Malur
Page 63 :
Multiple Document Interface (MDI, • An application is referred to as Multiple, Document Interface, or MDI, if the user can open, more than one document in the application, without closing it. to provide this functionality,, the application provides a parent frame that acts, as the main frame of the computer program., • Inside of this frame, the application allows, creating views that each uses its own frame,, making it distinct from the other., • Here is Microsoft Word 97 displaying as a classic, MDI application:, Department of Computer Science, GFGC,, Malur
Page 64 :
Multiple Document Interface (MDI), • SDI application allows the user to work on only one, document at a time, it also normally limits the user, to working on a specific type of document., • MDI applications not only enable the user to work on, multiple documents at the same time, but also MDI, applications can allow the user to work on multiple, types of documents., • An MDI application uses a window-in-a-window, style, where there is a frame window around one or, more child windows., Department of Computer Science, GFGC,, Malur
Page 65 :
Multiple Document Interface (MDI), • This is a common application style with many popular, software packages, including Word and Excel., • Architecturally, an MDI application is similar to an SDI, application. In fact, with a simple MDI application, the, only difference is the addition of a second frame class, to the other classes that the AppWizard creates, as, shown in Figure ., • The Document/View architecture is still very much the, approach you use for developing MDIapplications as, well as SDI applications, Department of Computer Science, GFGC,, Malur
Page 67 :
Multiple Document Interface (MDI, • When you create an MDI application, you will create, just one more class than you created with an SDI, application., The classes are, • The CWinAppderived class, • The CMDIFrameWndderived class, • The CMDIChildWndderived class, • The CDocumentderived class, • The CViewderived class, Department of Computer Science, GFGC,, Malur
Page 68 :
Multiple Document Interface (MDI, • Creating Multiple Document Interface Applications have, two, MDI, derived, classes,, CMDIFrameWnd(the, CMainFrameclass in your project) and CMDIChildWnd(the, CChildFrameclass in your project), are the only two classes, that are different from the SDI application that you created., • The first of these two classes, the CMDIFrameWndderived CMainFrame, is the main frame of the, application. It provides an enclosed space on the desktop, within which all application interaction takes place. This, frame window is the frame to which the menu and toolbars are attached., Department of Computer Science, GFGC,, Malur
Page 69 :
Multiple Document Interface (MDI, • The second of these two classes, the, CMDIChildWnd-derived CChildFrameclass, is, the frame that holds the CViewclass. It is the, frame that passes messages and events to the, view class for processing or display., , Department of Computer Science, GFGC,, Malur
Page 70 :
Building the Application Shell, • To create the application shell for today’s application,, follow these steps:, • 1. Create a new AppWizard project. Name the project ., • 2. On the first step of the AppWizard, select Multiple, Documents., • 3.Use the default values on the second step of the, AppWizard., • 4. On the third step of the AppWizard, uncheck the, support for ActiveX Controls, , Department of Computer Science, GFGC,, Malur
Page 71 :
Building the Application Shell, • 5. On the fourth step of the AppWizard, leave all the, default values. Click the Advanced button., • 6. In the Advanced Options dialog, enter a three-letter, file extension for the files that your application will, generate. Click the Close button to close the dialog and, then click Next to move to the next step of the, AppWizard., • 7. Use the default settings on the fifth step of the, AppWizard., • 8. On the sixth and final AppWizard step, leave the base, class as Cview and click Finish. The AppWizard generates, the application shell, Department of Computer Science, GFGC,, Malur
Page 72 :
Building the Application Shell, 1. Create a new AppWizard project. Name the project ., , Department of Computer Science, GFGC,, Malur
Page 73 :
Building the Application Shell, 2 On the first step of the AppWizard, select Multiple Documents, , Department of Computer Science, GFGC,, Malur
Page 74 :
Building the Application Shell, 3.Use the default values on the second step of the AppWizard., 4. On the third step of the AppWizard, uncheck the support for ActiveX Controls, 5. On the fourth step of the AppWizard, leave all the default values. Click the Advanced, button, , Department of Computer Science, GFGC,, Malur
Page 75 :
Building the Application Shell, 6. In the Advanced Options dialog, enter a three-letter file extension for the files, , that your application will generate (for example, dhcor dvp). Click the Close, button to close the dialog and then click Next to move to the next step of the, AppWizard., 7. Use the default settings on the fifth step of the AppWizard., , Department of Computer Science, GFGC,, Malur
Page 76 :
Building the Application Shell, 8. On the sixth and final AppWizard step, leave the base class as Cview and click, , Finish. The AppWizard generates the application shell, , Department of Computer Science, GFGC,, Malur