Você está na página 1de 45

VIDYAA VIKAS COLLEGE OF ENGINEERING AND TECHNOLOGY TIRUCHENGODE - 637 214

DEPARTMENT OF MASTER OF COMPUTER APPLICATIONS

RECORD NOTEBOOK

NAME

REGISTER NO

: ..

SUBJECT CODE

: .

SUBJECT

: .

VIDYAA VIKAS COLLEGE OF ENGINEERING AND TECHNOLOGY TIRUCHENGODE-637 214

DEPARTMENT OF MASTER OF COMPUTER APPLICATIONS

Certified

that

this is

the bonafide

record

of

work done by register academic

Mr / Ms. with number. of II year / IV semester during the year 2011 - 2012 for the VISUAL PROGRAMMING LAB.

Staff-in-charge

Head of the Department

Submitted for the university practical examination held on.

Internal Examiner

External Examiner

INDEX

S.No

DATE

NAME OF THE PROGRAM

PAGE NO

MARKS

STAFF SIGN

WINDOWS SDK/Visual C++

1.

KEYBOARD AND MOUSE EVENT

2.

DIALOG BASED APPLICATIONS

3.

MULTIPLE DOCUMENT INTERFACE

VISUAL C++

4.

THREADS

5.

DOCUMENT VIEW ARCHITECTURE, SERIALIZATION

6.

DYNAMIC CONTROLS

7.

MENU, ACCELERATOR, TOOL TIP, TOOL BAR

8.

CREATING DLLs AND USING THEM

9.

DATA ACCESS THROUGH ODBC

10.

ACTIVEX CONTROL

AVERAGE

EX.NO: KEYBOARD AND MOUSE EVENT AIM:

DATE:

To write a program in visual c++ for performing mouse and keyboard events. PROCEDURE: Step1: Start the process. Step2: Create the window by using window function and set parameters as need. Step3: Use the showwindow( ) to display the window. Step4: Add mouse and keyboard event in my function. Step5: Use message WM_LBUTTONDOWM and WM_LBUTTONUP for drawing dotted lines. Step6: Use message WM_KEYDOWN and WM_KEYUP for pressing and releasing any key in keyboard. Step7: Use WM_SYSKEYDOWN and WM_SYSKEYUP for performing alt or f10 key events. Step8: Build and run the project. Step9: stop the process.

CODING: #include"stdafx.h" LRESULT CALLBACK WndProc(HWND,UINT,UINT,long); WNDCLASS a; int flag=0; int WINAPI WinMain(HINSTANCE i,HINSTANCE j,char *k,int l) { HWND h; MSG m; a.hInstance =i; a.lpszClassName ="My"; a.lpfnWndProc =WndProc; a.hbrBackground =(HBRUSH) GetStockObject(WHITE_BRUSH); RegisterClass(&a); h=CreateWindow("My","Title",WS_OVERLAPPEDWINDOW, 10,10,150,100,0,0,0,i,0); ShowWindow(h,3); while(GetMessage(&m,0,0,0)) DispatchMessage(&m); return 0; } LRESULT CALLBACK WndProc(HWND W,UINT x,UINT y,long z) { HDC d; d=GetDC(W); switch(x) { case WM_LBUTTONDOWN: flag=1; break;

case WM_MOUSEMOVE: if(flag==1) { d=GetDC(W); SetPixel(d,LOWORD(z),HIWORD(z),RGB(255,85,158)); ReleaseDC(W,d); } break;

case WM_LBUTTONUP: flag=0; break; case WM_KEYDOWN: TextOut(d,100,100,"Key Pressed",12);break; case WM_KEYUP: TextOut(d,100,100,"Key Released",12);break; case WM_SYSKEYDOWN: TextOut(d,500,500,"Alt(or)F10 is pressed",21);break; case WM_SYSKEYUP: TextOut(d,500,500,"Alt(or)F10 is Released",22);break; default: return DefWindowProc(W,x,y,z); } return 0; }

OUTPUT:

RESULT:

EX.NO: DIALOG BASED APPLICATIONS AIM: To write a VC++ program for Dialog based Control. PROCEDURE: Step 1: Start the Program. Step 2: Create the New project by selecting

DATE:

