Tuesday, February 26, 2013

Database Management with Microsoft ODBC

Database Connectivity with Microsoft ODBC:
The open Database connectivity (ODBC) is an API that is widely used for database connectivity. It provides the standard interface to different sort of data source. These data source can be simple text or it may be full-fledged database server. It is also possible for defining interface for the compiled C program to any SQL database using ODBC.

ODBC Architecture:

ODBC architecture is useful in establishing the connection between the MFC program and various types of databases.
There is an ODBC32.DLL file, it act as driver manager. Its task is to load the required driver during program execution. ODBC32.DLL keeps track of various database specific DLL and allow the MFC program to access the data in various database. But the standard format can be accessed using Microsoft access Jet database engine or SQL server ODBC Driver.

Object Linking and Embedding (OLE)

Object Linking and Embedding (OLE):
OLE is technology developed by Microsoft that allows embedding and linking to documents and other objects. It links as well as embeds some elements from other application.
For ex: We can embed a spread sheet from excel in the word document. We can get picture from MS paint in the MS word.

OLE Drag and Drop:
OLE means transfer of data from source to destination hence for OLE drag and drop operations
 There are three things that are required –
1.     An Interface IDropSource.
2.     An Interface IDropTarget.
3.     Some library code that manage the drag and drop process.

·        Drag and Drop operation is similar to copy and paste operation.
·        The Drag and Drop is performed between two applications or between an application and the window.
·        When user start the drag, cursor change and turn into the “+” sign. If we are dropping some object on the target then the object gets copied on the target.
·        Source Side: There is a key function executed in drag and drop process that is DoDragDrop(). The task of this function is to create an object of class ColeDropSource. The DoDragDrop() function is a looping function which does not return anything for some time. It returns only when user performs the drop operation or user cancels the operation or when some period of time is completed. The DoDragDrop() function is called when user click the mouse inside the tracking rectangle.
·        Destination Side: At this side, the dragged object must be dropped on some target. There is a target class named ColeDropTarget which implements IDropTarget interface. This interface holds the IDropSource pointer which finally link to ColeDropSource object.

Monday, February 25, 2013

Component Object Model (COM)

Component Object Model (COM)
Microsoft has introduced this standard in 1993. Microsoft has developed this technology by which one object can talk to another object present at different location using its methods. This technology is known as COM.
The COM is software architecture that allows application to be build from binary standard. The operating system creates the object when they are required and Delete the object when they are not referred. It is responsibility of an OS to support the communication between two object located at different place across the network.
Features of COM:
                                i.            This standard is language independent.
                              ii.            It controls another exe on the same computer.
                            iii.            It provides the support for the new protocol such as OLE DB.
                           iv.            It allows dynamic loading and unloading of components.
                             v.            It is capable to communicate with operating systems.
                           vi.            It allows shared memory management between the components.
                         vii.            It can be provided on multiple platforms such as Windows XP, Windows NT, Windows 7, Windows 8, UNIX and MACINTOSH.
Basic Terminologies:
1.     Components (Control):
Components can be referred as objects. This is small code that provides specific service to rest of the system.
2.     VTable (Virtual function table):
COM defines the virtual function table in the memory. COM use VTable to call the function.

3.     Interface:
The interface is the collection of function through which application can interact with each other. The name of the interface begins with prefix “I”. All interfaces in COM are defined from “IUnknown” Interface. This interface has a pure virtual member function called “Query Interface”.
For Ex:
Struct IUnknown
Virtual Bool QueryInterface(int nIid,void ppvobj)=0;

Containment and Aggregation Vs Inheritance:
In containment, the component is used as a part of implementation of new component. That means in containment, the internal copy of contained object is created so that the internal object is never exposed to the client.

When an outer object aggregates an interface of an inner object, it does not re-implement the interface. It passes the inner object interface pointer directly to client.
Consider again that the interface IMul need to be accessed by the client then instead of containing object to call the contained object. The interface of contained object is directly executed. The inner IMul Interface can directly accessed by the client.

ActiveX Control

ActiveX Control
ActiveX is a set of technology from Microsoft that enables us to make the interactive user interface. ActiveX technology has a set of components or control that can be embedded into another application & webpage. These controls can be programmed for getting active responses.

ActiveX control is controlled using three things –
Classification of ActiveX controls:
1.     Properties:
Properties are the attributes of the control that can be modified by the container application.
2.     Methods:
Methods are the function that can be called by container application to make these function available to another application, one interface is used which is known as IDispatch.
3.     Events:
Events are the message that can be sent from the control to the container application.
i.                    Stock Events:
Trigger mouse & keyboard events handling.
ii.                  Custom Events:
Trigger specific function event handling.

