VP Lab Pgms Aim & Procedure
description
Transcript of VP Lab Pgms Aim & Procedure
1. SDK PROGRAM FOR CREATING SIMPLE WINDOW
AIM:
To write a Visual C++ program for creating a window using win32 application.
PROCEDURE:
1. Start the Process.
2. Create an object for an class which inherits CWinApp.
3. The object access InitInstance() function.
4. Create a pointer object for the class which inherits CFrameWindow by allocating the memory to
the object.
5. Show the created window using SW_SHOWNORMAL.
6. Stop the process.
2. SDK PROGRAM FOR KEYBOARD AND MOUSE EVENTS
AIM:
To write a Visual C++ application for Keyboard and Mouse Event Using SDK.{win32 application).
PROCEDURE:
1. Open VC++ to create a new project. Select win32 application in the project tab. 2. Choose new from the File Menu & Select C++ Source File and Enter the file name as Keyboard
3. Include the coding in the space provided for Keyboard.c
4. Build and Execute the Program.
3. SDK TYPE PROGRAM FOR GDI OBJECTS.
AIM:
To write a Visual C++ program using Graphical device Interface Objects in Software Development Kit.(win32 application).
PROCEDURE:
1.Create a new project by opening the Microsoft Visual VC++6.0
2.Select Win32 Application and click OK.Select an empty project and give the project
name and click finish.
3.select file new and select the source file in cpp and give the filename and ok.
4.Create a class Myframe.In public , declare the constructor myframe ( ), to create a
window.
5.In option function , create mypen , mybrush to draw different Graphical Shaphes.
6.Select the object mypen and mybrush to draw a rectangle and line.
7.Finally declare the DECLARE_MESSAGE_MAP( ) function in public.
8.Declare BEGIN_MESSAGE_MAP ( ) Function,
ON_WM_PAINT ( ) function and
END_MESSAGE_MAP ( ) function.
9.Create a class myapp
In public , declare the function
int InitInstance( )
10.Create a pointer variable *p for myframe as
myframe *p;
11.Assign the myframe( ) value to the variable p.
12.Show the window for display the rectangle and line using Pen and Brush
13.Finally create a object for myapp as
myapp s;
14.In project setting, select
MFC using Shared Library, Select ok.
15.Build and execute the project
4. SIMPLE DIALOG BASED APPLICATION FOR CALCULATOR
AIM:
To write a VC++ program using simple dialog based application for simple calculator.
PROCEDURE:
1. Create a new project using the Microsoft Visual c++ 6.0
2. Choose a file menu and select new option, MFCAppWizard[exe] and give the project name. Select a dialog-based option. Click finish, ok.
3. In dialog box, place the required controls to the dialog window. Select the System Menu and Minimise Box options.
4. Change the properties of the control.
CONTROL ID
Left operand edit control IDC_LEFT
Right operand edit control IDC_RIGHT
Result edit control IDC_RESULT
First radio button (Group property set) IDC_OPERATION
Compute push button IDC_COMPUTE
5.Use classWizard to add member variables and a command handler.Add the following data members.
CONTROL ID MEMBER VARIABLE TYPE
IDC_LEFT m_dLeft double
IDC_RIGHT m_dRight double
IDC_RESULT m_dResult double
IDC_OPERATION m_nOperation intAdd the message handler OnCompute for the IDC_COMPUTE button.
6. include the following code in the OnCompute function.
9. Build and execute the project.
5. CREATING SINGLE DOCUMENT INTERFACE APPLICATION
AIM:
To create a SDI (Application Wizard) and to draw an ellipse inside the view window using Device Context.
PROCEDURE:
1. Open VC++ to create a new project. Select the MFC AppWizard (.exe).
2. Be sure to select the Single Document Option in the 1st Screen and then accept all the default steps except in the step4.
3. In the Step4 of the MFC APPWizard Deselect the Printing and Print Preview.
4. Click the finish button and click the OK. Open the SDIView.cpp and SDIView.h files and look at the source code and modified the AppWizard generated. OnDraw () function in SDIView.cpp
5. Compile & Build the generated Code.
6. CREATING MULTIPLE DOCUMENT INTERFACE APPLICATION
AIM:
To create a MDI (Application Wizard) and to draw an ellipse inside the view window using Device Context.
PROCEDURE:
1. Create a new project by opening the Microsoft Visual C++ 6.0.
2. Choose a file menu and select a new option.
3. Select MFCAppWizard (exe) and give the project name
4. Choose a Multiple document option in the next window that appears [Default option].
5. Click Finish
6. Choose View , ClassWizard for selecting an event (WM_LBUTTONDBLCLK) and edit
the code for the function (or) Event
7. Build and Execute the project.
7. CREATING MODAL DIALOG
8. CREATING MODELESS DIALOG
AIM:
To create a vc++ program using MFC Application wizard to perform modeless process.
PROCEDURE:
1. Use AppWizard to generate a Dialog based project named modelessdia in the subdirectory
c:\vc++pgms\.
2. With Resource view pane double click on IDD_MODALESSDIALOG_DIALOG. Select
the TODO text and delete it. Similarly click Cancel button and delete it.
3. Select OK button and Right click on it. Select Properties from the context menu. In this
select General tab & Type Run the program by replacing the word OK. Similarly Select
CANCEL button and Right click on it. Select Properties from the context menu. In this
select General tab & Type Exit by replacing the word OK.
4. Place controls to the window. Select a static text control & place it on the window. Right
click on the static text to select the properties. Type the caption name as Select.
Similarly select a combo box and place it near the select and change its ID to
IDC_RUNPGM in the general tab. Select Data tab and type Calculator , Mspaint, Notepad,
Freecell, tourstart, Command prompt. (To come to next row press ctrl + enter).
5. Now select the class wizard (Ctrl+W) and add the member variable to IDC_RUNPGM.
Controls IDs Type Member
IDC_RUNPGM CString m_strRunPgm
6. Double click on the button Run the program & change its member function to OnRunPgm().
Type the following code.
7. Build and run the project.
9. PROGRAMMING FOR READING AND WRITING INTO DOCUMENTS
AIM:
To create a vc++ program using MFC Application wizard to create a serialization process.
PROCEDURE:
1. Use AppWizard to generate an MDI project named serialize in the subdirectory c:\vc++pgms\.
2. Select Insert menu and click on new class Class Type -> Generic class
Class Info -> Name – Cline
File name – Line.Cpp
Derived from CObject - public
3. Select class view and select CLine class. Add two member variables and member functions under Cline class.
Var type var name Access
CPoint startP and endP public
Function type F unction name Access
Void Draw(CDC *pDC) public
Void serialize(CArchive &ar) public
Cline(CPoint sp, CPoint ep) public
Type the Code for Cline class
4. Add 1 member variable in the doc class. Var type var name Access
CobArray Lines public
5. Add 3 member functions in the same doc class. Function type F unction name Access
Cline* AddLine(CPoint sp, CPoint ep) public
int GetLineCount() public
Cline* GetLine(int nIndex) public
Type the code for CSerializeDoc class
6. In the class wizard under view menu select message map tab. Set Object IDs as CSerializeDoc
Messages DeleteContents. Double click on it.
7. Expand the document class add deletecontent from the class wizard. Type the code.
8. Add member variable in the view class. Var Type Var Name Access
CPoint prev public
9. In the classwizard select the view class and add message handler.WM_LBUTTONDOWN
Type the code
10. In the classwizard select the view class and add message handler.WM_LBUTTONUP
Type the code
11. In the classwizard select the view class and add message handler.WM_MOUSEMOVE
Type the code
12. Add #include “Line.h” in both Doc class and view class in the header file class view.13. Build and run the project.
10. DYNAMIC CONTROL FOR SLIDER CONTROL
AIM:
To write a Visual C++ program for creating a Slider Control using win32 application.
PROCEDURE:
1. Start the Process
2. Create an object for an class which inherits CWinApp
3. The object access InitInstance() function
4. Create a pointer object for the class which inherits CFrameWindow by allocating the
memory to the object
5. Show the created window using SW_SHOWNORMAL
6. Stop the process
.
11. DYNAMIC CONTROL FOR TREE VIEW CREATION
AIM:
To write a Visual C++ program for creating a Tree View Control using win32 application.
PROCEDURE:
1. Start the Process.
2. Create an object for an class which inherits CWinApp.
3. The object access InitInstance() function.
4. Create a pointer object for the class which inherits CFrameWindow by allocating the
memory to the object.
5. Show the created window using SW_SHOWNORMAL.
6. Stop the process.
12. CREATING AND DYNAMIC SPLITTER WINDOW
AIM:
To create a Visual C++ program using MFC Application wizard to split the SDI view window.
PROCEDURE:
1. Create an SDI project. Click the Advanced button in the AppWizard Step 4 dialog. Click
on the Window Styles tab, and select Use Split Window.
2. When you check the Use Split Window check box, AppWizard adds code to your CMainFrame class.
3. The application's main frame window class needs a splitter window data member and a prototype for an overridden OnCreateClient function. Add this code to MainFrm.h file:
protected: CSplitterWnd m_wndSplitter;public: virtual BOOL OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext);
13.CREATING DLLS AND USING THEM.
AIM:
To create a simple MFC regular DLL that is statically linked to the MFC and to create client program to test the DLL with the help of application wizard IN VISUAL C++.
PROCEDURE:
To create a DLL :
1. Run AppWizard to produce F:\Visual_Program\VC++_Program\RegDLL. Choose New from Visual C++'s File menu, and then click on the Projects tab as usual. Choose MFC AppWizard (dll) and assign a project name with path. In this, only one AppWizard screen appears. Choose Regular DLL with MFC statically linked.
2. Examine the RegDLL.cpp file. AppWizard generates the following code, which includes a derived CWinApp class:
3. Add the code for the exported RegDLLFactorial function. It's okay to add this code in the RegDLL.cpp file.
4. Build the project to create DLL file.
To create a test client application :
1. Run AppWizard to produce F:\Visual_Program\VC++_Program\RegDLLTest. This is an ordinary MFC EXE program. Select Single Document. In others, accept the default settings. Be absolutely sure that in Step 5 you accept the As A Shared DLL option.
2. Add a new dialog resource and class to F:\Visual_Program\ VC++_Program\ RegDLLTest. Use the dialog editor to create the IDD_REGDLL template, as shown here.
3. Then use ClassWizard to generate a class CRegDllTestDialog, derived from CDialog. The controls, data members, and message map function are shown in the following table.
Control ID Type Data Member Message Map Function
IDC_INPUT edit m_dInput (double)
IDC_OUTPUT edit m_dOutput (double)
IDC_FACT button OnFact
2. Code the OnCompute function to call the DLL's exported function. Edit the ClassWizard-generated function in RegDLLTestDialog.cpp.
3. You'll have to declare the RegDLLFactorial function as an imported function. Add the following line to the RegDLLTestDialog.h file:
extern "C" __declspec(dllimport) long RegDLLFactorial(long f)
4. Integrate the CRegDLLTestDialog class into the RegDLLTest application. Insert a menu option named Test in the View menu using menu editor on the existing menu with the ID ID_TEST_REGDLLDLL. Use ClassWizard to map this option to a member function in the CRegDLLTestView class, and then code the handler in RegDLLTestView.cpp. Add the line in
#include "RegDLLTestDialog.h"
5. Add the REGDLL import library to the linker's input library list. Choose Settings from Visual C++'s Project menu, and then add program directory debug loation to the Object/Library Modules control on the Link page. Copy the RegDLL.dll into the EXE’s directory (i.e., F:\Visual_Program\VC++_Program\ RegDLLTest\Debug).
6. Build and test the updated RegDLLTest application. Choose Test Dll from the View menu. Type a number in the Input edit control, and then click the Factorial button. The result should appear in the Output control.
14. DATA ACCESS THROUGH ODBC – CDATABASE, CRECORDSET.
AIM:
To create a database application using CRecordview in MFC application wizard.
PROCEDURE:
1. Open Visual C++ and select New from the file menu and select MFC Appwizard(exe)
and type the project name as MyData.
2. In the step1 of the MFC application select Single Document Interface(SDI and in step2
select the database View without File support.
3. Create a database table student in Ms-access and save the file in a location.
4. In step2 dialog box,also click the Data Source button and choose the ODBC option and
select the Ms access database.Choose Dynaset as the Recordset type,then select the
database table.Finally,deselect Printing And Print Preview in step4.Now thw options and
the default class names are shown on the next step of MFC application.
5. Add the necessary controls to the dialog box IDD_MyData_FORM template. Add
properties for each controls by right clicking on the control and select properties. Type
the ID and Caption for each control.
6. Use ClassWizard to link the edit controls to the recordset data members.To add a data
member,click on the Member Variables tab and choose the ID corresponding to the edit
box for each variable.click the Add variable button,and click the arrow in the Member
variable Name combo box to display a list of variables.Select only the appropriate
variable for each control.
7. Now build and test the application.you should have a working read-only database
application .Now use the toolbar buttons to sequence through the instructor records.
8. Back Up the database.Now the logic is to be included to add,change and delete records.
9. Add the Menu Commands.Add the following items to the Record pop-up menu in the
IDR_MAINFRAME menu.Also ust the ClassWizard to map the commands to the
specified class members.
Menu Command
Command ID Command Handler UpdateCommand UI Handler
Add Record
ID_RECORD_ADD OnRecordAdd
Clear Fields
ID_RECORD_CLEAR_FEILDS OnRecordClearFields
Delete Record
ID_RECORD_DELETE OnRecordDelete OnUpdateRecordDelete
Update Record
ID_RECORD_UPDATE OnRecordUpdate OnUpdateRecordUpdate
1. Add and override the OnMove function in the CMyDataView class.The
CRecordView::OnMove function does the work of updating the database when the user
moves out of a record.Include the onmove codings .
2. Edit the menu command handlers.add the necessary codings for each buttons created.
3. Build and execute the program or Press F5.
16.CREATING ACTIVEX CONTROL AND USING IT.
AIM:
To write a VC++ program to build an application that uses a Calendar control in a dialog
using activeX.