File->New->MFCAppWizard(exe)and type Filename,and Select Dialog based option then click Finish. Step 3: select resource tab Choose the Dialog boxname IDD_DIALOG_BOX to add control to the dialog box using the tool box. Step 4: Build the dialog box with Name,Age,Salary,Experience, grade by dragging static Button and edit Button. Step 5: Select Each and every staticcontrols and change the caption. Step 6: Add value variable and control variable by selecting the right click on the edit control and select the Class wizard from the menu and select the member variable and type member variable with related category type. Step 7: select message map tab. Step 8: select IDOK from object IDs then select BN_CLICKED from messages. Step 9: Press add function and then press edit code button and type the code. Step 10: Click on ok Button. Click on build and execute.

CODING: DIALOG BASED CONTROL: //Initialize Member Variable BOOL CDialogDlg::OnInitDialog() { m_Name=_T("Enter your name"); m_Age=0; m_Salary=0; CDialog::OnInitDialog(); m_Gradeval.AddString("I");m_Gradeval.AddString("II"); m_Gradeval.AddString("III");m_Gradeval.AddString("IV"); m_Gradeval.SetCurSel(0); m_Experienceval.AddString("<3 yrs"); m_Experienceval.AddString("3 to 5 yrs"); m_Experienceval.AddString("6 to 10 yrs"); m_Experienceval.SetCurSel(0); return TRUE; }

//Message Handler for OK void CDialogDlg::OnOK() { CDialog::OnOK(); CString str,temp; str="Name:"+m_Name; str+="\nGrade:"+m_Grade; str+="\nExperience:"+m_Experience; str+=\nAge; temp.Format("%d",m_Age); str+=temp; str+="\nSalary"; temp.Format("%d",m_Salary); str+=temp; MessageBox(str); }

OUTPUT:

RESULT:

EX.NO: MULTIPLE DOCUMENT INTERFACE AIM: To write a VC++ program to create a message box using MDI. PROCEDURE: Step 1: Start the Program

DATE:

Step 2: Create the New project by selecting File->New->MFCAppWizard (exe) and type Filename. Step 3: Choose MDI option to create MDI and click finish. Step 4: Choose view from the File view and Edit code. Step 5: Then save and Press ctrl+f5 to compile and press ctrl+f7 to execute. Step6: Stop the program.

CODING: void CMultipledocView::OnDraw(CDC* pDC) { CMultipledocDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); MessageBox("This is multiple document",0,MB_OK);

OUTPUT:

RESULT:

EX.NO: THREADS AIM:

DATE:

To develop the single threaded program that contains the CPU intensive computation loop. PROCEDURE: Step 1: File->new->MFC Appwizard(exe) & click SDI application then finish button. Step 2: Open the resource view dialog folder, right click & choose insert dialog. Step 3: Design the dialog with start ,cancel button & progress bar with the id ID_START,ID_CANCEL & ID_PROGRESS1 respectively.

Step 4: Choose view->classwizard,select create a new dialog then give the name as compute & click ok button. Step 5: Select class name-> compute,object ID is compute, messages-WM_TIMER then click add function.

Step 6: select object id->ID_START,messages->BN_CLICKED then click add function and also add function to ID_CANCEL . finally click edit code. Step 7: select file view->header files->compute.h file. Declare the variable under class compute. Step 8: select file view->source files->projectnameview.cpp. Include header file as #include compute.h .then type coding under on draw function. Step 9: select view->class wizard , select object ID ->Cprojectnameview messages->WM_LBUTTONDOWN click add function and edit code.

