vc++ programs


Ex. No: 1                                       
Date: 20-01-09                    Keyboard events and mouse message


Aim:
            To perform keyboard events and mouse message using Visual C++ programming.

Algorithm:

Step 1: Select Start -->Programs –> Microsoft Visual Studio 6.0 and open “Microsoft visual C++ 6.0” application, to create a new project named “mouse events”.
Step 2: Include the necessary header files to compute the above operations.
Step 3: Declare the windows functions in the parameter and declare the variable globally.
Step 4: Under the main functions in the parameter and variable that process the Keyboard events and mouse events.
Step 5: Check whether the entire variable are registered, if registered then.
Step 6: Using Switch case change character and using mouse click and other mouse functions.
Step 7: After the event destroy the function.
Step 8: Compile and execute the program.
Step 9: close the application.





Program:
#include<windows.h>
#include<string.h>
#include<stdio.h>
#include<winuser.h>
LRESULT CALLBACK windowfunc(HWND,UINT,WPARAM,LPARAM);
char szwinName[]="my win";
char str[100]="MOUSE EVENTS";
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpszargs,int nWinMode)
{
            HWND hwnd;
            MSG msg;
            WNDCLASS wcl;
            wcl.hInstance=hInstance;
            wcl.lpszClassName=szwinName;
            wcl.lpfnWndProc=windowfunc;
            wcl.style=CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS;
            wcl.hCursor = LoadCursor(NULL,IDC_ARROW);
            wcl.hIcon=LoadIcon(NULL,IDI_APPLICATION);
            wcl.lpszMenuName=NULL;
            wcl.cbClsExtra=0;
            wcl.cbWndExtra=0;
            wcl.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
if(!RegisterClass(&wcl))
                        return 0;
            hwnd=CreateWindow(szwinName,"mouse events",  
           WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,
CW_USEDEFAULT,CW_USEDEFAULT,HWND_DESKTOP,
NULL,hInstance,NULL);
            ShowWindow(hwnd,nWinMode);
            UpdateWindow(hwnd);
            while(GetMessage(&msg,0,0,0))
            {
                        TranslateMessage(&msg);
                        DispatchMessage(&msg);
            }
            return (msg.wParam);
}
LRESULT CALLBACK windowfunc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam)
{
            HDC hdc;
            PAINTSTRUCT ps;
switch(message)
            {
case WM_CHAR:
                        hdc=GetDC(hwnd);
                        TextOut(hdc,1,1," ",2);
                        sprintf(str,"%c",(char)wParam);
                        TextOut(hdc,1,1,str,strlen(str));
                        ReleaseDC(hwnd,hdc);
                        break;
case WM_PAINT:
                        hdc=BeginPaint(hwnd,&ps);
                        TextOut(hdc,300,1,str,strlen(str));
                        EndPaint(hwnd,&ps);
                        break;
case WM_RBUTTONDOWN:
                        hdc=GetDC(hwnd);
                        strcpy(str,"Right Button is down");
                        TextOut(hdc,LOWORD(lParam),HIWORD(lParam),str,strlen(str));
                        ReleaseDC(hwnd,hdc);
                        break;
case WM_LBUTTONDOWN:
                        hdc=GetDC(hwnd);
                        strcpy(str,"Left Button is down");
                        TextOut(hdc,LOWORD(lParam),HIWORD(lParam),str,strlen(str));
                        ReleaseDC(hwnd,hdc);
                        break;
case WM_LBUTTONDBLCLK:
                        hdc=GetDC(hwnd);
                        strcpy(str,"DOUBLE CLICK Left Button is down");
                        TextOut(hdc,LOWORD(lParam),HIWORD(lParam),str,strlen(str));
                        ReleaseDC(hwnd,hdc);
                        break;
case WM_RBUTTONDBLCLK:
                        hdc=GetDC(hwnd);
                        strcpy(str,"DOUBLE CLICK RIGHT Button is down");
                        TextOut(hdc,LOWORD(lParam),HIWORD(lParam),str,strlen(str));
                        ReleaseDC(hwnd,hdc);
                        break;
case WM_DESTROY:
                        PostQuitMessage(0);
                        break;
default:
                        return DefWindowProc(hwnd,message,wParam,lParam);
}
return 0;
}










Output:




result:
            Thus the VC++ program to perform keyboard events and mouse messages has been complied and executed successfully.
Ex.No: 2                            
Date  : 10-02-09                             DIALOG BASED APPLICATION

Aim:
            To write a VC++ program to develop a calculator using Dialog based application.

ALGORITHM:
Step 1: Select Start -->Programs –> Microsoft Visual Studio 6.0 and open the Microsoft visual C++ 6.0 application.
Step 2:  Run the AppWizard to generate a project “DialogBasedAppl”.
Ø  Choose New from VC++ File menu and then click project tab in the resulting new dialog box, Select MFC AppWizard (exe).
Ø  Type the project name “DialogBasedAppl” and click the ok button.
Ø  Select the “Dialog Based” option in the AppWizard and click finish to develop project.
Step 3:  The Resource editor enabled, now design the dialog box using the controls as :
Step 4:  Use the dialog editor (i.e Rightclick on the control and select properties) to assign
 control IDs to the controls as
Control
ID
First operand edit control
IDC_FIRST
Second operand edit control
IDC_SECOND
Result edit control
IDC_RESULT
First Radio button (enable group property option)
IDC_OPERATION
Compute push button
IDC_COMPUTE

Step 5: Open the properties dialog box by right click any where inside the resource editor
             and choose properties option
Ø  Choose style tab enables the options “System Menu” and “Minimize box”.
Step 6: Use class wizard to add member variables for following controls by following
Steps repeatedly for each controls:
Ø  Select the control and right click and choose “class wizard” option
Ø  Choose Member variable option and select “Add variable button”, Enter the member variable name and the type.
Control ID
Member Variable
Type
IDC_FIRST
m_dFirst
Double
IDC_SECOND
m_dSecond
Double
IDC_RESULT
m_dResult
Double
IDC_OPERATION
m_nOperation
int

Step 7: Add the message handler OnCompute for the IDC_COMPUTE button:
Ø  Right click on compute button and choose class wizard
Ø  Choose “message maps” tab and double-click on BN_CLICKED command.
Ø  Accept the default OnCompute function and click ok.
Step 8: Double click on COMPUTE button and add the following coding for OnCompute() function.
void CDialogBasedApplDlg::OnCompute()
{
            UpdateData(TRUE);
            switch(m_nOperation)
            {
            //Addition
case 0:
                        m_dResult=m_dFirst+m_dSecond;
                        break;
            //Subtraction
            case 1:
                        m_dResult=m_dFirst-m_dSecond;
                        break;
            //Multiplication
            case 2:
                        m_dResult=m_dFirst*m_dSecond;
                        break;
            //Division
            case 3:
                        if(m_dSecond!=0.0)
                        {
                                    m_dResult=m_dFirst/m_dSecond;
                        }
                        else
                        {
                                    AfxMessageBox("Divide by Zero");
                                    m_dResult=0.0;
                        }
                        break;
            default:
                        TRACE("default;,m_nOperation=%d\n",m_nOperation);
            }
            UpdateData(FALSE);
}

Step 9:  Build and test the DialogBasedAppl.DSW application.
Step 10: Close the application.









OUTPUT:

Addition Operation






Division Operation







RESULT:
            The VC++ program for develop calculator using dialog based application has been successfully executed and verified.
Ex.No: 3                                        
Date  :  17-02-09                            MDI APPLICATION

Aim:
            To write a VC++ program to develop a MDI document by using MFC AppWizard(exe).

