1. Department of Computer Applications
Lab Manual
MC1755 – Visual Programming
(IV Semester)
Prepared by:
Ms. V.Kayathri
Ms. N.M. Kavitha & Ms.G.Padmavathy
(Lect. / MCA) (Lect. / MCA)
RAJALAKSHMI ENGINEERING COLLEGE
Rajalakshmi Nagar, Thandalam, Chennai – 602 105
1
2. List of Lab Exercises
Sl.
No.
Exercise Page No.
1. Window Creation
2. Message Map Functions
3. Graphical Device Interface
4. Single Document Interface
5. Multiple Document Interface
6. Toolbar Creation
7. Status bar Creation
8. Menu bar Creation
9. Modal Dialog Box Creation
10. Modeless Dialog Box Creation
11. Model Dialog Box creation – Student Details
12. Dynamic Controls
13. SDI Serialization
14. MDI serialization
15. ODBC connectivity
16. Dynamic Link Library
17. Document View Architecture
2
3. Ex.No: 1
Window Creation
Date :
Aim:
To write a Visual C++ program for creating a window using win32 application.
Logical Description:
The program starts with object creation. After initializing the instance, the user
created window is assigned as main window. Using Show window option project user
created window.
Algorithm:
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
Source Code:
#include<afxwin.h>
class mywnd : public CFrameWnd
{
public:
mywnd()
{
Create(0, "My window");
}
};
class myapp: public CWinApp
{
public :
BOOL InitInstance()
{
mywnd *p;
p = new mywnd;
m_pMainWnd = p ; // main thread
3
5. Ex.No: 2
Message Map Functions
Date :
Aim:
To write a Visual C++ program which uses message map functions using win32
application.
Logical Description:
The program starts with object creation. After initializing the instance, the user
created window is assigned as main window. Using Show window option project user
created window. Using message map option draw circles when ever mouse moves on the
client area.
Algorithm:
1. Start the Process
2. Create an object for a myapp class. Invoke InitInstance function and create object
for mywin to call the constructor mywin.
3. A window is created by calling the create function which resides inside the
constructor
4. Inside message map write the code for draw circle inside the view window.
5. Show the created window using SW_SHOWNORMAL
6. Stop the process
Source Code:
#include<afxwin.h>
class mywin :public CFrameWnd
{
public:
mywin()
{
Create(0,"MFC");
}
DECLARE_MESSAGE_MAP()
void OnMouseMove(UINT f,CPoint p)
{
CClientDC dc(this);
5
7. Ex.No: 3
Graphical Device Interface
Date :
Aim:
To write a Visual C++ program which uses the GDI tools
Logical Description:
The program starts with object creation. After initializing the instance, the user
created window is assigned as main window. Using Show window option project user
created window. Using message map create a pen & brush. Using that pen & brush draw
objects.
Algorithm:
1. Start the Process
2. Create an object for an myapp class. Invoke InitInstance function and create
object for mywin to call the constructor mywin.
3. A window is created by calling the create function which resides inside the
constructor
4. Inside message map write the code for GDI objects like pen & brush .
5. Show the created window using SW_SHOWNORMAL
6. Stop the process
Source Code:
#include <afxwin.h>
class mywnd : public CFrameWnd
{
public:
mywnd()
{
Create(0,"MFC");
}
DECLARE_MESSAGE_MAP()
void OnLButtonDown(UINT f,CPoint p)
{
CPen pen;
CBrush brush;
7
10. Ex.No: 4
Single Document Interface
Date :
Aim:
To create a SDI (Application Wizard) and to draw an ellipse inside the view
window using Device Context.
Logical Description:
Using wizards create a single document interface
Algorithm:
1. File – New – Projects tab – MFC Appwizard (exe) – Give the location
name and the project name – ok
2. Select single Document option.
3. Accept the defaults in the next four screens.
4. Click the finish button – ok button.
[ProgramnameView.cpp and ProgramnameView.h files define the
CprogramnameView class, which is central to the application ]
5. In the .cpp file , write the following code in the OnDraw function
void CprogramnameView :: OnDraw(CDC *pDC)
PDC TextOut(0,0, “Hello World “);
PDC SelectStockObject(GRAY_BRUSH);
PDC Ellipse(CRect(0,20,100,120));
These 3 are the member functions of the application framework’s device context
class CDC.
6. Build and execute the Application.
Source Code:
// sdiView.cpp : implementation of the CSdiView class
//
#include "stdafx.h"
#include "sdi.h"
10
11. #include "sdiDoc.h"
#include "sdiView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CSdiView
IMPLEMENT_DYNCREATE(CSdiView, CView)
BEGIN_MESSAGE_MAP(CSdiView, CView)
//{{AFX_MSG_MAP(CSdiView)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CSdiView construction/destruction
CSdiView::CSdiView()
{
// TODO: add construction code here
}
CSdiView::~CSdiView()
{
}
BOOL CSdiView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
11
14. Ex.No: 5
Multiple Document Interface
Date :
Aim:
To create a MDI (Application Wizard) and to draw an ellipse inside the view
window using Device Context.
Logical Description:
Using wizards create a multiple document interface
Algorithm:
1. File – New – Projects tab – MFC Appwizard (exe) – Give the location name and
the project name – ok
2. Select Multiple Document option.
3. Accept the defaults in the next four screens.
4. Click the finish button – ok button.
[ProgramnameView.cpp and ProgramnameView.h files define the
CprogramnameView class, which is central to the application ]
5. In the .cpp file , write the following code in the OnDraw function
void CprogramnameView :: OnDraw(CDC *pDC)
PDC TextOut(0,0, “Hello World “);
PDC SelectStockObject(GRAY_BRUSH);
PDC Ellipse(CRect(0,20,100,120));
These 3 are the member functions of the application framework’s device context
class CDC.
6. Build and execute the Application.
Source Code:
// mdiView.cpp : implementation of the CMdiView class
#include "stdafx.h"
#include "mdi.h"
#include "mdiDoc.h"
14
15. #include "mdiView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMdiView
IMPLEMENT_DYNCREATE(CMdiView, CView)
BEGIN_MESSAGE_MAP(CMdiView, CView)
//{{AFX_MSG_MAP(CMdiView)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMdiView construction/destruction
CMdiView::CMdiView()
{
// TODO: add construction code here
}
CMdiView::~CMdiView()
{
}
BOOL CMdiView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CMdiView drawing
15
18. Ex.No: 6
Tool bar Creation
Date :
Aim:
To write a VC++ program to create a toolbar which displays different shapes
when the buttons are clicked from tool bar.
Logical Description:
The program starts with object creation. After initializing the instance, the user
created window is assigned as main window. Using Show window option project user
created window. Using resources option create a toolbar & attach it to the user created
window.
Algorithm:
1. Start the process
2. Create 4 buttons for displaying circle, rectangle, square and exit by inserting
resources and saving them with their respective names.
3. Create 4 functions to its corresponding IDs draw
4. Map these 4 functions to its corresponding IDs.
5. Create a tool bar tab from its base class CToolBar in a function names
OnCreate().
6. Allocate memory space for toolbar
7. Load the tool bar and create it using the functions load toolbar and enable
docking.
8. Set the style of the toolbar by using SetBarStyle functions
9. Stop the process
Source Code:
#include<afxwin.h>
#include<afxext.h>
#include "resource.h"
class mywin:public CFrameWnd
{
public:
18
21. Ex.No: 7
Status bar Creation
Date :
Aim:
To write a VC++ program to create a window which contains status bar
Logical Description:
The program starts with object creation. After initializing the instance, the user
created window is assigned as main window. Using Show window option project user
created window. Using resources option create a statusbar & attach it to the user created
window.
Algorithm:
1. Start the process
2. Initially control starts from object creation
3. Then it calls the myapp class which has the main function is which constructor is
invoked using the pointer variable.
4. Constructor mywin then creates the window
5. After the DECLARE_MESSAGE_MAP macro, specify the codeing for message
handlers. OnMyRect(), OnMysquare(), OnMyCircle() and OnMyExit().
6. In the OnCreate message handler, specify the status bar base class, create an
instance of it and use the instance of it and use the instance to create the status bar
7. Next define the messages corresponding to the message handlers defines above
then assign the user created window as the main window and project the same
using show window
8. Finally when the user moves the mouse on the options corresponding message
appears on status bar and on selection of the option, the corresponding figure is
displayed
9. Stop the process
21
22. Source Code:
#include<afxwin.h>
#include<afxext.h>
#include"resource.h"
class mywin : public CFrameWnd
{
public :
mywin()
{
Create(0,"MFC",WS_OVERLAPPEDWINDOW,
CRect(100,100,600,500),0,
MAKEINTRESOURCE(IDR_MENU1));
}
DECLARE_MESSAGE_MAP()
int OnCreate(LPCREATESTRUCT lp)
{
UINT panes[] = {0,0,ID_INDICATOR_CAPS,
ID_INDICATOR_NUM,ID_INDICATOR_SCRL};
CStatusBar *sb;
sb = new CStatusBar();
sb->Create(this);
sb->SetIndicators(panes,5);
return 0;
}
void OnMyExit()
{
PostQuitMessage(0);
}
};
BEGIN_MESSAGE_MAP(mywin,CFrameWnd)
ON_COMMAND(ID_EXIT,OnMyExit)
ON_WM_CREATE()
END_MESSAGE_MAP()
class myapp : public CWinApp
{
public:
BOOL InitInstance()
{
mywin *p;
p = new mywin();
22
24. Ex.No: 8
Menu bar creation
Date :
Aim:
To write a VC++ program to create a menu bar which displays when the menu
items are selected from the menu bar
Logical Description:
The program starts with object creation. After initializing the instance, the user
created window is assigned as main window. Using Show window option project user
created window. Using resources option create a menu bar & attach it to the user created
window.
Algorithm:
1. Start the process
2. Create a tool bar tab from its base class CToolbar in a function name OnCreate().
3. Create 4 buttons for displaying circle, rectangle, square and exit by inserting
resources and saving them with their respective names
4. Create 4 functions to its corresponding IDs draw
5. Map these 4 functions to its corresponding IDs
6. Allocate memory space for tool bar
7. Load the tool bar and create it using the functions load tool bar and enable
docking
8. Set the style of the tool bar by using SetBarStyle function
9. After the DECLARE_MESSAGE_MAP macro, specify the coding for message
handlers. OnRect(), OnSquare(), OnCircle() and OnExit()
10. Load the tool bar
11. Stop the process
24
25. Source Code:
#include<afxwin.h>
#include"resource.h"
class myframe:public CFrameWnd
{
public:
int u,u1,u2,u3;
COLORREF b;
myframe()
{
Create(0,"DRAWINGS",WS_OVERLAPPED |
WS_SYSMENU,CRect(0,0,500,500),0,MAKEINTRESOURCE(IDR_MENU1));
}
void OnPaint();
void Rectangle()
{
u =1;
Invalidate();
}
void Circle()
{
u =2;
Invalidate();
}
void Ellipse()
{
u =3;
Invalidate();
}
void Square()
{
u =4;
Invalidate();
}
void Line()
{
u =5;
Invalidate();
}
void Solid()
{
u2 =1;
Invalidate();
}
void Dash()
25
30. Ex.No: 9
Modal Dialog box Creation
Date :
Aim:
To write a VC++ program for creating a modal dialog box
Logical Description:
The program starts with object creation. After initializing the instance, the user
created window is assigned as main window. Using Show window option project user
created window. Using resources option create a Modal dialog box & attach it to the user
created window.
Algorithm:
1. Start the process
2. Initially control starts from object creation
3. Create a dialog box of type modal
4. using IDD_DIALOG1 crate a new dialog box and add the items in it
5. Type cast te allocated memory obtained using GetDlgItem() function into CListBox
and assign it to lb which is of type CListBox
6. Add the data given in the edit box IDC_EDIT1 into the listbox IDC_LIST1 using a
user created add function
7. Remove the data given in the list box IDC_LIST1 by clicking remove button
which is actually a user defined function
8. Stop the process
Source Code:
#include<afxwin.h>
#include<afxdlgs.h>
#include "resource.h"
class mydlg:public CDialog
{
private:
CListBox *lb;
public:
30
34. Ex.No: 10
Modeless Dialog box Creation
Date :
Aim:
To write a VC++ program to display the text on modeless dialog box
Logical Description:
The program starts with object creation. After initializing the instance, the user
created window is assigned as main window. Using Show window option project user
created window. Using resources option create a Modeless dialog box & attach it to the
user created window.
Algorithm:
1. Start the process
2. Create a dialog box using IDD_DIALOG1 and add the items in it
3. The creation of the dialog box can be done with the help of CDialog creating
an instance to it.
4. Allocate memory to the created instance
5. Call the create method (creation of instance) on the event RButtonDown
6. Stop the process
Source Code:
#include<afxwin.h>
#include<afxdlgs.h>
#include "resource.h"
class mydlg:public CDialog
{
public:
mydlg():CDialog()
{
}
public:
BOOL OnInitDialog()
34
37. Ex.No: 11
Modal Dialog box Creation – Student Details
Date :
Aim:
To write a VC++ program to display the text on modeless dialog box
Logical Description:
The program starts with object creation. After initializing the instance, the user
created window is assigned as main window. Using Show window option project user
created window. Using resources option create a Modeless dialog box & attach it to the
user created window.
Algorithm:
1. Start the process
2. Create a dialog box using IDD_DIALOG1 and add the items in it
3. The creation of the dialog box can be done with the help of CDialog creating
an instance to it.
4. Allocate memory to the created instance
5. Call the create method (creation of instance) on the event RButtonDown
6. Stop the process
Source Code:
#include<afxwin.h>
#include<afxdlgs.h>
#include”resource.h”
class mydialog::public CDialog
{
public:
mydialog():CDialog(IDD_DIALOG1)
{ }
BOOL OnInitDialog()
{
SetDlgItemText(IDC_EDIT1, “”);
SetDlgItemText(IDC_EDIT2, “”);
CheckRadioButton(IDC_RADIO1,IDC_RADIO2,IDC_RADIO3);
CheckDlgButton(IDC_CHECK1,0);
37
41. Ex.No: 12
Dynamic Controls
Date :
Aim:
To write a VC++ program to implement the dynamic controls
Logical Description:
The program starts with object creation. After initializing the instance, the user
created window is assigned as main window. Using Show window option project user
created window. Using message mapping create dynamically controls such as label, edit
box and button
Algorithm:
1. Start the process
2. Initially control starts from object creation
3. Next it calls the myapp class which in turn calls the constructor
4. The constructor creates an Output:window
5. Create name, address, phone and password using WS_VISIBLE, WS_CHILD
& SS_CENTREIMAGE.
6. Define respective message maps for the corresponding functions.
7. Execute the program
8. Stop the process
Source Code:
#include<afxwin.h>
#include<ctype.h>
#define EDIT_NUM 100
#define BUT_OK 103
class myedit:public CEdit
{
public:
void OnChar(UINT nChar,UINT nRepCnt,UINT nFlags)
{
if(isdigit(nChar))
CEdit::OnChar(nChar,nRepCnt,nFlags);
else
::MessageBeep(0);
41
44. Ex.No: 13
SDI Serialization
Date :
Aim:
To write a VC++ program to implement SDI Serialization
Logical Description:
Process of saving and restoring objects is called serialization. Implement
serialization for SDI applications
Algorithm:
1. Start the process
2. Create an object for myapp and invoke a method InitInstance( ) which calls
mywin( ).
3. Write a method to write into a file: OnWrite( ) in mywin class.
4. Write a method to read from a file : OnRead ( ) in the class mywin.
5. Map these methods to the members created.
6. Stop the process
Source Code:
// sdiDoc.cpp : implementation of the CSdiDoc class
#include "stdafx.h"
#include "sdi.h"
#include "sdiDoc.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CSdiDoc
IMPLEMENT_DYNCREATE(CSdiDoc, CDocument)
BEGIN_MESSAGE_MAP(CSdiDoc, CDocument)
//{{AFX_MSG_MAP(CSdiDoc)
44
45. // NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CSdiDoc construction/destruction
CSdiDoc::CSdiDoc()
{
// TODO: add one-time construction code here
}
CSdiDoc::~CSdiDoc()
{
}
BOOL CSdiDoc::OnNewDocument()
{
if (!CDocument::OnNewDocument())
return FALSE;
dx=50;
dy=50;
// TODO: add reinitialization code here
// (SDI documents will reuse this document)
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// CSdiDoc serialization
void CSdiDoc::Serialize(CArchive& ar)
{
if (ar.IsStoring())
{
// TODO: add storing code here
ar<<dx<<dy;
//ar>>dx>>dy;
}
else
{
// TODO: add loading code here
//ar<<dx<<dy;
ar>>dx>>dy;
}
}
/////////////////////////////////////////////////////////////////////////////
// CSdiDoc diagnostics
#ifdef _DEBUG
void CSdiDoc::AssertValid() const
45
47. Ex.No: 14
MDI Serialization
Date :
Aim:
To write a VC++ program to implement MDI serialization
Logical Description:
Process of saving and restoring objects is called serialization. Implement
serialization for MDI applications
Algorithm:
1. Start the process
2. Select MFC appwizard (Exe) and select multiple document in that.
3. Give next for further steps and finally click finish button
4. Create menu for read and write
5. For both read and write go to the class wizard, select command in that and write
the required codings
6. The document file will be available in the local space where we have started.
7. Execute the program
8. Stop the process
Source Code:
// serializationmdiView.cpp : implementation of the CSerializationmdiView class
#include "stdafx.h"
#include "serializationmdi.h"
#include "serializationmdiDoc.h"
#include "serializationmdiView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CSerializationmdiView
47
48. IMPLEMENT_DYNCREATE(CSerializationmdiView, CView)
BEGIN_MESSAGE_MAP(CSerializationmdiView, CView)
//{{AFX_MSG_MAP(CSerializationmdiView)
ON_COMMAND(ID_WRITE, OnWrite)
ON_COMMAND(ID_READ, OnRead)
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CSerializationmdiView construction/destruction
CSerializationmdiView::CSerializationmdiView()
{
// TODO: add construction code here
}
CSerializationmdiView::~CSerializationmdiView()
{
}
BOOL CSerializationmdiView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CSerializationmdiView drawing
void CSerializationmdiView::OnDraw(CDC* pDC)
{
CSerializationmdiDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
}
/////////////////////////////////////////////////////////////////////////////
// CSerializationmdiView printing
BOOL CSerializationmdiView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CSerializationmdiView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
48
51. Ex.No: 15
ODBC Connectivity
Date :
Aim:
To Write a VC++ program that implements database connectivity
Logical Description:
Implementing ODBC connectivity for a SDI application
Algorithm:
1. Create a database and table in MSAccess.
Goto MSACCESS,
File->New->Blank database->Give database name(Students details)
Inside that database create a table named stud with fields Roll no and
Name.
Enter details for some five records ,save and exit.
2. Creating a DSN
Goto Control Panel->click Data sources(ODBC)
Click user DSN tab
Click the Add button
Double click Driver Do Microsoft Access(*.mdb)
Give data source name as DSN1
Select database(the location where u have stored ur students details
database)
Click ok
Now the DSN is created.
3. Run Appwizard(EXE) to create a SDI project named stud.
Select Header files only option in step 2.
Set CScrollView as class type in step 6.
4. Use class wizard
Choose Add class->New->give class name(CStudSet) and set base
class name as CRecordSet.
Click ok,it will show a Database options dialog box.
In that select the DSN name and click Recordset type as dynaset,click
ok.
51
52. It will ask u to select the table,select the table name stud,click ok.
5. Add the member variable to the class CstudDoc
CStudSet m_studSet;
6. Edit the studDoc.cpp file
Add the line #include “studSet.h” before the line #include “studDoc.h”.
7. Add the following private data member to the CstudView class.
CStudSet* m_pSet;
8. Edit the OnDraw and OnInitialUpdate functions in studView.cpp.
void CStudView::OnDraw(CDC* pDC)
{
TEXTMETRIC tm;
pDC->GetTextMetrics(&tm);
int nLineHeight=tm.tmHeight+tm.tmExternalLeading;
CPoint pText(0,0);
int y=0;
CString str;
if(m_pSet->IsBOF())
return;
m_pSet->MoveFirst();
while(!m_pSet->IsEOF()){
str.Format("%ld",m_pSet->m_Roll);
pDC->TextOut(pText.x,pText.y,str);
pDC->TextOut(pText.x+1000,pText.y,m_pSet->m_Name);
m_pSet->MoveNext();
pText.y-=nLineHeight;
}
}
void CStudView::OnInitialUpdate()
{
CScrollView::OnInitialUpdate();
CSize sizeTotal(8000,10500);
// TODO: calculate the total size of this view
SetScrollSizes(MM_HIENGLISH, sizeTotal);
m_pSet=&GetDocument()->m_studSet;
if(m_pSet->IsOpen())
m_pSet->Close();
m_pSet->Open();
}
52
53. Add the #include “studSet.h” before the line #include “studDoc.h”
9. Edit the stud.cpp file
Add #include “studSet.h” before the line #include “studDoc.h”
10. Build and run the application.
Output:
53
54. Ex.No: 16
Dynamic Link Library
Date :
Aim:
To calculate the simple interest using Dynamic Link Library (DLL).
Logical Description:
Dynamic Link Libraries(DLL):
A DLL is a collection of small programs, any of which can be called when
needed by a large program that is running in the computer
The advantage of DLL files is that, because they do not get loaded into RAM
together with the main program, space is saved in RAM. When and if a DLL file
is needed, then it is loaded and run.
Examples As long as a user of MsWord is editing a document, the printer DLL
file does not need to be loaded into RAM.
If the user decides to print the document, then the word application causes the
printer DLL file to be loaded and run.
A DLL file is often given a “.DLL” file name .DLL files are dynamically linked
with the program that uses them during program execution rather then being
complied with the main program.
Algorithm:
1. Create a dynamic link library
2. Create the Client Program
3. Go to project ->settings->link tab->object/library modules->C:vc++dmDebug
dm.lib(Type the above said path)
4. Now copy the .DLL file which has been created in the C:vc++dmDebug to the
client program in the path C:vc++dc.
5. Compile the Client Application and run the application. Click on the calculate
button to view the result in the last edit control.
Source Code:
54
55. MYClass.cpp
Float CMYClass :: interest(float p, float n, float r)
{
return(p*n*r/100);
}
dcDlg.h
#include ”c:vc++dmMyClass.h”
public:
CMyClass objclass;
Include the following lines in dcDlg.cpp
void dcDlg::OnButton1() {
UpdateData(true)
m_res=objclass.interest(m_p,m_n,m_r);
UpdateData(false);
}
void dcDlg::On Button2() {
PostQuitMessage(0);
}
Output:
55
56. Ex.No: 17
Document / View Architecture
Date :
Aim:
To write a VC++ program to implements Document / View architecture
Logical Description:
Implementing Document / View Architecture for SDI applications and creating
some drawing objects
Algorithm:
1. Start the process
2. Create an object for myapp calss. Using he object allocate memory to the mywin
class and call the constructor.
3. mywin class inherits the properties of CFrameWnd class
4. Draw some objects using message handler
5. Execute the program
6. Stop the process
Source Code:
sdisquaresDoc.h header file
//Implementation
public:
void SetSquare(int i,int j,COLORREF color);
COLORREF GetSquare(int i,int j);
COLORREF GetCurrentColor();
Virtual ~CsdisquaresDoc();
//Generated messagemap functions
prortected:
COLORREF m_clrCurrentColor;
COLORREF m_clrGrid[4][4];
//{{AFX_MSG(CsdisquaresDoc)
afx_msg void OnColorRed();
afx_msg void OnColorGreen();
afx_msg void OnColorBlue();
afx_msg void OnColorWhite();
56