CODING: Type in compute.cpp in source files void compute::OnCancel() { if(m_ncount==0) CDialog::OnCancel(); else m_ncount=nmaxcount; } void compute::OnStart() { MSG message; m_ntimer=SetTimer(1,100,NULL); ASSERT(m_ntimer!=0); GetDlgItem(ID_START)->EnableWindow(FALSE); volatile int temp; for(m_ncount=0;m_ncount<nmaxcount;m_ncount++) { for(temp=0;temp<10000;temp++) { } if(::PeekMessage(&message,NULL,0,0,PM_REMOVE)) { ::TranslateMessage(&message); ::DispatchMessage(&message); } }

CDialog::OnOK(); } void compute::OnTimer(UINT nIDEvent) { CProgressCtrl *pbar=(CProgressCtrl *)GetDlgItem(IDC_PROGRESS1); pbar->SetPos(m_ncount *100/nmaxcount); CDialog::OnTimer(nIDEvent); } Declare the variable in compute.h in header files Under class compute : public CDialog int m_ntimer; int m_ncount; enum{nmaxcount=10000}; Type in threadsview.cpp in source files void CThreadsView::OnDraw(CDC* pDC) { CThreadsDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); pDC->TextOut(0,0,"Press left mouse button); } void CThreadsView::OnLButtonDown(UINT nFlags, CPoint point) { compute dlg; dlg.DoModal(); CView::OnLButtonDown(nFlags, point); }

OUTPUT:

RESULT:

EX.NO:

DATE:

DOCUMENT VIEW ARCHITECTURE, SERIALIZATION AIM: To develop the VC++ program for document view architecture with serialization. PROCEDURE: Step 1: Run VC++ APPWizard (exe) to create SDI application. Step 2: Accept all the default settings and select the document view architecture and deselect the printing and print preview by accepting all the default settings. Step 3: Declare the string data members in viewdoc.h file CString str data. Step 4: Edit the serialize() function to viewdoc.cpp. Step 5: Use the class wizard to connect the WM_CHAR() message handler in viewview.cpp Step 6: Build the program.

CODING:

void CDocDoc::Serialize(CArchive& ar) { if (ar.IsStoring()) { ar<<StrData; } else { ar>>StrData; } }

void CDocView::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags) {

CDocDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); pDoc->StrData+=nChar; Invalidate(); pDoc->SetModifiedFlag(); CView::OnChar(nChar, nRepCnt, nFlags); } void CDocView::OnDraw(CDC* pDC) { CDocDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); pDC->TextOut(0,0,pDoc->StrData); }

OUTPUT:

RESULT:

EX.NO: DYNAMIC CONTROLS AIM:

DATE:

To create simple object COM with the function to display the string and to check the functionality of COM using Visual Basic. PROCEDURE: Step 1: Start the program. Step 2: File> New>Projects> ATLCOM AppWizard and give the file name. Step 3: Accept all the default settings and click DLL and click finish. Step 4: Click the class file and right click and select new ATL object.select simple object in the ATL Object Wizard and click next.Then fill the ATL object wizard names,attributes and click ok. Step 5: Right click the project class workspace to add a method. Step 6: Then fill the method name add and attributes as [in] long a, [in] long b,[out] long *d and click ok. Step 7: Then right click the method add[long a,long b] and write the code. Step 8: Then save the project and just compile the code without executing and COM now created successfully. Step 9: Now test COM using Visual Basic and open the visual basic and create a new standard EXE project. Step 10: Design a form with one button as ADD. Click project menu. Step 11: Select References Click Browse and select the COM project and select library file COM.Liband click ok write code for the command button. Step 12: Save and Run the project. Step 13: Stop the program.

CODING: #include "stdafx.h" #include "com.h" #include "TEST_ATL.h"

STDMETHODIMP CTEST_ATL::add(long a, long b, long *d) { *d=a+b; return S_OK; }

FORM: Private Sub Command1_Click() Dim c As COMLib.TEST_ATL Set c = New TEST_ATL Dim x As Long c.Add 20, 50, x MsgBox ("20,50=" & x) End Sub

OUTPUT:

RESULT:

EX.NO:

DATE: MENU, ACCELERATOR, TOOLBAR AND TOOLTIP

AIM: To draw Line, Rectangle using Toolbar and Menu bar. PROCEDURE: Step 1: Start the Program. Step 2: Create the New project by selecting File->New->MFCAppWizard (exe) and type Filename. Step 3: Choose single document option and click finish. Step 4: From the Resource Tab select Menu->IDR_MAINFRAME then double click. Step 5: select the Empty field and then right click choose properties type draw in the caption field. Step 6: Same procedure for line, type line in caption. ID_DRAW_LINE in ID and ctrl+l in prompt. Step 7: From the tool bar select IDR_MAINFRAME, select any tool and draw it in the graph. Then press enter, choose ID_DRAW_LINE in ID. Step 8: Select properties in the dialog box type ID_DRAW_LINE in ID and type l in next box. Step 9: From File view, select source file->toolview.cpp, and right click in the code area and select class wizard select ID_DRAW_LINE from object IDs, and select command in messages and click add function then edit the code . Step 10: Press Ctrl +f5 for compile and press ctrl +f7 for execute. Step 11: Stop the program.

CODING: void CMenuView::OnDrawLine() { CClientDC dc(this); dc.LineTo (100,300); } void CMenuView::OnDrawEllipse() { CClientDC dc(this); dc.Ellipse (100,50,50,100); } void CMenuView::OnDrawRectangle() { CClientDC dc(this); dc.Rectangle (100,100,200,200); }