ALGORITHM:
Step 1: Select Start -->Programs –> Microsoft Visual Studio 6.0 and open “Microsoft visual C++ 6.0” application.
Step 2: Run the AppWizard to create MDI Application, Select MFC AppWizard (exe), enter the project name as “MDI” and press ok to create a project.
Step 3: Select “Multiple Documents” option and deselect the “Document view architecture” and click next.
Step 4:  Select “Database support” to none and click the next button.
Step 5:  Accept the default settings and select Finish button.
Step 6:  Now the App wizard will create a new MDI project and click ok.
Step 7: Now the MDI project will be created with its specific classes.
Step 8: in the workspace window select the file view tab.
Step 9:  in the Source files open the ChildView.cpp file.
Step 10:  Add the following codes for CChildView::OnPaint() function.
void CChildView::OnPaint()
{
              CPaintDC dc(this); // device context for painting
              dc.TextOut(0,0,"Sample of MDI");
             
dc.Rectangle(100,100,200,200);
}

Step 11: Compile and execute the application.
Step 12: Close the application.




















OUTPUT:










RESULT:
            The VC++ program for developing MDI application by using MFC AppWizard (exe), has been successfully executed and verified.
Ex.No:4                                         
Date: 25-02-09                                           THREAD

Aim:
            To create a VC++ project to implement the threads in our application.

ALGORITHM:
Step 1: Select Start -->Programs –> Microsoft Visual Studio 6.0 and open “Microsoft visual C++ 6.0” application.
Step 2: Run the MFC AppWizard (exe) application, type the project name as “Thread “and click ok.
Step 3: Select single document option, accept all default settings and click finish button.
Step 4: Choose Resource from Visual C++ Insert menu, and then choose Dialog and select new button.
Step 5: To design the dialog box as shown below:
Step 6: Change the id of the controls as:
Control
ID
Progress Indicator
IDC_PROGRESS1
OK button
IDC_START
Cancel button
IDCANCEL

Step 7: Use class wizard to adding new class as CComputeDlg class.


Step 8: After the class is generated add a “WM_TIMER message handler function for the “CComputeDlg” class.
Step 9: Add the BN_CLICKED message handler for the IDC_START and IDCANCEL, by accept the default names “OnStart” and “OnCancel” as shown below.

Step 10:  Add the three data members to the “CComputeDlg” class from select class view tab.
Class CComputeDlg : public CDialog
{
private:
              int m_nTimer;
              int m_nCount;
              enum { nMaxCount=10000 } ;
……………..
}

Step 11: Add the following initialization code in “CComputeDlg” constructor of the ComputeDlg.cpp file.
CComputeDlg::CComputeDlg(CWnd* pParent ) : CDialog(CComputeDlg::IDD,  pParent)
{   m_nCount=0;     }

Step 12: Define the OnStart, OnTimer, OnCancel function in ComputeDlg.cpp file.

void CComputeDlg::OnTimer(UINT nIDEvent)
{
              CProgressCtrl* pBar=(CProgressCtrl*)GetDlgItem(IDC_PROGRESS1);
              pBar->SetPos(m_nCount*100/nMaxCount);
              CDialog::OnTimer(nIDEvent);
}
void CComputeDlg::OnStart()
{
              MSG message;
              m_nTimer=SetTimer(1,100,NULL);
              ASSERT(m_nTimer!=0);
              GetDlgItem(IDC_START)->EnableWindow(FALSE);
              volatile int nTemp;
              for(m_nCount=0;m_nCount<nMaxCount; m_nCount++)
              {         for(nTemp=0;nTemp<10000;nTemp++) {  }
                        if(::PeekMessage(&message,NULL,0,0,PM_REMOVE))
                        {
                                    ::TranslateMessage(&message);
                                    ::DispatchMessage(&message);
                         }
              }
              CDialog::OnOK();
}
void CComputeDlg::OnCancel()
{
              TRACE("Entering CComputeDlg::OnCancel\n");
              if(m_nCount==0)
              {                     CDialog::OnCancel();             }
              else
              {                     m_nCount=nMaxCount;         }
 }
             
Step 13: Edit the OnDraw function in ThreadView.cpp as:
              void CThreadView::OnDraw(CDC* pDC)
{          pDC->TextOut(0,0,"Press the left mouse button here");  }

Step 14: Then use class wizard to change class as CThreadView and add the “OnLButtonDown” to handle WM_LBUTTONDOWN messages.
Step 15: Go to ThreadView.cpp file from file view tab, add the following code for OnLButtonDown() function.
void CThreadView::OnLButtonDown(UINT nFlags, CPoint point)
{
            CComputeDlg dlg;
            dlg.DoModal();
}
Step 16: In the Thread view.cpp add the following header file by include the following statement:
#include "ComputeDlg.h"
Step 17: Build and Run the application.
Step 18: Close the application.













OUTPUT:










RESULT:
            The VC++ program for threads has been successfully executed and verified.
Ex. No: 5                           
Date: 03-03-09                               DOCUMENT VIEW ARCHITECTURE

Aim:
            To create a VC++ application in document view architecture with serialization.

ALGORITHM:
Step 1: Select Start -->Programs –> Microsoft Visual Studio 6.0 and open “Microsoft visual C++ 6.0” application.
Step 2: Run the MFC AppWizard(exe) application, type the project name as “DocumentView” and click ok.
Step 3: Select single document option, click next.
Step 4: In the step 4 of the MFC AppWizard dialog deselect the “Printing and Preview” option and click finish.
Step 5: Declare the following string in DocumentViewDoc.h file as:
              public:
CString StrData;
Step 6: Initialize the data member in DocumnetViewDoc.cpp file as:
            CDocumentViewDoc::CDocumentViewDoc()
{
 StrData=" ";
}
Step 7: Edit the Serialize () function in DocumentViewDoc.cpp file as:
void CDocumentViewDoc::Serialize(CArchive& ar)
{
            if (ar.IsStoring())
            {
                        ar<<StrData;
            }
            else
            {
                        ar>>StrData;
            }
}
Step 8: Use class wizard to connect the WM_CHAR message to CDocumentViewView class as shown below.

Step 9: Edit the OnDraw() and OnChar message handler in DocViewView.cpp file as,
            void CDocumentViewView::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
            CDocumentViewDoc* pDoc=GetDocument();
            ASSERT_VALID(pDoc);
            pDoc->StrData+=nChar;
            Invalidate();
            pDoc->SetModifiedFlag();
            CView::OnChar(nChar, nRepCnt, nFlags);
}

void CDocumentViewView::OnDraw(CDC* pDC)
{
            CDocumentViewDoc* pDoc = GetDocument();
            ASSERT_VALID(pDoc);
            pDC->TextOut (0,0,pDoc->StrData);
}

Step 10: Build the program and run the application.
Step 11:  Close the application.








OUTPUT:

Creation of new document









Saving a document:





RESULT:
            The VC++ program for developing a application using document view architecture with serialization has been successfully executed and verified.
Ex.No: 6                                        
Date: 10-03-09                               DYNAMIC CONTROLS       

Aim:
            To write a VC++ program to create a simple object COM with the function to display the string and check the functionality of COM using visual basic.