ActiveX Control Vs Ordinary Windows Controls:
ActiveX Control
Ordinary Windows Control
It can be embedded in application.
It cannot be embedded in application.
The important features of ActiveX control are properties & methods.
Ordinary windows control can be controlled by the message handler.
ActiveX controls can be embedded into webpage.
It cannot be embedded into webpage.
ActiveX control can be written using MFC, C#, C++, AIL
It can written as simple in win32 application or written in C.
It supports COM & OLE technologies.
It do not support any of both neither COM nor OLE.
They normally created in the .OCX.
The ordinary window control gets created in the .exe file.
It is easy to build some complex application such as window media player, Internet explorer.
Ordinary windows control can be used for building simple user interface based application.

Creating ActiveX Controls:
ActiveX is set of technology from Microsoft. It is used to provide better GUI facilities.

Installing ActiveX Controls:
ActiveX controls can be used when it is register in windows registry. There is a windows utility “Regsvr32”, using which the control can be registered.

Steps for installing ActiveX Control –
(Consider an ActiveX control we have named “ActiveCDemo.OCX”)
                                i.            Go to command prompt (cmd), locate the directory in which the “.OCX” file of your ActiveX control is present.
                              ii.            Type the command “C:\ActiveXDemo\debug\regsvr32 ActiveXDemo.OCX”
                            iii.            We will get following message on hitting Enter key –


ActiveX Control Container Programming:
ActiveX control container programming is a way by which how we used preinstalled and stored ActiveX control.
For installing the calendar we will apply following steps:
1.     Start VC++ 6.0, select MFC AppWizard (.exe) option, Give the project name and click ok.
2.     Now select the dialog based radio button and click net button. Accept the default value and generate application code.
3.     Now install the calendar control on the control toolbox, select the project menu-> Add to project-> Components and control. Then click insert button to insert the control.
This control will be added into control toolbox. This calendar control provides many events or properties to handle mouse and keyboard events.
When we build the project using MFC AppWizard (.exe), it must be ensured that the support for ActiveX control option is checked. Then the AppWizard do the following things –
i.                    It insert following line in the InitInstance member function of the application class –
ii.                  It insert the following line in the “Stdafx.h”file

Dynamic Link Library (DLL)

Dynamic Link Library (DLL)
DLL do not get loaded in RAM along with main program all the time. Memory does not get occupied unnecessarily. But if a DLL file is called by some exe then only it is loaded. The DLL files have the extension .DLL, .OCX, .DRV. Any DLL file can be called by an executable (.EXE) file only when it is required.
Advantages of DLL:
                               I.            Reduce uses of memory.
                             II.            DLL can be supported by multiple languages.
                          III.            If you want to change into function then there is no need to change into client program.

How the Client Program Finds a DLL:
If user link explicitly with LoadLibrary, user can specify the DLL’s full pathname. If user doesn’t specify the pathname, or if user link implicitly, Windows follows this search sequence to locate his DLL:
                                i.            The directory containing the EXE file
                              ii.            The process’s current directory
                            iii.            The Windows system directory
                           iv.            The Windows directory
                             v.            The directories listed in the Path environment variable
Difference between implicit and explicit linkage:
    Implicit Linkage:
a.     In implicit linkage the LIB file is used in which the name of corresponding DLL name is stored.
b.     All the DLL file get loaded that are associated with particular LIB file.
    Explicit Linkage:
a.     In explicit linkage LoadLibrary() function is used in which the path of DLL file is explicitly mentioned.
b.     We are explicitly specifying the name of required DLL in the LoadLibrary() function.

MFC DLL s- extension Vs Regular:
1.     Extension DLL:
It supports a C++ interface so it can export whole classes and user can instantiate those classes and user can also inherit classes exported from extension DLL. These types of DLLs are dynamically linked to the code in the DLL version of the MFC library and the client program must be dynamically linked to MFC library. Extension DLLs are quite small in size therefore it loads quickly.

2.     Regular DLL:
It supports only C style function. C++ classes cannot be exported by regular DLLs but C++ classes can be used inside the regular DLLs. It is also supported by WIN32 programming environment. It can be linked statically or dynamically. It is not necessary for the client program to be dynamically linked to MFC library.

MDI and Splitter window

MDI (Multiple Document Interface) :-
It is possible to create documents that are associated with single view, Such as interface is called MDI.

The SDI can load only one document at time although it can have multiple views in the same window, using the splitter window.
The MDI has multiple child windows, each of which corresponds to individual document. We can have multiple views in multiple document interface using split window.
For Ex: MS Word

Splitter window & multiple views
The multiple documents can be associated with multiple views but the single document interface (SDI) is associated with only one document at a time. We can have multiple views in a single document interface using a special control called splitter window.
For Ex:

