Professional Documents
Culture Documents
VP Record Full
VP Record Full
VP Record Full
STEPS INVOLVED:
Step 2: Click File menu and select the New Project sub menu.
Step 3: Select the project types as VC++ and select MFC ->MFC
Application.
Step 4: Name the project , change the location(if needed) and Click OK.
Step 6: From the Application Type Window, select the application type as
Single document or Multiple document and select other
options, Click next.
Step 8: From the Solution Explorer on the left-hand side of the workspace,
double click the project name to select the files.
Step 10: From the Source File folder, click the drDoc.cpp file and enter the
following code,
BOOL CdrDoc::OnNewDocument()
{
if (!CDocument::OnNewDocument())
return FALSE;
str="hello";
return TRUE;
}
Step 11: From the source file folder, double click the drView.cpp file to
edit the OnDraw() function with the following code,
}
Step10: Click Save All and execute the application.
Output:
STEPS INVOLVED:
Step 2: Click File menu and select the New Project sub menu.
Step 3: Select the project types as VC++ , and select MFC ->MFC
Application.
Step 4: Name the project , change the location(if needed) and Click OK.
Step 8: From the Solution Explorer on the left-hand side of the workspace,
double click the project name.
Step 9: Double click the (project name)View.h file under Header file
folder and enter the following member variables,
m_nColor=GRAY_BRUSH;
Step 11: From the Object Browser, select the project name, choose the
view file & from the properties window, Click the messages icon to add
OnLButtonDown event into
(project name)View.cpp
else
m_nColor=GRAY_BRUSH;
Step 12: From the same file edit the OnDraw() function, with the following
code,
Step 13: Click Save All and execute, In the output, Keep the mouse
pointer into the ellipse and click the left mouse button to observe the change
of color.(The color of the ellipse changes from gray to white).
Output:
3. Program using graphical device interface objects.
GDI: Graphical Device Interface, provides device independent graphics
support. Pen & Brush are the GDI objects used in the following program.
STEPS INVOLVED:
Step 2: Click File menu and select the New Project sub menu.
Step 3: Select the project types as VC++ and select General -> Empty
Project.
Step 6: Similarly, right click the Resource files folder and add a new
menu resource. Create two menus namely, SHAPES and TOOLS.
SHAPES -> RECT, CIRCLE, LINE
TOOLS ->PEN ->THIN, THICK
SOLID, HATCH
Step 7: Add the following code into the C++ file.
#include<afxwin.h>
#include "resource.h"
class myframe:public CFrameWnd
{
public:
char shape;
int width;
char tag;
myframe()
{
Create(0,"GDI",WS_OVERLAPPEDWINDOW,rectDefault,NULL,MAKEINTRES
OURCE(IDR_MENU1));
shape='a';
width=1;
tag='s';
}
void rect()
{
shape='r';
Invalidate();
}
void circle()
{
shape='c';
Invalidate();
}
void line()
{
shape='l';
Invalidate();
}
void thin()
{
width=2;
}
void thick()
{
width=2;
}
void solid()
{
tag='s';
}
void hatch()
{
tag='h';
}
void OnPaint()
{
CPaintDC d(this);
CPen *p;
p=new CPen;
p->CreatePen(PS_SOLID,width,RGB(0,0,255));
d.SelectObject(p);
CBrush *b;
b=new CBrush;
if(tag=='s')
b->CreateSolidBrush(RGB(255,0,0));
else if(tag=='h')
b->CreateHatchBrush(HS_DIAGCROSS,RGB(0,0,255));
d.SelectObject(b);
if(shape=='r')
d.Rectangle(100,200,200,300);
else if(shape=='c')
d.Ellipse(100,200,200,300);
else if(shape=='l')
{
d.MoveTo(10,100);
d.LineTo(200,400);
}
} DECLARE_MESSAGE_MAP()
};
BEGIN_MESSAGE_MAP(myframe,CFrameWnd)
ON_COMMAND(ID_SHAPES_REC,rect)
ON_COMMAND(ID_SHAPES_CIRCLE,circle)
ON_COMMAND(ID_SHAPES_LINE,line)
ON_COMMAND(ID_TOOLS_PEN_THIN,thin)
ON_COMMAND(ID_TOOLS_PEN_THICK,thick)
ON_COMMAND(ID_TOOLS_BRUSH_SOLID,solid)
ON_COMMAND(ID_TOOLS_BRUSH_HATCH,hatch)
ON_WM_PAINT()
END_MESSAGE_MAP()
class mywin:public CWinApp
{
public:
BOOL InitInstance()
{
m_pMainWnd=new myframe();
m_pMainWnd->ShowWindow(m_nCmdShow);
m_pMainWnd->UpdateWindow();
return TRUE;
}
};mywin my;
Step 2: Click File menu and select the New Project sub menu.
Step 3: Select the project types as VC++ , and select MFC ->MFC Application.
Step 4: Name the project , change the location(if needed) and Click OK.
Step 6: From the Application Type Window, select the application type as either
Single document or Multiple document and select other options,
Click next.
Step 8: From the Solution Explorer on the left-hand side of the workspace,
double click the project name and select the Resource files folder to add a Dialog
Box resource.
Step 9: From the resource view window, Add a dialog box with the following
controls,
Step 10: From the solution explorer, right click the source file folder, add a
class and name it disp and set the base class to CDialog
(Eg: disp ) disp.cpp & disp.h files will be created in the source files folder and
header file folder.
Step11: Click the disp.h file and add the following code,
CString Name;
CString Dept;
CString Bio;
int Regno;
Name=_T(“”);
Regno=0;
Bio=_T(“”);
Dept=_T(“”);
And in the DoDataExchange() method, enter the following code,
DDX_Text(pDX,IDC_EDIT2, Regno);
DDX_Text(pDX,IDC_EDIT3, Bio);
DDX_CBString(pDX,IDC_COMBO1, Dept);
Step13: Choose View-> Object Browser-> Select the project name and
from the properties window, select the messages icon & activate the
WM_ONLBUTTONDOWN.(As done for Event handling program)
CView::OnLButtonDown(nFlags, point);
disp a;
a.Name="KUMAR";
a.Regno="101";
a.Bio="STUDENT";
a.Dept="MCA";
int r=a.DoModal();
TRACE("%d",r);
Step14: Now click the (projectname)Doc.h file, within the Public access
specifier, include,
CString str;
pDC->TextOut(50,50,pDoc->str);
4. b) Modaless Dialogbox
Modaless Dialog Box: It behaves like a conventional window, it can be reactivated
even while the dialog box is being displayed. (E.g. Find and Replace window in
word document).
STEPS INVOLVED:
Step 2: Click File menu and select the New Project sub menu.
Step 3: Select the project types as VC++ and select General -> Empty
Project.
Step 6: Similarly, right click the Resource files folder and add a new
dialogbox resource with the following controls,
#include<afxwin.h>
#include<afxext.h>
#include "resource.h"
class mydialog:public CDialog
{
public:
mydialog():CDialog(IDD_DIALOG1)
{ }
void OnOk()
{
EndDialog(TRUE);
}
void OnCancel()
{
EndDialog(TRUE);
}
void color()
{
CColorDialog a;
if(a.DoModal ()==IDOK)
{
CClientDC dc(this);
dc.SetTextColor(a.GetColor());
dc.TextOut (10,10,"Hello",5);
}
}
void save_open()
{
char *str = "AllFiles(*.*)|*.*|CFile(*.c)";
CFileDialog d(false,NULL, "*.*",0,str);
if(d.DoModal ()==IDOK)
{
CString str;
str = "fileSave in:"+d.GetPathName ();
d.GetPathName ();
MessageBox(str,"Location");
}
}
void font()
{
LOGFONT lf;
CFontDialog fd(&lf);
if(fd.DoModal()==IDOK)
{
CFont f;
f.CreateFontIndirect(&lf);
CClientDC d(this);
d.SelectObject(&f);
d.SetTextColor(fd.GetColor());
d.TextOut(10,10,"hello",5);
}
}
DECLARE_MESSAGE_MAP()
};
class myframe:public CFrameWnd
{
public:
mydialog *d1;
myframe()
{
d1=new mydialog();
d1->DoModal();
}
};
BEGIN_MESSAGE_MAP(mydialog,CDialog)
ON_BN_CLICKED(IDC_BUTTON1,color)
ON_BN_CLICKED(IDC_BUTTON2,font)
ON_BN_CLICKED(IDC_BUTTON3,save_open)
END_MESSAGE_MAP()
class mywin:public CWinApp
{
public:
BOOL InitInstance()
{
m_pMainWnd=new myframe();
m_pMainWnd->ShowWindow(4);
m_pMainWnd->UpdateWindow();
return TRUE;
}
};
mywin a;
Step 9: Save All and Execute.
Output:
5a) Program using static controls
Step 2: Click File menu and select the New Project sub menu.
Step 3: Select the project types as Visual Basic , and select Windows
->Windows Application.
Step 4: Name the project , change the location(if needed) and Click OK.
Step 5: Draw a Text Box on the form, and set the multiline property to
True.
Step 6: Add two buttons below the Text Box and customize the following
properties,
Step 7: Right click the Form1.vb and select View code to enter the
following line of code,
Step 8: Double click the “Enter the Temperatures” button and enter the
following code,
Dim i As Short
For i = 0 To UBound(Temperatures)
Step 9: Doble click the “Display Temperatures” button and add the
following code,
Dim i As Short
Result = "High Temperatures for the week: " & vbCrLf & vbCrLf
For i = 0 To UBound(Temperatures)
Result = Result * "Day " &(i + 1) & vbTab & _ Temperatures(i) &
vbCrlf
Next
Result = Result & vbCrlf & _"Average temperature: " & Format(Total /
7,"0.0")
TextBox1.Text = Result
Step 2: Click File menu and select the New Project sub menu.
Step 3: Select the project types as VC++ and select General -> Empty Project.
Step 5: From the solution explorer, right click the source file folder and create
a new C++ file.
Step 6: Click the C++ file and add the following code,
#include<afxwin.h>
#include<afxcmn.h>
class myframe:public CFrameWnd
private:
CTreeCtrl tree;
public:
myframe()
int OnCreate(LPCREATESTRUCT l)
HTREEITEM lang,os,c,cpp,java;
tree.Create(WS_VISIBLE|TVS_LINESATROOT|
TVS_HASBUTTONS|TVS_SHOWSELALWAYS,
CRect(30,30,300,350),this,1);
lang=tree.InsertItem("Proglang",TVI_ROOT,TVI_SORT);
c=tree.InsertItem("c",lang,TVI_SORT);
tree.InsertItem("tc",c);
tree.InsertItem("qc",c);
cpp=tree.InsertItem("c++",lang,TVI_SORT);
tree.InsertItem("vc++",cpp);
tree.InsertItem("borland c++",cpp);
java=tree.InsertItem("java",lang,TVI_SORT);
tree.InsertItem("vj++",java);
tree.InsertItem("sunjava",java);
os=tree.InsertItem("os",TVI_ROOT,TVI_SORT);
tree.InsertItem("XP",os);
tree.InsertItem("Fedora",os);
return 1;
HTREEITEM h;
CString str;
if(p->hdr.code==TVN_SELCHANGED)
h=tree.GetSelectedItem();
str=tree.GetItemText(h);
MessageBox(str,"selection");
return 1;
DECLARE_MESSAGE_MAP()
};
BEGIN_MESSAGE_MAP(myframe,CFrameWnd)
ON_WM_CREATE()
END_MESSAGE_MAP()
public:
BOOL InitInstance()
{ myframe *my;
my=new myframe;
my->ShowWindow(3);
m_pMainWnd=my;
return TRUE;
};
mywin a;
Output:
Step 8: In the Advanced Features window, deselect the Printing and Print
Preview option and click next until Finish.
Step 9: From the solution Explorer, Select the Header Files folder & Select the
splittDoc.h and enter the following member variable,
Public:
CString str;
Step 10: From the Source File folder, click the splittDoc.cpp file and enter the
following code,
BOOL CSplittDoc::OnNewDocument()
{
if (!CDocument::OnNewDocument())
return FALSE;
str="Splitter Window";
return TRUE;
}
Step 11: From the source file folder, click the splittview.cpp file and enter the
following code into the OnDraw() function,
void CSplittView::OnDraw(CDC* pDC)
{
CSplittDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
pDC->Ellipse(25,25,200,100);
pDC->TextOut(50,50,pDoc->str);
}
Step 12: Click Save All and Build & Execute., In the output window, Goto
View-> Split & use mouse to partition the window area.
Output:
7a). Program using Tool bar
Steps Involved:
Step 2: Click File menu and select the New Project sub menu.
Step 3: Select the project types as Visual Basic and select Windows -> Windows
Application.
Step 5: Insert Picture Box controls in to Form1.vb from the Tool Box.
Step 6: Click the Tool Strip control in the Tool box, to add it to Form1.vb
Step 7: Click over the Tool Strip control and a list down box appears in the
Form1.vb, select the Button tools (add four buttons).
Step 8: Right click the button and select the Set Image option, import the image
to be displayed as icon for the button should be selected and set the tooltip
property to New, Zoom In, Zoom Out and Close.
Step 9: Add the appropriate images and create four buttons of following style,
Step 10: Double the first button and enter the following code,
Step 11: Click the second button and enter the following code,
PictureBox1.Width = PictureBox1.Width + 10
PictureBox1.Height = PictureBox1.Height + 10
Step 12: Click the third button and enter the following code,
PictureBox1.Height = PictureBox1.Height – 10
Step 13: Click the fourth button and enter the following code,
End
Steps Involved:
Step 2: Click File menu and select the New Project sub menu.
Step 3: Select the project types as Visual Basic and select Windows -> Windows
Application.
Step 5: Add a Status bar and Button in to the form from Tool Box & set the
Text property of the button to “Caption”
Step 6: Right click the status bar and click the panel properties, add three
panels using the add button,
Step 7: Enable the show panel property to True.
StatusBarPanel2.Text = DateString
StatusBarPanel3.Text = TimeString
Step 7: Click the C++ file and add the following code,
#include<afxwin.h>
#include<afxext.h>
#include "resource.h"
class myeditview:public CEditView
{
DECLARE_DYNCREATE(myeditview)
public:
BOOL PreCreateWindow(CREATESTRUCT &cs)
{
BOOL bp=CEditView::PreCreateWindow(cs);
cs.style&=~(WS_HSCROLL);
return bp;
}
};
IMPLEMENT_DYNCREATE(myeditview,CEditView)
class mydocument:public CDocument
{
DECLARE_SERIAL(mydocument)
void Serialize(CArchive &ar)
{
myeditview *v;
v=(myeditview *)m_viewList.GetHead();
v->SerializeRaw(ar);
}
int OnNewDocument()
{
CDocument::OnNewDocument();
if(!CDocument::OnNewDocument())
return 0;
else
return 1;
}
void DeleteContents()
{
myeditview *x;
if(m_viewList.GetCount())
{
x=(myeditview *)m_viewList.GetHead();
x->SetWindowText(NULL);
}
}
};
IMPLEMENT_SERIAL(mydocument,CDocument,0)
class myapp:public CWinApp
{
BOOL InitInstance()
{
CSingleDocTemplate *d;
CRuntimeClass *f, *doc,*view;
doc=RUNTIME_CLASS(mydocument);
f=RUNTIME_CLASS(CFrameWnd);
view=RUNTIME_CLASS(myeditview);
d=new CSingleDocTemplate(IDR_MENU1,doc,f,view);
AddDocTemplate(d);
OnFileNew();
return 1;
}
DECLARE_MESSAGE_MAP()
};
BEGIN_MESSAGE_MAP(myapp,CWinApp)
ON_COMMAND(ID_FILE_NEW,CWinApp::OnFileNew)
ON_COMMAND(ID_FILE_OPEN,CWinApp::OnFileOpen)
END_MESSAGE_MAP()
myapp a;
Output:
8 b). MDI SERIALIZATION
Step 1: Start Visual Studio.
Step 2: Click File menu and select the New Project sub menu.
Step 3: Select the project types as VC++ and select General -> Empty
Project.
Step 4: Name the project and click OK.
Step 5: From the solution explorer, right click the source file folder and
create a new C++ file.
Step 6: Similarly, right click the Resource files folder and add a new
menu resource.
Step 7: Click the C++ file and add the following code,
#include<afxwin.h>
#include<afxext.h>
#include "resource.h"
class myeditview:public CEditView
{
DECLARE_DYNCREATE(myeditview)
public:
BOOL PreCreateWindow(CREATESTRUCT &cs)
{
BOOL bp=CEditView::PreCreateWindow(cs);
cs.style&=~(WS_HSCROLL);
return bp;
}
};
IMPLEMENT_DYNCREATE(myeditview,CEditView)
class mydocument:public CDocument
{
DECLARE_SERIAL(mydocument)
void Serialize(CArchive &ar)
{ myeditview *v;
v=(myeditview *)m_viewList.GetHead();
v->SerializeRaw(ar);
}
int OnNewDocument()
{
CDocument::OnNewDocument();
if(!CDocument::OnNewDocument())
return 0;
else
return 1;
}
void DeleteContents()
{
myeditview *x;
if(m_viewList.GetCount())
{
x=(myeditview *)m_viewList.GetHead();
x->SetWindowText(NULL);
} } };
IMPLEMENT_SERIAL(mydocument,CDocument,0)
class myapp:public CWinApp
{
BOOL InitInstance()
{
CMultiDocTemplate *mdi;
CRuntimeClass *f, *doc,*view;
doc=RUNTIME_CLASS(mydocument);
f=RUNTIME_CLASS(CMDIChildWnd);
view=RUNTIME_CLASS(myeditview);
mdi=new CMultiDocTemplate(IDR_MENU1,doc,f,view);
AddDocTemplate(mdi);
CMDIFrameWnd *ff;
ff=new CMDIFrameWnd;
ff->LoadFrame(IDR_MENU1);
ff->ShowWindow(3);
m_pMainWnd=ff;
OnFileNew();
return 1;
} DECLARE_MESSAGE_MAP()
};
BEGIN_MESSAGE_MAP(myapp,CWinApp)
ON_COMMAND(ID_FILE_NEW,CWinApp::OnFileNew)
ON_COMMAND(ID_FILE_OPEN,CWinApp::OnFileOpen)
END_MESSAGE_MAP()
myapp a;
Output:
9)Program to create dynamic link libraries using MFC
#include "stdafx.h"
int ht=-((p->GetDeviceCaps(LOGPIXELSY)*size)/72);
CFont myfont;
myfont.CreateFont(ht,0,0,0,FW_NORMAL,0,0,0,DEFAULT_CHARSET,O
UT_CHARACTER_PRECIS,CLIP_CHARACTER_PRECIS,DEFAULT_QUALITY
,DEFAULT_PITCH|FF_DONTCARE,name);
CFont*pfont=p->SelectObject(&myfont);
p->SetTextColor(c);
p->SetBkMode(TRANSPARENT);
p->TextOut(pt.x,pt.y,text);
p->SelectObject(pfont);
Step 8: Right click the header file folder, add a header file and add the
following code,
#include<afxwin.h>
#include "font.h"
public:
myframe()
Create(0,"Client");
CClientDC d(this);
display(&d,"",72,RGB(255,0,255),pt,"INDIA");
DECLARE_MESSAGE_MAP()
};
BEGIN_MESSAGE_MAP(myframe,CFrameWnd)
ON_WM_LBUTTONDOWN()
END_MESSAGE_MAP()
class mywin:CWinApp
m_pMainWnd=new myframe();
m_pMainWnd->ShowWindow(1);
m_pMainWnd->UpdateWindow();
return TRUE;
};
mywin my;
Step 13: Goto Regular (project )folder and select Debug-> copy dll file &
object file paste it into client/Debug folder.
Step 14: Copy font.h from (project) Regular folder and paste it into client
folder.
Step 15: Goto Project ->properties->Linker->Map File Name and set the
path of the dll file in the client folder.
Step 16: Click Save all and execute.
Output:
Step 2: Click File menu and select the New Project sub menu.
Step 3: Select the project types as Visual Basic , and select Windows
->Windows Application.
Step 4: Name the project , change the location(if needed) and Click OK.
Step 6: From the Data Menu, click the Add New Data Source Command.
Step 7: In the Data Source Configuration Wizard, click the New Connection
button,
Step 8: Select the Database format and click Continue,
Step 9: From the Add connection window, Click the Browse button and
select the path of the access file & click the Test Connection Button.
Step 11: Once again from the Data Connection Wizard, click the
Connection String(+) sign and click Next
Step 12: Click Next, A message appears, click No.
Step 13: Click the (+) next to the Tables node, Select the Table1 and field
values Student Name and Dept & click Views and click Finish.
Step 14: Click the StudentDataset.xsd and click the View Designer icon at
the top of properties window.
Step 15: Click the Student Name field value and press F4 & set the
maxlength property to 50.
Step 16: Click the ListBox next to ID field and select Text Box, drag the
field over to the form.