ALGORITHM:
Step 1: Select Start -->Programs –> Microsoft Visual Studio 6.0 and open “Microsoft visual C++ 6.0” application.
Step 2: Choose new from file menu, Select ATL COM AppWizard and enter the project name as “MY_ATL”.
Step 3: Accept all the default settings and Click Finish button.
Step 4: Choose “Class view” tab in Workspace window.
Step 5: Right click on the MY_ATL classes and choose NEW ATL object option.
Step 6: Then select Simple Object in the ATL Object wizard and click next.
Step 7: Choose name tab and Fill the short Name as “TEST_ATL” other fields are filled automatically.
Step 8: In that wizard choose Attributes tab and enable interface as Custom and aggregation as No option, like as shown below and click ok.
Step 9: Choose class view from Workspace window double click the MY_ATL classes.
Ø  Double click the CTEST_ATL and right click on the ITEST_ATL and choose Add Methods option.
Step 10: Then fill the method name as  “add”  and attributes as  [in] long a, [in] long b,  [in] long *c and click ok.

 Step 11: Double click on the method “add ()” inside the ITEST_ATL class in workspace and write the following codes.
STDMETHODIMP CTEST_ATL::add(long a, long b, long *c)
{
           *c=a+b;
return S_OK;
}
Step 12:  Then save the project and just compile and execute it, now the COM was successfully created, and close the project.
Step 13:  Now open the Visual Basic 6.0 by choose Start -->Programs –> Microsoft Visual Studio 6.0 - - > Visual Basic 6.0.
Step 14. Choose standard exe from New Project dialog box.
Step 15: Then create a new form and design a button and change the name in caption as “ADD” in property dialog box.

Step 16: Then click Project menu and select Reference option.
Step 17: Now click the browse button and locate the MY_ATL.tlb file from the location where the MYATL project is stored.
Step 18: Now enable “MY_ATL 1.0 Type Library” option and click ok.
Step 19: Double click on Command button “ADD” and write the following codes.
Private Sub Command1_Click()
Dim a As MY_ATLLib.TEST_ATL
Set a = New TEST_ATL
Dim x As Long
a.Add 20, 50, x
MsgBox ("20+50= " & x)
End Sub
 Step 20: Run the Project by press F5 and click the ADD button to view the result.
 Step 21: Close the application.







OUTPUT:











RESULT:
            The VC++ program for Dynamic Controls has been successfully executed and verified.
Ex.No:7                                         
Date: 17-03-09                   CREATION OF MENU, TOOL BAR AND TOOL TIP

Aim:
            To create a Menu, toolbar and tool tip using MFC AppWizard.
ALGORITHM:
Step 1: Select Start -->Programs –> Microsoft Visual Studio 6.0 and open “Microsoft visual C++ 6.0” application.
Step 2: Run the MFC AppWizard (exe) application, type the project name as “ToolbarStatus” and click ok.
Step 3: Select single document option, click next.
Step 4: in the step 4 of the MFC AppWizard dialog deselect the “Printing and Preview” option and click finish.
Step 5: In the work space choose resource tab choose toolbar resources double click on the IDR_MAINFRAME from menu folder, to create a menu.
Step 6: To create a menu called “draw”, and create sub menu “Rectangle with the id as ID_DRAW_RECTANGLE”,
Step 7: In the work space choose resource tab choose toolbar resource.
Step 8: Double click on the IDR_MAINFRAME from Toolbar folder, create a new tool using painting area.
Step 9: Select toolbar Button property from view menu., select ID as  “ID_DRAW_RECTANGLE”.
Step 10:  Use the class wizard to change class name as “CToolBarStatusView” and add the following member functions.

Object ID
Message
Member Function
ID_DRAW_RECTANGLE
COMMAND
OnDrawRectangle
ID_DRAW_RECTANGLE
UPDATE_COMMAND_UI
OnUpdateDrawRectangle


Step 11:  Add the two data members to the “CToolBatStatusView” class by choose from class     view tab.
class CToolBarStatusView : public CView
{

            private:
            CRect m_rect;
            BOOL m_bSquare;
            ……..
            …….. 
}
Step 12:  Edit the “ToolBarStatusView.cpp” file from choose the   “file view“ tab
CToolBarStatusView::CToolBarStatusView():  
{
     m_bSquare=TRUE;
}
void CToolBarStatusView::OnDraw(CDC* pDC)
{
CBrush brush(HS_BDIAGONAL,5L);
if(m_bSquare)
{
     pDC->Rectangle (m_rect);
}
     pDC->SelectStockObject(WHITE_BRUSH);
}

void CToolBarStatusView::OnDrawRectangle()
{
m_rect+=CPoint(25,25);
InvalidateRect(m_rect);
}

void CToolBarStatusView::OnUpdateDrawRectangle(CCmdUI* pCmdUI)
{
     pCmdUI->Enable (m_bSquare);
}

Step 13: Build and test the application.
Step 14:  Close the application.


OUTPUT:








RESULT:
            The VC++ program for creation of menu, tool bar and tool tip application has been successfully executed and verified.
Ex. No: 8
Date: 17-03-09                                           CREATION OF DLL

Aim:
            To create a Server DLL with a function to display the string, and that will invoke from the client DLL.
ALGORITHM:
DLL Server(Mydll.dsw)
Step 1: Select Start -->Programs –> Microsoft Visual Studio 6.0 and open “Microsoft visual C++ 6.0” application.
Step 2: Run the MFC AppWizard(dll) application, type the project name as “Mydll.”and click ok.
Step 3: Select Regular DLL using Shared MFC DLL and click Finish button.
Step 4: Go to Class view and right click the Mydll class and choose new class.
Step 5: Now choose the class type to be the “Generic class” and type the class name as “CMyClass”.
Step 6:  Then add member function to the CMyClass by right clicking the CMyClass and type the function type as CString and function name as “sayhello(CString strName);” and the type of access  is public.
Step 7: Add the function definition in Myclass.cpp.
 CString CMyClass::sayhello(CString strName)
{
return "Hello"+strName;
}
Step 8: Go to file view in workspace editor and open the header file named “Myclass.h”.
Step 9: To call the DLL function from an external application have to modify the “CMyClass” inside the “MyClass.h” header file as :
class CMyClass 
{
public:
            _declspec(dllexport)CString sayhello(CString strName);
            _declspec(dllexport)CMyClass();
            _declspec(dllexport) virtual ~CMyClass();
};
Step 10: Compile the code without execution.
DLL Client (Testdll.dsw).
Step 1: Select Start -->Programs –> Microsoft Visual Studio 6.0 and open “Microsoft visual C++ 6.0” application.
Step 2: Run the MFC AppWizard (exe) application, type the project name as “Testdll”, and click ok.
Step 3:  Select dialog based option and click finish to create a project.
Step 4: In the resource editor design the dialog box as shown below.
Step 5:  To change the id of edit control as “IDC_NAME .


Step 6: Right click on the edit control and choose class wizard, to add the member variable “m_edit” with CString type.
Step 7: Right click on the OK button control and choose class wizard, choose Message maps add member function “OnOk” by select “BNCLICKED” message.
Step 8: Now add the following code in the “TestDlldlg.cpp” as by double click the ok button:
void CTestdllDlg::OnOK()
{
              UpdateData(TRUE);
              CString str=objMyClass.sayhello(m_edit);
              AfxMessageBox(str);
              CDialog::OnOK();
}
Step 9: Now add the entire path of the already created “MyDll’ server path in the “TestdllDlg.h” header file.
E.g.     #include "C:\Mydll\MyClass.h"
Step 10: Create an object for the CMyClass of the MyDll in the TestdllDlg.cpp as
                        CMyClass objMyClass;
Step 11:  Choose Project -- > Settings from menu and choose link tab , enter the entire path of   the “Mydll.Lib” file of the MyDll server file in  “object/library module” option as shown below.
Step 12: Now copy the “Mydll.dll” file from server project “MyDll” and paste inside the TestDll folder.
Step 13:  Now build the project and execute it.
Step 14:  Close the application.






OUTPUT:














RESULT:
            The VC++ program for creating DLL has been successfully executed and verified.