Types of splitter window:
1.     Static splitter window
It gets created when the window is firs created. The panes of the static window cannot be changed. The user cannot move the bar and cannot re-split or un-split the window.

2.     Dynamic splitter window
User allowed splitting window using the menu bar option view->split. In a dynamic splitter window scroll bars are shared among the view. All the dynamic view objects get destroyed when the frame is destroyed.

Document and View architecture

Document and View Architecture:
1.     Concept of document and view architecture:
The document and view architecture consists of three parts. The view, one or more document and frames.
i.                    View:
The base class for view is CView. The view is platform on which the user can view the stored data and he can edit that data.
ii.                  Document:
The base class document is CDocument. The document is like a buffer which simply stores all the user data or the file is saved on disk. This saved file is called document.
iii.                Frame:
The base class for frame is CFrameWnd. This frame is physical representation of windows. The frame provides the border to the window.
2.     Menu:
Menu bar is an important element of any GUI. It is basically a collection of various menu items. These items can be arranged on the pop-up menu. User can select any item by clicking the top level items first then by selecting the desired menu option. In Microsoft VC++ there is a menu resource using which the menu can be created.

Steps for creating Menu:
i.                    Create new project using MFC AppWizard
ii.                  Goto Resource view
iii.                Goto Menu option in the list
iv.               Now default Menu will be shown in main window. We can add new item by clicking on last blank box icon

3.     Keyboard Accelerators:
We have to make use of keyboard while using shortcut key. Sometime one character is underlined; it indicates that press that character along with the special key and that particular menu item will be selected. Such underlined characters are hotkeys.
Some application designer may use of keyboard accelerator. Keyboard accelerators are similar to the hot key for example in Microsoft word, the short key F7 is used for spell check-up.
Steps for creating Menu:
i.                    Create new project using MFC AppWizard
ii.                  Goto Resource view
iii.                Goto Accelerator option in the list
iv.               Now a list of all already constructed accelerators will be shown in main window. We can add new accelerator by right clicking on any already defined accelerator and selecting New Accelerator option.

4.     Tool Bar:
A tool bar consists of horizontal arrangement of graphical button, the graphical image for buttons are stored in a single bitmap that is attached to single resource file. When a button is clicked, it sends a command message.

Steps for creating toolbar:
i.                    Create new project using MFC AppWizard
ii.                  Goto Resource view
iii.                Goto Toolbar option in the list
iv.               Now a Toolbar will be shown in main window. We can add new item by clicking on last blank box icon
Tool tips & prompt string:
We can set the prompt string by writing some string in the prompt window of particular menu item properties. The prompt string can be displayed in the status bar window.
If we want to get tool tips displayed on each button on the toolbar then that tool tip can be set by adding the tip’s text to the end of menu prompt, preceded by a new line character (\n).

5.     Status Bar:
The status bar is another child window which is present at the bottom of the main window. This window neither accepts input nor generates any command, but used to display the help information.
The status bar is made up of two types of panes –
                                           I.            Message line panes:
On the message line pane the help information can be displayed.
                                         II.            Indicator panes:
The indicator panes show current status of key, such as caps lock, num lock, scroll lock is indicated.
In the mainFRM.CPP file the framework for status bar can be defined as follows:

Class Wizard for status message –

6.     Reusable frame window Base class:
Any mainframe of window is derived from the class CframeWnd. The reusable frame is kind of window frame that is derived from CframeWnd Class.
But it remember following characteristics of the frame window –
a.     Window size
b.     Window position
c.      Window status (Minimized| Maximized)
d.     Toolbar & Status bar  getting enable & disable

7.     Separating document from its view:
In the document view architecture the document object hold data and the view object display the data of the user and allow him to edit that data. In SDI application there are two Base classes CDocument & CView.
                                           I.            CView::GetDocument():
Every view object is associated with only one document.
The GetDocument() function allow moving the control from view to document. Sometimes on running the application, user enter the data in the edit box that means the data is updated in view mode and this data must be updated by the document object as well.
                                         II.            CDocument::OnNewDocument();
The document framework first construct the document object & when user click new menu item from the file then the OnNewDocument() function is called. We can set some initial data for viewing on this new document function.
                                      III.            CDocument::UpdateAllView():
The UpdateAllView() function must be called when the data in the document gets change and document must inform it to one or more view associated with it.
                                      IV.            CView::OnInitialUpdate():
When an application gets standard or when user click the new from file menu or when user clicks on the open from the file menu, the CView function is called at that time OnInitialUpdate () is called.
                                        V.            CView::OnUpdate():
The base class CView calls the OnInitialUpdate() function which in turn , calls OnUpdate() function. The purpose of this function is to update all the view if any change occur in the document data.

Powered by Blogger.