OUTPUT:

RESULT:

EX.NO: CREATING DLLs AND USING THEM AIM:

DATE:

To write a VC++ program for implementing Dynamic Link Libraries. PROCEDURE Step1: Run application wizard(dll) and create a project named Framer select Regular DLL using shared MFC DLL in step2 dialogbox then click finish. Step2: Edit the Framer.h header file. Add the prototype for function DateAndTime. Step3: Edit the Framer.cpp file, code the DateAndTime function. Step4: Build the Framer.cpp file code and copy Framer.dll to windows/system directory Or windows/system32 directory. Step5: Copy the Framer.lib file to the sub directory of the application that will use dll. Step6: Run Application wizard(exe) and create an application dlldemo. Select SDI and shared dll option in step5 dialog box & click finish. Step7: Edit dlldemoView.h and dlldemoView.cpp file to call the dll. Step8: Choose project->settings->link. Give the pathname of library in object/module link option. Step9: Build and run the dlldemo application.

CODING: Framer.h #include "resource.h" __declspec(dllexport)void WINAPI DateAndTime();

Framer.cpp __declspec(dllexport)void WINAPI DateAndTime() { AFX_MANAGE_STATE(AfxGetStaticModuleState()); struct tm* date_time; time_t timer; time(&timer); date_time=localtime(&timer); const CString& strtime = asctime(date_time); AfxMessageBox(strtime,MB_OK,0); }

dlldemoView.h //prototype declaration extern void WINAPI DateAndTime();

dlldemoView.cpp void CDlldemoView::OnDraw(CDC* pDC) { pDC->TextOut(280,100,"send text to window",23); DateAndTime(); }

OUTPUT:

RESULT:

EX.NO: DATA ACCESS THROUGH ODBC AIM: To create an ODBC connectivity for the Database using VC++. PROCEDURE: Step1: Start the program.

DATE:

Step2: Create the database name as student details.mdb using MSAccess with field Name, Regno,Mark1,Mark2,Mark3,Total. Step3: To create a ODBC Connection Start>Control Panel>ODBC. Choose User DSN tab from the ODBC Data Source. Step4: Click the add Button select MS ACCESS driver (*.mdb) from the created new data source dialog box. Step5: Enter the Data Source Name and description as ODBCD Microsoft Access setup and assign newly created (student details.mdb) to the ODBC.Then click ok. Step6: Creation of front end application in VC++ , Step7: Select file>projects>MFCAppWizard (.exe) and give the project name as student and select SDI. Step18: Select The Option Data Base view with file support and select the data source name we have created and the table name under Ms Access using Data Source Button. Step9: Select Dynaset option from the Record set then click Finish. Step10: Add the controls using Toolbox and in class wizard assign the record field name as the Member variable to the controls.

Step11: Add the Message handler member function to the control and click edit code. Step12: Then save and press ctrl+f5 to compile and press Ctrl+f7 to execute. Step13: Stop the program.

CODING: void COdbcd1View::OnAddvalue() { SetDlgItemInt(IDC_regno,0); SetDlgItemText(IDC_name," "); SetDlgItemInt(IDC_m1,0); SetDlgItemInt(IDC_m2,0); SetDlgItemInt(IDC_m3,0); SetDlgItemInt(IDC_total,0); } void COdbcd1View::OnCalculate() { UpdateData(true); m_pSet->m_Total =m_pSet->m_M1 +m_pSet->m_M2 +m_pSet->m_M3 ; UpdateData(false); } void COdbcd1View::OnSave() { m_pSet->AddNew (); UpdateData(true); if(m_pSet->CanUpdate ()) { m_pSet->Update();

MessageBox("Records Added"); } if(m_pSet->IsEOF ()) { m_pSet->MoveLast(); UpdateData(false); } } void COdbcd1View::OnUpdate() { m_pSet->Edit (); UpdateData(true); if(m_pSet->CanUpdate ()) { m_pSet->Update (); MessageBox("Records Updated"); } }

void COdbcd1View::OnDelete() { int f; try

{ f=MessageBox("Are u Sure ","Delete",MB_OKCANCEL); if(f=IDOK) { m_pSet->Delete (); MessageBox("records Deleted"); } } catch(CDBException *e) { MessageBox(e->m_strError ); e->Delete (); } m_pSet->MoveNext (); UpdateData(true); }