Ex. No: 9                                       
Date: 07-04-09                      DATA BASE ACCESS THROUGH ODBC

Aim:
            To create a Database using MS access and access the database from VC++ application through ODBC connectivity.
ALGORITHM:
Step 1: Create the Purchase database in MS access with the fields namely
Ø  BookName
Ø  EachCost.

Step 2: Select Start -->Programs –> Microsoft Visual Studio 6.0 and open the “Microsoft visual C++ 6.0” application.
Step 3: Choose new from file menu, Select MFC AppWizard (exe) and enter the project name as “odbc”.
Step 4: Select single document option and enable “document view architecture” click next.
Step 5: Select “Database view with file support” option and select Data Source option.
Step 6: In data options dialog box select data source as ODBC with MS Access Database and click ok.
Step 7: Select the database from the directory where we have created the database purchase and click ok select the table as shown below.
Step 8: Now accept all the default settings and click finish button.
Step 9: Design the dialog box with Book Name and Book cost fields.


Step 10: Use class wizard to add member variables for following controls by following
   Steps repeatedly for each control:
Ø    Select the control and right click and choose “class wizard” option
Ø    Choose Member variable option and select “Add variable button”, Enter the member variable name and the type.
Control ID
Member Variable
Type
IDC_EDIT1
m_text1
CString
IDC_EDIT2
m_text2
CString

Step 11: Add the message handler function for the IDC_BUTTON1 as:
Ø  Right click on ” CLICK HERE” button and choose class wizard
Ø  Choose “message maps” tab and double-click on BN_CLICKED command.
Ø  Accept the default OnButton1 function and click ok.
Step 12: Double click the “CLICK HERE” button add the following coding.
void COdbcView::OnButton1()
{
m_text1=m_pSet->m_BookName ;
UpdateData(false);
m_text2=m_pSet->m_Eachcost ;
UpdateData(false);
}
Step 13: Then build the code and run the program by selecting the database and view the records in the data base.
Step 14: Close the application.




OUTPUT:









RESULT:
            The VC++ program for Database using MS access has been executed and verified successfully.
Ex. No: 10                         
Date: 21-04-09                               ACTIVE X CONTROL

Aim:
            To create VC++ application to install active X control to our application and to perform some operations.
ALGORITHM:
Step 1: Select Start -->Programs –> Microsoft Visual Studio 6.0 and open Microsoft visual C++ 6.0 application.
Step 2:  Run the MFC AppWizard (EXE) application, type the project name as “ActiveXControls” and click ok.
Step 3: Select single document option, click next.
Step 4: In the step 3 of the MFC AppWizard dialog, to enable “ActiveXControls” option.
Step 5: In the step 4 of the MFC AppWizard dialog deselect the “Printing and Preview” option and click finish.
Step 6: Now to insert the ActiveX Controls in to our project, by Choose Project -- >Add to Project -- > Components and controls.
Step 7: Choose Registered Active X Controls, and then choose Calendar Control 8.0.
Step 8: Choose Resource from Insert menu, and then choose Dialog and select new button.
Step 9: To design the dialog box as shown below:
           

Step 10: Change the id of the newly created dialog as “IDD_ACTIVEXDIALOG”. Accept the id of OK and Cancel button as IDOK, IDCANCEL.
Step 11:  Modify the id of all the controls as like shown below.
Control
ID
Calendar control
IDC_CALENDAR1
Select Date button
IDC_SELECTDATE
Edit control
IDC_DAY
Edit control
IDC_MONTH
Edit control
IDC_YEAR
Next week button
IDC_NEXTWEEK

Step 12: Select View--> class wizard from menu, create a class CActiveXDialog class.
Ø  It shows a “adding a Class” dialog box select create a new class option and press ok.
Step 13: To create class by the dialog as shown below.
Step 14: Choose Message Maps tab and add the following message handler function as shown below.
Object ID
Message
Member Function
CActiveXDialog
WM_INITDIALOG
OnInitDialog()
IDC_CALENDAR1
NewMonth(event)
OnNewMonthCalendar1
IDC_SELECTDATE
BN_CLICKED
OnSelectdate
IDC_NEXTWEEK
BN_CLICKED
OnNextWeek
IDOK
BN_CLICKED
OnOk()

Step 15: Use Class Wizard, choose Member Variables and add the following member variable as
Control ID
Type
Member
IDC_CALENDAR!
CCalendar
m_calendar
IDC_DAY
Short
m_sDay
IDC_MONTH
Short
m_sMonth
IDC_YEAR
Short
m_sYear

Step 16: Edit the ActiveXDialog.h file by including the following member variables as data members.
                       
enum { IDD = IDD_ACTIVEXDIALOG };
            CCalendar       m_calendar;
            short    m_sDay;
            short    m_sMonth;
            short    m_sYear;
            //}}AFX_DATA
            COleVariant m_varValue;
            unsigned long m_BackColor;
Step 17:  Initialize the m_backColor value in ActiveXDialog.cpp as,

CActiveXDialog::CActiveXDialog(CWnd* pParent /*=NULL*/)
            : CDialog(CActiveXDialog::IDD, pParent)
{
            //{{AFX_DATA_INIT(CActiveXDialog)
            m_sDay = 0;
            m_sMonth = 0;
            m_sYear = 0;
            //}}AFX_DATA_INIT
            m_BackColor=0x8000000F;
}

Step 18: Edit the message handling functions OnInitDialog(), OnSelectdate(),OnNextweek() ,
OnOK()

BOOL CActiveXDialog::OnInitDialog()
{
            CDialog::OnInitDialog();
            m_calendar.SetValue (m_varValue);
return TRUE; 
}

void CActiveXDialog::OnSelectdate()
{
CDataExchange dx(this,TRUE);
DDX_Text(&dx,IDC_DAY,m_sDay);
DDX_Text(&dx,IDC_MONTH,m_sMonth);
DDX_Text(&dx,IDC_YEAR,m_sYear);
m_calendar.SetDay(m_sDay);
m_calendar.SetMonth(m_sMonth);
m_calendar.SetYear(m_sYear);
}


void CActiveXDialog::OnNextweek()
{
m_calendar.NextWeek();
}

void CActiveXDialog::OnOK()
{
           
            CDialog::OnOK();
            m_varValue=m_calendar.GetValue();
}

Step 19: Add the message handler WM_LBUTTON using class wizard for  the dialog box and add the following coding as in ActiveXControlsView.cpp file;

void CActiveXControlsView::OnLButtonDown(UINT nFlags, CPoint point)
{
CActiveXDialog dlg;
dlg.m_BackColor=RGB(255,251,240);
COleDateTime today=COleDateTime::GetCurrentTime();
dlg.m_varValue =COleDateTime(today.GetYear(),today.GetMonth(),today.GetDay(),0,0,0);
if(dlg.DoModal()==IDOK)
{
            COleDateTime date(dlg.m_varValue);
            AfxMessageBox(date.Format("%B %d ,%Y"));
}

Step 20 : Include the header file “ ActiveXDialog.cpp” in the file “ActivexControlsView.cpp” as
                        #include "ActiveXDialog.h"
Step 21: Include the following codes for OnDaraw() function in “ActivexControlsView.cpp” file as
void CActiveXControlsView::OnDraw(CDC* pDC)
{
pDC->TextOut(0,0,"Press the left mouse button here");
            CActiveXControlsDoc* pDoc = GetDocument();
            ASSERT_VALID(pDoc);
}
Step 22: Build the application and run the project.
Step 23: close the application.










OUTPUT:

Select Date operation
Ex. No: 1                                       
Date: 20-01-09                    Keyboard events and mouse message


Aim:
            To perform keyboard events and mouse message using Visual C++ programming.

Algorithm:

Step 1: Select Start -->Programs –> Microsoft Visual Studio 6.0 and open “Microsoft visual C++ 6.0” application, to create a new project named “mouse events”.
Step 2: Include the necessary header files to compute the above operations.
Step 3: Declare the windows functions in the parameter and declare the variable globally.
Step 4: Under the main functions in the parameter and variable that process the Keyboard events and mouse events.
Step 5: Check whether the entire variable are registered, if registered then.
Step 6: Using Switch case change character and using mouse click and other mouse functions.
Step 7: After the event destroy the function.
Step 8: Compile and execute the program.
Step 9: close the application.





Program:
#include<windows.h>
#include<string.h>
#include<stdio.h>
#include<winuser.h>
LRESULT CALLBACK windowfunc(HWND,UINT,WPARAM,LPARAM);
char szwinName[]="my win";
char str[100]="MOUSE EVENTS";
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpszargs,int nWinMode)
{
            HWND hwnd;
            MSG msg;
            WNDCLASS wcl;
            wcl.hInstance=hInstance;
            wcl.lpszClassName=szwinName;
            wcl.lpfnWndProc=windowfunc;
            wcl.style=CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS;
            wcl.hCursor = LoadCursor(NULL,IDC_ARROW);
            wcl.hIcon=LoadIcon(NULL,IDI_APPLICATION);
            wcl.lpszMenuName=NULL;
            wcl.cbClsExtra=0;
            wcl.cbWndExtra=0;
            wcl.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
if(!RegisterClass(&wcl))
                        return 0;
            hwnd=CreateWindow(szwinName,"mouse events",  
           WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,
CW_USEDEFAULT,CW_USEDEFAULT,HWND_DESKTOP,
NULL,hInstance,NULL);
            ShowWindow(hwnd,nWinMode);
            UpdateWindow(hwnd);
            while(GetMessage(&msg,0,0,0))
            {
                        TranslateMessage(&msg);
                        DispatchMessage(&msg);
            }
            return (msg.wParam);
}
LRESULT CALLBACK windowfunc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam)
{
            HDC hdc;
            PAINTSTRUCT ps;
switch(message)
            {
case WM_CHAR:
                        hdc=GetDC(hwnd);
                        TextOut(hdc,1,1," ",2);
                        sprintf(str,"%c",(char)wParam);
                        TextOut(hdc,1,1,str,strlen(str));
                        ReleaseDC(hwnd,hdc);
                        break;
case WM_PAINT:
                        hdc=BeginPaint(hwnd,&ps);
                        TextOut(hdc,300,1,str,strlen(str));
                        EndPaint(hwnd,&ps);
                        break;
case WM_RBUTTONDOWN:
                        hdc=GetDC(hwnd);
                        strcpy(str,"Right Button is down");
                        TextOut(hdc,LOWORD(lParam),HIWORD(lParam),str,strlen(str));
                        ReleaseDC(hwnd,hdc);
                        break;
case WM_LBUTTONDOWN:
                        hdc=GetDC(hwnd);
                        strcpy(str,"Left Button is down");
                        TextOut(hdc,LOWORD(lParam),HIWORD(lParam),str,strlen(str));
                        ReleaseDC(hwnd,hdc);
                        break;
case WM_LBUTTONDBLCLK:
                        hdc=GetDC(hwnd);
                        strcpy(str,"DOUBLE CLICK Left Button is down");
                        TextOut(hdc,LOWORD(lParam),HIWORD(lParam),str,strlen(str));
                        ReleaseDC(hwnd,hdc);
                        break;
case WM_RBUTTONDBLCLK:
                        hdc=GetDC(hwnd);
                        strcpy(str,"DOUBLE CLICK RIGHT Button is down");
                        TextOut(hdc,LOWORD(lParam),HIWORD(lParam),str,strlen(str));
                        ReleaseDC(hwnd,hdc);
                        break;
case WM_DESTROY:
                        PostQuitMessage(0);
                        break;
default:
                        return DefWindowProc(hwnd,message,wParam,lParam);
}
return 0;
}










Output:




result:
            Thus the VC++ program to perform keyboard events and mouse messages has been complied and executed successfully.
Ex.No: 2                            
Date  : 10-02-09                             DIALOG BASED APPLICATION

Aim:
            To write a VC++ program to develop a calculator using Dialog based application.

ALGORITHM:
Step 1: Select Start -->Programs –> Microsoft Visual Studio 6.0 and open the Microsoft visual C++ 6.0 application.
Step 2:  Run the AppWizard to generate a project “DialogBasedAppl”.
Ø  Choose New from VC++ File menu and then click project tab in the resulting new dialog box, Select MFC AppWizard (exe).
Ø  Type the project name “DialogBasedAppl” and click the ok button.
Ø  Select the “Dialog Based” option in the AppWizard and click finish to develop project.
Step 3:  The Resource editor enabled, now design the dialog box using the controls as :
Step 4:  Use the dialog editor (i.e Rightclick on the control and select properties) to assign
 control IDs to the controls as
Control
ID
First operand edit control
IDC_FIRST
Second operand edit control
IDC_SECOND
Result edit control
IDC_RESULT
First Radio button (enable group property option)
IDC_OPERATION
Compute push button
IDC_COMPUTE

Step 5: Open the properties dialog box by right click any where inside the resource editor
             and choose properties option
Ø  Choose style tab enables the options “System Menu” and “Minimize box”.
Step 6: Use class wizard to add member variables for following controls by following
Steps repeatedly for each controls:
Ø  Select the control and right click and choose “class wizard” option
Ø  Choose Member variable option and select “Add variable button”, Enter the member variable name and the type.
Control ID
Member Variable
Type
IDC_FIRST
m_dFirst
Double
IDC_SECOND
m_dSecond
Double
IDC_RESULT
m_dResult
Double
IDC_OPERATION
m_nOperation
int

Step 7: Add the message handler OnCompute for the IDC_COMPUTE button:
Ø  Right click on compute button and choose class wizard
Ø  Choose “message maps” tab and double-click on BN_CLICKED command.
Ø  Accept the default OnCompute function and click ok.
Step 8: Double click on COMPUTE button and add the following coding for OnCompute() function.
void CDialogBasedApplDlg::OnCompute()
{
            UpdateData(TRUE);
            switch(m_nOperation)
            {
            //Addition
case 0:
                        m_dResult=m_dFirst+m_dSecond;
                        break;
            //Subtraction
            case 1:
                        m_dResult=m_dFirst-m_dSecond;
                        break;
            //Multiplication
            case 2:
                        m_dResult=m_dFirst*m_dSecond;
                        break;
            //Division
            case 3:
                        if(m_dSecond!=0.0)
                        {
                                    m_dResult=m_dFirst/m_dSecond;
                        }
                        else
                        {
                                    AfxMessageBox("Divide by Zero");
                                    m_dResult=0.0;
                        }
                        break;
            default:
                        TRACE("default;,m_nOperation=%d\n",m_nOperation);
            }
            UpdateData(FALSE);
}

Step 9:  Build and test the DialogBasedAppl.DSW application.
Step 10: Close the application.









OUTPUT:

Addition Operation






Division Operation







RESULT:
            The VC++ program for develop calculator using dialog based application has been successfully executed and verified.
Ex.No: 3                                        
Date  :  17-02-09                            MDI APPLICATION

Aim:
            To write a VC++ program to develop a MDI document by using MFC AppWizard(exe).