OUTPUT:

RESULT:

EX.NO: ACTIVEX CONTROL AIM:

DATE:

To install the Activex Control into our application and perform the Calendar Control. PROCEDURE: Step1: Run VC++ AppWizard(EXE) to create an SDI application:Accept all the default settings and select the document view architecture and click finish to design the project. Step2: Select the ActiveXcontrols in the AppWizard Step3 dialog,make sure the activeX Controls option is selected. Step 3: Now we have to insert the ActiveXControls into our project.Choose add to Project from Visual C++s Project menu and then choose components and Controls. Step 4: Choose Registered ActiveXControls and then choose Calendar Control8.0. Step 5: Use the dialog editor to create a new dialog resource.Choose Resource from Visual C++s Insert menu, and then choose Dialog and create the dialog. Step 6: Change the id of the newly created dialog as IDD_ACTIVEXDIALOG and also change the dialog caption to ActiveXDialog. Accept the default OK and Cancel buttons with the IDs IDOK and IDCANCEL. Step 7 Modify the id of all the controls in the dialog box. Add the id of the controls in the dialog.

CONTROL Calendar control Select Date Edit Control Edit Control Edit Control

ID IDC_CALENDER1 IDC_SELECTDATE IDC_DAY IDC_MONTH IDC_YEAR

Step 8: Use ClassWizard to create the CActiveXDialog class for the newly created Dialog box. Select class wizard from the view menu and press ok to create new dialog class as CActiveXDialog. Step 9: Click on the ClassWizard Message Maps tab and then add the message handler functions. ObjectID CActiveXDialog IDC_CALENDAR1 IDC_SELECTDATE IDC_NEXTWEEK IDOK Messages WM_INITDIALOG New Month BN_CLICKE BN_CLICKED BN_CLICKED Member Function OnInitDialog OnNewMonth OnSelectDate OnNextWeek OnOk

Step 10: Use ClassWizard to add data members to the CActiveXDialog class.Add the datamembers in the CActiveDialog class. Step 11: Edit the ActiveXDialog the file and add the m_varValue and m_BackColor data members. COleVariant m_varValue; unsigned long m_BackColor;

Step 12: Initialize the m_BackColor value in ActiveDialog.h. Step 13: Edit the message handling functions OnInitDialog,onn new Month Calendar1,OnSelectDate,OnNextWeek and OnOK in Active Dialog.cpp file. Step 14: Add the message handler for the view class for displaying the dialog box on the view window when the user presses the left mouse button. Use ClassWizard to map the WM_LBUTTONDOWN message and then edit the handler function. Step 15: Edit the virtual OnDraw function and include the file #includeActiveXDialog.h in the file ActiveXControlsView.cpp. Step 16: Build the application and run the project so that the following window appears after we press the left mouse button on the view window and then give the values of day, month and year inside the edit box and then click the select date button so that it is selected in the calendar control.

CODING: Activexdialog.h // Dialog Data

//{{AFX_DATA(CActivexDialog) enum { IDD = IDD_ACTIVEXDIALOG }; CCalendar m_calender; short short short m_sDAY; m_sMONTH; m_sYEAR;

//}}AFX_DATA COleVariant m_varValue; unsigned long m_BackColor;

// CActivexDialog

ActivexD ialog .cpp

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; } BOOL CActivexDialog::OnInitDialog() { CDialog::OnInitDialog(); m_calender.SetValue (m_varValue); return TRUE; }

void CActivexDialog::OnNewMonthCalendar1() {

AfxMessageBox("EVENT:ActiveXDialog::OnNewMonthCalender1"); }

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_calender.SetDay (m_sDAY); m_calender.SetMonth(m_sMONTH); m_calender.SetYear(m_sYEAR);

} void CActivexDialog::OnNextweek() { m_calender.NextWeek (); } void CActivexDialog::OnOK() { CDialog::OnOK(); m_varValue=m_calender.GetValue (); }

ACTIVEXCONTROLVIEW.CPP #include "ActiveXDialog.h" // CActivexControlView message handlers void CActivexControlView::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")); } } // CActivexControlView drawing void CActivexControlView::OnDraw(CDC* pDC) { CActivexControlDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); pDC->TextOut (0,0,"Press the Left Mouse Button Here"); }

OUTPUT:

RESULT:

Você também pode gostar