ALGORITHM:
Step 1: Select Start -->Programs –> Microsoft Visual Studio 6.0 and open “Microsoft visual C++ 6.0” application.
Step 2: Run the AppWizard to create MDI Application, Select MFC AppWizard (exe), enter the project name as “MDI” and press ok to create a project.
Step 3: Select “Multiple Documents” option and deselect the “Document view architecture” and click next.
Step 4:  Select “Database support” to none and click the next button.
Step 5:  Accept the default settings and select Finish button.
Step 6:  Now the App wizard will create a new MDI project and click ok.
Step 7: Now the MDI project will be created with its specific classes.
Step 8: in the workspace window select the file view tab.
Step 9:  in the Source files open the ChildView.cpp file.
Step 10:  Add the following codes for CChildView::OnPaint() function.
void CChildView::OnPaint()
{
              CPaintDC dc(this); // device context for painting
              dc.TextOut(0,0,"Sample of MDI");
             
dc.Rectangle(100,100,200,200);
}

Step 11: Compile and execute the application.
Step 12: Close the application.




















OUTPUT:










RESULT:
            The VC++ program for developing MDI application by using MFC AppWizard (exe), has been successfully executed and verified.
Ex.No:4                                         
Date: 25-02-09                                           THREAD

Aim:
            To create a VC++ project to implement the threads in our application.

ALGORITHM:
Step 1: Select Start -->Programs –> Microsoft Visual Studio 6.0 and open “Microsoft visual C++ 6.0” application.
Step 2: Run the MFC AppWizard (exe) application, type the project name as “Thread “and click ok.
Step 3: Select single document option, accept all default settings and click finish button.
Step 4: Choose Resource from Visual C++ Insert menu, and then choose Dialog and select new button.
Step 5: To design the dialog box as shown below:
Step 6: Change the id of the controls as:
Control
ID
Progress Indicator
IDC_PROGRESS1
OK button
IDC_START
Cancel button
IDCANCEL

Step 7: Use class wizard to adding new class as CComputeDlg class.


Step 8: After the class is generated add a “WM_TIMER message handler function for the “CComputeDlg” class.
Step 9: Add the BN_CLICKED message handler for the IDC_START and IDCANCEL, by accept the default names “OnStart” and “OnCancel” as shown below.

Step 10:  Add the three data members to the “CComputeDlg” class from select class view tab.
Class CComputeDlg : public CDialog
{
private:
              int m_nTimer;
              int m_nCount;
              enum { nMaxCount=10000 } ;
……………..
}

Step 11: Add the following initialization code in “CComputeDlg” constructor of the ComputeDlg.cpp file.
CComputeDlg::CComputeDlg(CWnd* pParent ) : CDialog(CComputeDlg::IDD,  pParent)
{   m_nCount=0;     }

Step 12: Define the OnStart, OnTimer, OnCancel function in ComputeDlg.cpp file.

void CComputeDlg::OnTimer(UINT nIDEvent)
{
              CProgressCtrl* pBar=(CProgressCtrl*)GetDlgItem(IDC_PROGRESS1);
              pBar->SetPos(m_nCount*100/nMaxCount);
              CDialog::OnTimer(nIDEvent);
}
void CComputeDlg::OnStart()
{
              MSG message;
              m_nTimer=SetTimer(1,100,NULL);
              ASSERT(m_nTimer!=0);
              GetDlgItem(IDC_START)->EnableWindow(FALSE);
              volatile int nTemp;
              for(m_nCount=0;m_nCount<nMaxCount; m_nCount++)
              {         for(nTemp=0;nTemp<10000;nTemp++) {  }
                        if(::PeekMessage(&message,NULL,0,0,PM_REMOVE))
                        {
                                    ::TranslateMessage(&message);
                                    ::DispatchMessage(&message);
                         }
              }
              CDialog::OnOK();
}
void CComputeDlg::OnCancel()
{
              TRACE("Entering CComputeDlg::OnCancel\n");
              if(m_nCount==0)
              {                     CDialog::OnCancel();             }
              else
              {                     m_nCount=nMaxCount;         }
 }
             
Step 13: Edit the OnDraw function in ThreadView.cpp as:
              void CThreadView::OnDraw(CDC* pDC)
{          pDC->TextOut(0,0,"Press the left mouse button here");  }

Step 14: Then use class wizard to change class as CThreadView and add the “OnLButtonDown” to handle WM_LBUTTONDOWN messages.
Step 15: Go to ThreadView.cpp file from file view tab, add the following code for OnLButtonDown() function.
void CThreadView::OnLButtonDown(UINT nFlags, CPoint point)
{
            CComputeDlg dlg;
            dlg.DoModal();
}
Step 16: In the Thread view.cpp add the following header file by include the following statement:
#include "ComputeDlg.h"
Step 17: Build and Run the application.
Step 18: Close the application.













OUTPUT:










RESULT:
            The VC++ program for threads has been successfully executed and verified.
Ex. No: 5                           
Date: 03-03-09                               DOCUMENT VIEW ARCHITECTURE

Aim:
            To create a VC++ application in document view architecture with serialization.

ALGORITHM:
Step 1: Select Start -->Programs –> Microsoft Visual Studio 6.0 and open “Microsoft visual C++ 6.0” application.
Step 2: Run the MFC AppWizard(exe) application, type the project name as “DocumentView” and click ok.
Step 3: Select single document option, click next.
Step 4: In the step 4 of the MFC AppWizard dialog deselect the “Printing and Preview” option and click finish.
Step 5: Declare the following string in DocumentViewDoc.h file as:
              public:
CString StrData;
Step 6: Initialize the data member in DocumnetViewDoc.cpp file as:
            CDocumentViewDoc::CDocumentViewDoc()
{
 StrData=" ";
}
Step 7: Edit the Serialize () function in DocumentViewDoc.cpp file as:
void CDocumentViewDoc::Serialize(CArchive& ar)
{
            if (ar.IsStoring())
            {
                        ar<<StrData;
            }
            else
            {
                        ar>>StrData;
            }
}
Step 8: Use class wizard to connect the WM_CHAR message to CDocumentViewView class as shown below.

Step 9: Edit the OnDraw() and OnChar message handler in DocViewView.cpp file as,
            void CDocumentViewView::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
            CDocumentViewDoc* pDoc=GetDocument();
            ASSERT_VALID(pDoc);
            pDoc->StrData+=nChar;
            Invalidate();
            pDoc->SetModifiedFlag();
            CView::OnChar(nChar, nRepCnt, nFlags);
}

void CDocumentViewView::OnDraw(CDC* pDC)
{
            CDocumentViewDoc* pDoc = GetDocument();
            ASSERT_VALID(pDoc);
            pDC->TextOut (0,0,pDoc->StrData);
}

Step 10: Build the program and run the application.
Step 11:  Close the application.








OUTPUT:

Creation of new document









Saving a document:





RESULT:
            The VC++ program for developing a application using document view architecture with serialization has been successfully executed and verified.
Ex.No: 6                                        
Date: 10-03-09                               DYNAMIC CONTROLS       

Aim:
            To write a VC++ program to create a simple object COM with the function to display the string and check the functionality of COM using visual basic.

ALGORITHM:
Step 1: Select Start -->Programs –> Microsoft Visual Studio 6.0 and open “Microsoft visual C++ 6.0” application.
Step 2: Choose new from file menu, Select ATL COM AppWizard and enter the project name as “MY_ATL”.
Step 3: Accept all the default settings and Click Finish button.
Step 4: Choose “Class view” tab in Workspace window.
Step 5: Right click on the MY_ATL classes and choose NEW ATL object option.
Step 6: Then select Simple Object in the ATL Object wizard and click next.
Step 7: Choose name tab and Fill the short Name as “TEST_ATL” other fields are filled automatically.
Step 8: In that wizard choose Attributes tab and enable interface as Custom and aggregation as No option, like as shown below and click ok.
Step 9: Choose class view from Workspace window double click the MY_ATL classes.
Ø  Double click the CTEST_ATL and right click on the ITEST_ATL and choose Add Methods option.
Step 10: Then fill the method name as  “add”  and attributes as  [in] long a, [in] long b,  [in] long *c and click ok.

 Step 11: Double click on the method “add ()” inside the ITEST_ATL class in workspace and write the following codes.
STDMETHODIMP CTEST_ATL::add(long a, long b, long *c)
{
           *c=a+b;
return S_OK;
}
Step 12:  Then save the project and just compile and execute it, now the COM was successfully created, and close the project.
Step 13:  Now open the Visual Basic 6.0 by choose Start -->Programs –> Microsoft Visual Studio 6.0 - - > Visual Basic 6.0.
Step 14. Choose standard exe from New Project dialog box.
Step 15: Then create a new form and design a button and change the name in caption as “ADD” in property dialog box.

Step 16: Then click Project menu and select Reference option.
Step 17: Now click the browse button and locate the MY_ATL.tlb file from the location where the MYATL project is stored.
Step 18: Now enable “MY_ATL 1.0 Type Library” option and click ok.
Step 19: Double click on Command button “ADD” and write the following codes.
Private Sub Command1_Click()
Dim a As MY_ATLLib.TEST_ATL
Set a = New TEST_ATL
Dim x As Long
a.Add 20, 50, x
MsgBox ("20+50= " & x)
End Sub
 Step 20: Run the Project by press F5 and click the ADD button to view the result.
 Step 21: Close the application.







OUTPUT:











RESULT:
            The VC++ program for Dynamic Controls has been successfully executed and verified.
Ex.No:7                                         
Date: 17-03-09                   CREATION OF MENU, TOOL BAR AND TOOL TIP

Aim:
            To create a Menu, toolbar and tool tip using MFC AppWizard.
ALGORITHM:
Step 1: Select Start -->Programs –> Microsoft Visual Studio 6.0 and open “Microsoft visual C++ 6.0” application.
Step 2: Run the MFC AppWizard (exe) application, type the project name as “ToolbarStatus” and click ok.
Step 3: Select single document option, click next.
Step 4: in the step 4 of the MFC AppWizard dialog deselect the “Printing and Preview” option and click finish.
Step 5: In the work space choose resource tab choose toolbar resources double click on the IDR_MAINFRAME from menu folder, to create a menu.
Step 6: To create a menu called “draw”, and create sub menu “Rectangle with the id as ID_DRAW_RECTANGLE”,
Step 7: In the work space choose resource tab choose toolbar resource.
Step 8: Double click on the IDR_MAINFRAME from Toolbar folder, create a new tool using painting area.
Step 9: Select toolbar Button property from view menu., select ID as  “ID_DRAW_RECTANGLE”.
Step 10:  Use the class wizard to change class name as “CToolBarStatusView” and add the following member functions.

Object ID
Message
Member Function
ID_DRAW_RECTANGLE
COMMAND
OnDrawRectangle
ID_DRAW_RECTANGLE
UPDATE_COMMAND_UI
OnUpdateDrawRectangle


Step 11:  Add the two data members to the “CToolBatStatusView” class by choose from class     view tab.
class CToolBarStatusView : public CView
{

            private:
            CRect m_rect;
            BOOL m_bSquare;
            ……..
            …….. 
}
Step 12:  Edit the “ToolBarStatusView.cpp” file from choose the   “file view“ tab
CToolBarStatusView::CToolBarStatusView():  
{
     m_bSquare=TRUE;
}
void CToolBarStatusView::OnDraw(CDC* pDC)
{
CBrush brush(HS_BDIAGONAL,5L);
if(m_bSquare)
{
     pDC->Rectangle (m_rect);
}
     pDC->SelectStockObject(WHITE_BRUSH);
}

void CToolBarStatusView::OnDrawRectangle()
{
m_rect+=CPoint(25,25);
InvalidateRect(m_rect);
}

void CToolBarStatusView::OnUpdateDrawRectangle(CCmdUI* pCmdUI)
{
     pCmdUI->Enable (m_bSquare);
}

Step 13: Build and test the application.
Step 14:  Close the application.


OUTPUT:








RESULT:
            The VC++ program for creation of menu, tool bar and tool tip application has been successfully executed and verified.
Ex. No: 8
Date: 17-03-09                                           CREATION OF DLL

Aim:
            To create a Server DLL with a function to display the string, and that will invoke from the client DLL.
ALGORITHM:
DLL Server(Mydll.dsw)
Step 1: Select Start -->Programs –> Microsoft Visual Studio 6.0 and open “Microsoft visual C++ 6.0” application.
Step 2: Run the MFC AppWizard(dll) application, type the project name as “Mydll.”and click ok.
Step 3: Select Regular DLL using Shared MFC DLL and click Finish button.
Step 4: Go to Class view and right click the Mydll class and choose new class.
Step 5: Now choose the class type to be the “Generic class” and type the class name as “CMyClass”.
Step 6:  Then add member function to the CMyClass by right clicking the CMyClass and type the function type as CString and function name as “sayhello(CString strName);” and the type of access  is public.
Step 7: Add the function definition in Myclass.cpp.
 CString CMyClass::sayhello(CString strName)
{
return "Hello"+strName;
}
Step 8: Go to file view in workspace editor and open the header file named “Myclass.h”.
Step 9: To call the DLL function from an external application have to modify the “CMyClass” inside the “MyClass.h” header file as :
class CMyClass 
{
public:
            _declspec(dllexport)CString sayhello(CString strName);
            _declspec(dllexport)CMyClass();
            _declspec(dllexport) virtual ~CMyClass();
};
Step 10: Compile the code without execution.
DLL Client (Testdll.dsw).
Step 1: Select Start -->Programs –> Microsoft Visual Studio 6.0 and open “Microsoft visual C++ 6.0” application.
Step 2: Run the MFC AppWizard (exe) application, type the project name as “Testdll”, and click ok.
Step 3:  Select dialog based option and click finish to create a project.
Step 4: In the resource editor design the dialog box as shown below.
Step 5:  To change the id of edit control as “IDC_NAME .


Step 6: Right click on the edit control and choose class wizard, to add the member variable “m_edit” with CString type.
Step 7: Right click on the OK button control and choose class wizard, choose Message maps add member function “OnOk” by select “BNCLICKED” message.
Step 8: Now add the following code in the “TestDlldlg.cpp” as by double click the ok button:
void CTestdllDlg::OnOK()
{
              UpdateData(TRUE);
              CString str=objMyClass.sayhello(m_edit);
              AfxMessageBox(str);
              CDialog::OnOK();
}
Step 9: Now add the entire path of the already created “MyDll’ server path in the “TestdllDlg.h” header file.
E.g.     #include "C:\Mydll\MyClass.h"
Step 10: Create an object for the CMyClass of the MyDll in the TestdllDlg.cpp as
                        CMyClass objMyClass;
Step 11:  Choose Project -- > Settings from menu and choose link tab , enter the entire path of   the “Mydll.Lib” file of the MyDll server file in  “object/library module” option as shown below.
Step 12: Now copy the “Mydll.dll” file from server project “MyDll” and paste inside the TestDll folder.
Step 13:  Now build the project and execute it.
Step 14:  Close the application.






OUTPUT:














RESULT:
            The VC++ program for creating DLL has been successfully executed and verified.
Ex. No: 9                                       
Date: 07-04-09                      DATA BASE ACCESS THROUGH ODBC

Aim:
            To create a Database using MS access and access the database from VC++ application through ODBC connectivity.
ALGORITHM:
Step 1: Create the Purchase database in MS access with the fields namely
Ø  BookName
Ø  EachCost.

Step 2: Select Start -->Programs –> Microsoft Visual Studio 6.0 and open the “Microsoft visual C++ 6.0” application.
Step 3: Choose new from file menu, Select MFC AppWizard (exe) and enter the project name as “odbc”.
Step 4: Select single document option and enable “document view architecture” click next.
Step 5: Select “Database view with file support” option and select Data Source option.
Step 6: In data options dialog box select data source as ODBC with MS Access Database and click ok.
Step 7: Select the database from the directory where we have created the database purchase and click ok select the table as shown below.
Step 8: Now accept all the default settings and click finish button.
Step 9: Design the dialog box with Book Name and Book cost fields.


Step 10: Use class wizard to add member variables for following controls by following
   Steps repeatedly for each control:
Ø    Select the control and right click and choose “class wizard” option
Ø    Choose Member variable option and select “Add variable button”, Enter the member variable name and the type.
Control ID
Member Variable
Type
IDC_EDIT1
m_text1
CString
IDC_EDIT2
m_text2
CString

Step 11: Add the message handler function for the IDC_BUTTON1 as:
Ø  Right click on ” CLICK HERE” button and choose class wizard
Ø  Choose “message maps” tab and double-click on BN_CLICKED command.
Ø  Accept the default OnButton1 function and click ok.
Step 12: Double click the “CLICK HERE” button add the following coding.
void COdbcView::OnButton1()
{
m_text1=m_pSet->m_BookName ;
UpdateData(false);
m_text2=m_pSet->m_Eachcost ;
UpdateData(false);
}
Step 13: Then build the code and run the program by selecting the database and view the records in the data base.
Step 14: Close the application.




OUTPUT:









RESULT:
            The VC++ program for Database using MS access has been executed and verified successfully.
Ex. No: 10                         
Date: 21-04-09                               ACTIVE X CONTROL

Aim:
            To create VC++ application to install active X control to our application and to perform some operations.
ALGORITHM:
Step 1: Select Start -->Programs –> Microsoft Visual Studio 6.0 and open Microsoft visual C++ 6.0 application.
Step 2:  Run the MFC AppWizard (EXE) application, type the project name as “ActiveXControls” and click ok.
Step 3: Select single document option, click next.
Step 4: In the step 3 of the MFC AppWizard dialog, to enable “ActiveXControls” option.
Step 5: In the step 4 of the MFC AppWizard dialog deselect the “Printing and Preview” option and click finish.
Step 6: Now to insert the ActiveX Controls in to our project, by Choose Project -- >Add to Project -- > Components and controls.
Step 7: Choose Registered Active X Controls, and then choose Calendar Control 8.0.
Step 8: Choose Resource from Insert menu, and then choose Dialog and select new button.
Step 9: To design the dialog box as shown below:
           

Step 10: Change the id of the newly created dialog as “IDD_ACTIVEXDIALOG”. Accept the id of OK and Cancel button as IDOK, IDCANCEL.
Step 11:  Modify the id of all the controls as like shown below.
Control
ID
Calendar control
IDC_CALENDAR1
Select Date button
IDC_SELECTDATE
Edit control
IDC_DAY
Edit control
IDC_MONTH
Edit control
IDC_YEAR
Next week button
IDC_NEXTWEEK

Step 12: Select View--> class wizard from menu, create a class CActiveXDialog class.
Ø  It shows a “adding a Class” dialog box select create a new class option and press ok.
Step 13: To create class by the dialog as shown below.
Step 14: Choose Message Maps tab and add the following message handler function as shown below.
Object ID
Message
Member Function
CActiveXDialog
WM_INITDIALOG
OnInitDialog()
IDC_CALENDAR1
NewMonth(event)
OnNewMonthCalendar1
IDC_SELECTDATE
BN_CLICKED
OnSelectdate
IDC_NEXTWEEK
BN_CLICKED
OnNextWeek
IDOK
BN_CLICKED
OnOk()

Step 15: Use Class Wizard, choose Member Variables and add the following member variable as
Control ID
Type
Member
IDC_CALENDAR!
CCalendar
m_calendar
IDC_DAY
Short
m_sDay
IDC_MONTH
Short
m_sMonth
IDC_YEAR
Short
m_sYear

Step 16: Edit the ActiveXDialog.h file by including the following member variables as data members.
                       
enum { IDD = IDD_ACTIVEXDIALOG };
            CCalendar       m_calendar;
            short    m_sDay;
            short    m_sMonth;
            short    m_sYear;
            //}}AFX_DATA
            COleVariant m_varValue;
            unsigned long m_BackColor;
Step 17:  Initialize the m_backColor value in ActiveXDialog.cpp as,

CActiveXDialog::CActiveXDialog(CWnd* pParent /*=NULL*/)
            : CDialog(CActiveXDialog::IDD, pParent)
{
            //{{AFX_DATA_INIT(CActiveXDialog)
            m_sDay = 0;
            m_sMonth = 0;
            m_sYear = 0;
            //}}AFX_DATA_INIT
            m_BackColor=0x8000000F;
}

Step 18: Edit the message handling functions OnInitDialog(), OnSelectdate(),OnNextweek() ,
OnOK()

BOOL CActiveXDialog::OnInitDialog()
{
            CDialog::OnInitDialog();
            m_calendar.SetValue (m_varValue);
return TRUE; 
}

void CActiveXDialog::OnSelectdate()
{
CDataExchange dx(this,TRUE);
DDX_Text(&dx,IDC_DAY,m_sDay);
DDX_Text(&dx,IDC_MONTH,m_sMonth);
DDX_Text(&dx,IDC_YEAR,m_sYear);
m_calendar.SetDay(m_sDay);
m_calendar.SetMonth(m_sMonth);
m_calendar.SetYear(m_sYear);
}


void CActiveXDialog::OnNextweek()
{
m_calendar.NextWeek();
}

void CActiveXDialog::OnOK()
{
           
            CDialog::OnOK();
            m_varValue=m_calendar.GetValue();
}

Step 19: Add the message handler WM_LBUTTON using class wizard for  the dialog box and add the following coding as in ActiveXControlsView.cpp file;

void CActiveXControlsView::OnLButtonDown(UINT nFlags, CPoint point)
{
CActiveXDialog dlg;
dlg.m_BackColor=RGB(255,251,240);
COleDateTime today=COleDateTime::GetCurrentTime();
dlg.m_varValue =COleDateTime(today.GetYear(),today.GetMonth(),today.GetDay(),0,0,0);
if(dlg.DoModal()==IDOK)
{
            COleDateTime date(dlg.m_varValue);
            AfxMessageBox(date.Format("%B %d ,%Y"));
}

Step 20 : Include the header file “ ActiveXDialog.cpp” in the file “ActivexControlsView.cpp” as
                        #include "ActiveXDialog.h"
Step 21: Include the following codes for OnDaraw() function in “ActivexControlsView.cpp” file as
void CActiveXControlsView::OnDraw(CDC* pDC)
{
pDC->TextOut(0,0,"Press the left mouse button here");
            CActiveXControlsDoc* pDoc = GetDocument();
            ASSERT_VALID(pDoc);
}
Step 22: Build the application and run the project.
Step 23: close the application.










OUTPUT:

Select Date operation




RESULT:
            The VC++ program for develop application to use active controls has been successfully executed and verified.




RESULT:
            The VC++ program for develop application to use active controls has been successfully executed and verified.

No comments:

Post a Comment

PLEASE ENTER THE VALUABLE COMMENTS