Anda di halaman 1dari 90

Ex.

No :

MDI APPLICATION

DATE :
AIM
To create MDI and to draw an ellipse inside the view window using Device Context.
PROCEDURE
1.File -> New project tab->MFCAppWizard(exe). Give the location name and project
name
-> Ok.
2.Select Multiple Document option.
3.Accept the default in next 4 screen.
4.Click the finish button ->Ok button.
5. In the CPP file, write the following code in OnDraw()
void CMDINProjectView::OnDraw(CDC* pDC)
{
CMDINProjectDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
pDC->TextOut(0,0,"Hello world");
pDC->SelectStockObject(GRAY_BRUSH);
pDC->Ellipse(CRect(0,20,100,120));
}
6.Build and execute the application.
7. Stop the program.

OUTPUT

RESULT:
Thus the program is executed and output is verified successfully.

EX.NO :

CREATING A SDI APPLI CATION WITH


APPLICATION WIZARD

DATE :

AIM
To create a SDI Application with application wizard.

ALGORITHM
Step 1: Create a SDI application with project name SDIProj.
Step 2: Accept the default in the next four screens.
Step 3: Click finish button.
Step 4: Edit the OnDraw function in the view class.
void CSDINProjView::OnDraw(CDC* pDC)
{
pDC->TextOut(0,0,"Welcome to VC++ Lab");
pDC->SelectStockObject(GRAY_BRUSH);
pDC->Ellipse(CRect(0,0,100,120));
}

Step 5: Compile and execute the program.

OUTPUT

RESULT
Thus the program is executed and output is verified successfully.

EX. NO:

KEYBOARD EVENT

DATE :
AIM
To write a VC++ program for keyboard events using Win32 Application.

ALGORITHM
Step 1: Start the program.
Step 2: Create an object for an class which inherits CWinApp.
Step 3: Object access InitInstance() function.

Step 4: Create a pointer object for the class which inherits CFrameWindow by
Allocating memory to object.
Step 5: Show the created window using SW_SHOWNORMAL.
Step 6: Stop the program.

PROGRAM
#include<afxwin.h>
class myapp:public CFrameWnd
{
public:

myapp()
{
Create(0,"HAI");
}
void OnKeyDown(UINT flag,CPoint p)
{
CPen pen;
CBrush bru;
CClientDC dc(this);
pen.CreatePen(PS_SOLID,5,RGB(50,50,130));
dc.SelectObject(pen);
dc.SelectObject(bru);
dc.Ellipse(p.x,p.y,p.x+50,p.y+50);
}
void OnKeyUp(UINT flag,CPoint p)
{
CPen pen;
CBrush bru;
CClientDC dc(this);
pen.CreatePen(PS_SOLID,5,RGB(200,120,130));
bru.CreateHatchBrush(HS_HORIZONTAL,RGB(150,150,130));
dc.SelectObject(pen);
dc.SelectObject(bru);
dc.Ellipse(50,50,150,150);
}
DECLARE_MESSAGE_MAP();
};

BEGIN_MESSAGE_MAP(myapp,CFrameWnd)
ON_WM_KEYDOWN()
ON_WM_KEYUP()
END_MESSAGE_MAP()
class myfram:public CWinApp
{
public:
int InitInstance()
{
myapp *p;
p=new myapp;
p->ShowWindow(3);
m_pMainWnd=p;
return 1;
}
};
myfram a;

OUTPUT

RESULT
Thus the keyboard event program was compiled and successfully executed.

EX. NO:

MOUSE EVENTS

DATE :

AIM
To write a VC++ program for keyboard events using Win32 Application.

ALGORITHM
Step 1: Start the program.
Step 2: Create an object for an class which inherits CWinApp.
Step 3: Object access InitInstance() function.
Step 4: Create a pointer object for the class which inherits CFrameWindow by
Allocating memory to object.
Step 5: Show the created window using SW_SHOWNORMAL.
Step 6: Stop the program.

PROGRAM
#include<afxwin.h>
class myapp:public CFrameWnd
{
public:
myapp()
{
Create(0,"Mouse Events");
}
void OnLButtonDown(UINT flage,CPoint p)
{
CClientDC d(this);
d.TextOut(p.x,p.y,"WelCome",7);
}
DECLARE_MESSAGE_MAP();
};

BEGIN_MESSAGE_MAP(myapp,CFrameWnd)
ON_WM_LBUTTONDOWN()
END_MESSAGE_MAP()
class myfram:public CWinApp
{
public:
int InitInstance()
{
myapp *p;
p=new myapp;
p->ShowWindow(3);
m_pMainWnd=p;
return 1;}};myfram a;

OUTPUT

RESULT
Thus the mouse events program was compiled and successfully executed.

EX. NO:

MFC WINDOW CREATION

DATE :

AIM
To write a program to create window using MFC.

ALGORITHM
Step 1: Start the program.
Step 2: Create a window class that inherits CFrameWnd class.
Step 3: Define the constructor and create a window.
Step 4: Create the application class that inherits the CWinApp.
Step 5: Define the virtual function InitInstance().
Step 6: Create an object for the window class.
Step 7: Display the window.
Step 8: Globally declare an object for the application.
Step 9: Stop the program.

PROGRAM
#include<afxwin.h>
class mywin:public CFrameWnd
{
public:
mywin()
{
Create(0,"MY MFC");
}
};
class myapp:public CWinApp
{
public:
BOOL InitInstance()
{
mywin *p;
p=new mywin();
m_pMainWnd=p;
p->ShowWindow(SW_SHOWNORMAL);
return TRUE;
}

};
myapp a;

OUTPUT

RESULT
Thus the window creation program was compiled and successfully executed.

EX. NO:

MESSAGE MAP USING MFC

DATE :

AIM
To write a program for message map using MFC.

ALGORITHM
Step 1: Start the program.
Step 2: Create a window class the inherits CFrameWnd class.
Step 3:Define the message handler for mouse move event.
Step 4: Declare the message map.
Step 5: Define the message map for mouse move event.
Step 6: Create the application class that inherits CWinApp.
Step 7: Define the virtual function InitInstance.

Step 8: Create an object for the window class.


Step 9: Display the window.
Step 10: Globally declare an object for application.
Step 11: Stop the program.

PROGRAM
#include<afxwin.h>
class mywin:public CFrameWnd
{
public: mywin()
{
Create(0,"MFC");
}
DECLARE_MESSAGE_MAP()

void OnMouseMove(UINT f,CPoint p)


{
CClientDC d(this);
d.Ellipse(p.x,p.y,p.x+50,p.y+50);
}};
BEGIN_MESSAGE_MAP(mywin,CFrameWnd)
ON_WM_MOUSEMOVE()
END_MESSAGE_MAP()
class myapp:public CWinApp
{
public:
BOOL InitInstance()
{
mywin *p;
p=new mywin();
m_pMainWnd=p;
p->ShowWindow(SW_SHOWNORMAL);
return TRUE;
}
};myapp A;

OUTPUT

RESULT
Thus the program was executed and the output is verified successfully.

EX. NO :

CALCULATOR

DATE :

AIM
To design a calculator in VB.

ALGORITHM
Step 1: Start the program.
Step 2: Design the calculator using the tools Frame, TextBox, Command button.
Step 3: To create a control array for the command button.
Step 4: To change the label and properties for each button.
Step 5: Type the required code for each button what action perform when the button
clicked.
Step 6: Save and execute the program.
Step 7: Stop the program.

PROGRAM
Dim s As Variant
Dim n1 As Variant, a As Variant

Private Sub Cmdadd1_Click()


s = Cmdadd1.Caption
n1 = Text1.Text
Text1.Text = " "
End Sub

Private Sub CmdDiv_Click()


s = CmdDiv.Caption
n1 = Text1.Text
Text1.Text = " "
End Sub

Private Sub CmdMul_Click()


s = CmdMul.Caption
n1 = Text1.Text
Text1.Text = " "
End Sub

Private Sub Cmdsub_Click()


s = Cmdsub.Caption
n1 = Text1.Text
Text1.Text = " "
End Sub

Private Sub Command1_Click(Index As Integer)


If Text1.Enabled = True Then
a = Command1(Index).Caption
Text1.Text = Text1.Text + a
Else
MsgBox "calculator"
End If
End Sub

Private Sub Command6_Click()


If s = "+" Then
Text1.Text = Val(n1) + Val(Text1.Text)
ElseIf s = "-" Then
Text1.Text = Val(n1) - Val(Text1.Text)
ElseIf s = "*" Then
Text1.Text = Val(n1) * Val(Text1.Text)
ElseIf s = "/" Then
Text1.Text = Val(n1) / Val(Text1.Text)
End If
End Sub

Private Sub Command7_Click()


Text1.Text = " "
End Sub

OUTPUT

RESULT
Thus the calculator program was executed and the output was verified.

EX.NO :

STRING MANIPULATION

DATE :

AIM
To write a program for string manipulation in VB.

ALGORITHM
Step 1: Start the program.
Step 2: Open the new Standard EXE.
Step 3: In the form to add the Label, TextBox, Command button for manipulate the
String.
Step 4: Type the require code for manipulating a string.
Step 5: Save and Run the program.
Step 6: Stop the program.

PROGRAM
Private Sub Command1_Click()
Text2.Text = LCase(Text1.Text)
Label2.Caption = "Lower Case"
End Sub

Private Sub Command10_Click()


Text2.Text = StrReverse(Text1.Text)
Label2.Caption = "Reverse String"
End Sub

Private Sub Command11_Click()


Text2.Text = Text1.Text + Text2.Text
Label2.Caption = "Concatenate"
End Sub

Private Sub Command2_Click()


Text2.Text = UCase(Text1.Text)
Label2.Caption = "Upper Case"
End Sub

Private Sub Command3_Click()

Text2.Text = Left(Text1.Text, 1)
Label2.Caption = "Ltrim"
End Sub

Private Sub Command4_Click()


Text2.Text = Right(Text1.Text, 5)
Label2.Caption = "Rtrim"
End Sub

Private Sub Command5_Click()


Text2.Text = Len(Text1.Text)
Label2.Caption = "Length"
End Sub

Private Sub Command6_Click()


Text2.Text = InStr(3, Text1.Text, "l")
Label2.Caption = "InString"
End Sub

Private Sub Command7_Click()


Text2.Text = Mid(Text1.Text, 2, 4)
Label2.Caption = "Middle"
End Sub

Private Sub Command8_Click()


Text1.Text = ""
Text2.Text = " "
Label2.Caption = ""
End Sub

Private Sub Command9_Click()


End
End Sub

OUTPUT

RESULT
Thus the string manipulation program was executed and the output was verified.

EX.NO :

DATA CONTROL

DATE :

AIM
To write a program using the data control in VB.

ALGORITHM
Step 1: Start the program.
Step 2: Add the new form in the project.
Step 3: Design the form using Label, TextBox, Command button.
Step 4: To add the data control in the form.
Step 5: Create a new database for this program.
i)By select menu Add_Ins -> Visual Data Manager.
ii)Then click File -> New -> Microsoft Access -> Version 7.0 MDB.
iii)Then enter the database name in the selected location.
iv)Right click the properties, choose New Table.
v)Give the Table Name and add the necessary fields with corresponding
data types.
Step 6: In the data control properties we set the property DatabaseName and
RecordSource.
Step 7: Then change each TextBox property DataSource and DataField.
Step 8: Type the required code.
Step 9: Save and Run the program.
Step 10: Stop the program.

PROGRAM
Private Sub AddNew_Click()
Data1.Recordset.AddNew
AddNew.Enabled = False
Del.Enabled = False
Ext.Enabled = False
MovFirst.Enabled = False
MovLast.Enabled = False
MovPre.Enabled = False
MovNext.Enabled = False
End Sub

Private Sub Command1_Click()


Data1.Recordset.Edit
MsgBox "The current record is edited"
End Sub

Private Sub Del_Click()


Data1.Recordset .Delete
MsgBox "The current record is deleted"

End Sub

Private Sub Ext_Click()


End
End Sub

Private Sub Form_Load()


Text1.Text = " "
Text2.Text = " "
Text3.Text = ""
Text4.Text = ""
Text5.Text = ""
End Sub

Private Sub MovFirst_Click()


Data1.Recordset.MoveFirst
End Sub

Private Sub MovLast_Click()


Data1.Recordset.MoveLast
End Sub

Private Sub MovNext_Click()


Data1.Recordset.MoveNext
If (Data1.Recordset.EOF) Then
Data1.Recordset.MoveLast
MsgBox "You are already in the last record"
End If
End Sub

Private Sub MovPre_Click()


Data1.Recordset.MovePrevious
If (Data1.Recordset.BOF) Then
Data1.Recordset.MoveFirst
MsgBox "You are already in the first record"
End If
End Sub

Private Sub Save_Click()


Data1.Recordset.Update
MsgBox "The new record is saved"
AddNew.Enabled = True
Del.Enabled = True
Ext.Enabled = True
MovFirst.Enabled = True
MovLast.Enabled = True
MovPre.Enabled = True
MovNext.Enabled = True
End Sub

OUTPUT

RESULT
Thus the data control program was executed and the output was verified.

EX.NO :

FILE LIST CONTROL

DATE :

AIM
To create a file system control by using VB6.0.

ALGORITHM
Step 1: Start a new project by selecting Standard EXE .
Step 2: Add a FileListBox, DriveListBox, DirListBox ,Command button, Label,
PictureBox and TextBox.
Step 3: Type the required code.
Step 4: Save and Run the program.
Step 5: Select the location which picture to show.
Step 6: Stop the program.

PROGRAM
Private Sub Command1_Click()
End
End Sub

Private Sub Dir1_Change()


File1.Path = Dir1.Path
End Sub

Private Sub Drive1_Change()


Dir1.Path = Drive1.Drive
File1.Pattern = "*.jpg"
End Sub

Private Sub File1_Click()


Text1.Text = File1.Path
End Sub

Private Sub Form_Load()


Drive1.Drive = "c"

End Sub

Private Sub Option1_Click()


Image1.Visible = True
Image1.Picture = LoadPicture(Text1.Text & "\" & File1.FileName)
End Sub
Private Sub Option2_Click()
Image1.Visible = False
End Sub

OUTPUT

RESULT
Thus the file system control program was executed and the output was verified.

EX.NO :

ADO DATA CONTROL

DATE :
AIM To write a program for ADO Data Control in VB6.0.
ALGORITHM
Step 1: Start the program.
Step 2: Add the new form in the project.
Step 3: Design the form using Label, TextBox, Command button.
Step 4: To add the data control in the form
i)Select the menu Project -> Components
ii)The dialog box will be appeared. In the dialog box check the option
iii)Microsoft ADO Data Control 6.0.

iv)Then the ADO Data Control 6.0 appear int the tool box and add into the
form.
Step 5: Create a new database for this program.
i)By select menu Add_Ins -> Visual Data Manager.
ii)Then click File -> New -> Microsoft Access -> Version 7.0 MDB.
iii)Then enter the database name in the selected location.
iv)Right click the properties, choose New Table.
v)Give the Table Name and add the necessary fields with corresponding
data types.
Step 6: In the ADODC property to set the ConnectionString as follow:
i)Click Build -> Microsoft Jet 3.51 OLE DB provider ->
Click Next.
ii)In the Connection Tab select the database name.
iii)Then click Test Connection Button -> Ok -> Ok ->Ok.
Step 7: In the ADODC property to set the RecordSource.
In theCommand Text(SQL) type any SQL Command to select the rows -> Ok.
Step 8: Then change each TextBox property DataSource as and DataField.
Step 9: Type the required code.
Step 10: Save and Run the program.
Step 11: Stop the program.

PROGRAM
Private Sub Command1_Click()
Text7.Text = Val(Text3.Text) + Val(Text4.Text) + Val(Text5.Text) + Val(Text6.Text)
Text8.Text = Val(Text7.Text) / 4
If (Val(Text3.Text) < 35 Or Val(Text4.Text) < 35 Or Val(Text5.Text) < 35 Or Val(Text6.Text) <
35) Then
Text9.Text = "FAIL"

ElseIf (Val(Text8.Text) >= 60) Then


Text9.Text = "First class"
ElseIf (Val(Text8.Text) >= 50) Then
Text9.Text = "Second Class"
Else
Text9.Text = "Third Class"
End If
Command2.Enabled = True
End Sub

Private Sub Command2_Click()


Adodc1.Recordset.AddNew
Text1.SetFocus
Command2.Enabled = False
End Sub

Private Sub Command3_Click()


Adodc1.Recordset.Update
MsgBox "Your data was updated"
End Sub
Private Sub Command4_Click()
Adodc1.Recordset.MoveFirst
End Sub
Private Sub Command5_Click()
Adodc1.Recordset.MovePrevious
If (Adodc1.Recordset.BOF) Then
Adodc1.Recordset.MoveFirst

MsgBox "you are on the first record"


End If
End Sub

Private Sub Command6_Click()


Adodc1.Recordset.MoveLast
End Sub

Private Sub Command7_Click()


Adodc1.Recordset.Delete
MsgBox "Your data was deleted"
End Sub

Private Sub Command8_Click()


Adodc1.Recordset.MoveNext
If (Adodc1.Recordset.EOF) Then
Adodc1.Recordset.MoveLast
MsgBox "You are on the last record"
End If
End Sub

Private Sub Command9_Click()


End
End Sub

OUTPUT

RESULT
Thus the ADO data control program was executed and the output was verified.

EX.NO :

MOUSE EVENTS AND KEYBOARD EVENTS

DATE :

AIM
To write a simple VB application that demonstrate the use of keyboard and mouse events.

ALGORITHM
Step 1: Start a new project by select Standard EXE form new project.
Step 2: Then type the required code.
Step 3: Save and Run the program.
Step 4: Stop the program.

PROGRAM
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Select Case Shift
Case vbShiftMask
Print "You pressed the shift key"
Case vbCtrlMask
Print "You pressed the ctrl key"
Case vbShiftMask
Print "You pressed the shift key+ alt key"
Case vbAltMask
Print "You pressed the alt key"
End Select
End Sub
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Circle (X, Y), 75
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)

DrawWidth = 3
PSet (X, Y)
End Sub
Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim ccode As Integer
Randomize
ccode = Int(15 * Rnd)
FillStyle = 0
FillColor = QBColor(ccode)
Circle (X, Y), 75
End Sub

OUTPUT

RESULT
Thus the program for keyboard and mouse events was executed successfully and the
output was verified.

EX.NO :

PALINDROME

DATE :

AIM
To develop a simple application to reverse a given string and to check whether the string
is palindrome or not.

ALGORITHM
Step 1: Start a new project by select Standard EXE form new project.

Step 2: Add a TextBox and Command button to the form.


Step 3: Type the required code.
Step 4: Save and Run the program.
Step 5: Stop the program.

PROGRAM
Option Explicit
Dim str1, str2 As String

Private Sub Cmd_Pol_Click()


str1 = Trim(Text1.Text)
str2 = StrReverse(str1)
Text3.Text = str2
If str1 = str2 Then
MsgBox "String is palindrome"
Else
MsgBox "String is not a palindrome"
End If
End Sub

Private Sub Cmd_quit_Click()


End
End Sub

Private Sub Cmd_reset_Click()


Text1.Text = " "
Text3.Text = " "
End Sub

OUTPUT

RESULT
Thus the palindrome program was executed successfully and the output was verified.

DATA REPORT

EX.NO :
DATE :

AIM
Step 1: Start new project.
Step 2: Design the form using Command button.
Step 3: Add the Data Environment and Data Report to the project.
Click menu Project -> Add Data Environment.
Click menu Project -> Add Data Report.
Step 5: Create a new database for this program.
i)By select menu Add_Ins -> Visual Data Manager.
ii)Then click File -> New -> Microsoft Access -> Version 7.0 MDB.
iii)Then enter the database name in the selected location.
iv)Right click the properties, choose New Table.
v)Give the Table Name and add the necessary fields with corresponding
data types.
Step 6: To create a ODBC Connection Start -> Control Pannal ->
System and Security -> Administrative Tools -> Data Source(ODBC).
i)In the User DSN Tab Click Add button -> Select the Driver do Microsoft
Access(*.mdb).
ii)Then the ODBC Microsoft Access setup diabox appear. Give the DataSourceName.
Select the database-> Ok -> Ok -> Ok.

Step 7: In the Data Environment right click the connection choose properties.
Select the Microsoft OLE DB Provider for ODBC Drivers -> Next .
Give the select the data source name. Click Test Connection button ->Ok ->Ok.
Step 8: Right click the connection Add Command.
Step 9: Right click the command1 choose properties.
Step 10: Give Database Object as Table and select the object name ->Ok.
Step 11: Drag the command1 in the Data Environment into Data Report.
Step 12: Set the Data Report property DataSource as Data Environment and DataMember as
Command1.
Step 13: Type the required code in Command1_Click()

Private Sub Command1_Click()


DataReport1.Show
End Sub
Step 14: Save and Rum the program.
Step 15: Stop the program.

OUTPUT

RESULT
Thus the Data Report program was executed and the output was verified.

EX.NO :

SLIDER CONTROL

DATE :

AIM
To write a VC++ Program for creating a slider control using Win32 application.

ALGORITHM
Step 1: Start the program.
Step 2: Open a new project by selecting File>New>Win32 Application.
Select the location and give the File Name then click Ok ->Finish ->Ok.
Step 3: Open a new source file by selecting File>New>C++ Source files and Click
Ok.
Step 4: Type the required code.
Step 5: Select menu Project>Settings>Microsoft foundation classes choose for Use
MFC in a Shared DLL.
Step 7: Compile and Execute the program.
Step 8: Stop the program.

PROGRAM
#include<afxwin.h>
#include<afxcmn.h>
class myframe:public CFrameWnd
{
private:
CSliderCtrl sli;
CButton gr;
public:
myframe()
{
CString mywindowclass;
mywindowclass=AfxRegisterWndClass(CS_VREDRAW|CS_HREDRAW,0,
(HBRUSH)::GetStockObject(LTGRAY_BRUSH),0);

Create(mywindowclass,"Slider Control");
}
int OnCreate(LPCREATESTRUCT I)
{
CFrameWnd::OnCreate(I);
gr.Create("SLIDER DISPLAY",WS_CHILD|WS_VISIBLE|
BS_GROUPBOX,CRect(30,30,310,100),this,1);
sli.Create(WS_CHILD|WS_VISIBLE|TBS_HORZ|TBS_AUTOTICKS|
TBS_BOTTOM|TBS_ENABLESELRANGE,CRect(35,50,305,90),this,2);
sli.SetRange(0,8);
sli.SetPos(2);
sli.SetSelection(0,2);
sli.SetPageSize(3);
return 0;
}
void OnHScroll(UINT code,UINT pos,CScrollBar *scroll)
{
switch(code)
{
case TB_LINEUP:
case TB_LINEDOWN:
case TB_PAGEUP:
case TB_PAGEDOWN:
case TB_TOP:
case TB_BOTTOM:
pos=sli.GetPos();
sli.SetSelection(0,pos);
sli.SetTic(pos);

break;
case TB_THUMBPOSITION:
sli.SetSelection(0,pos);
sli.SetTic(pos);
break;
case TB_THUMBTRACK:
sli.SetSelection(0,pos);
sli.SetTic(pos);
break;
}
}
DECLARE_MESSAGE_MAP()
};
BEGIN_MESSAGE_MAP(myframe,CFrameWnd)
ON_WM_CREATE()
ON_WM_HSCROLL()
END_MESSAGE_MAP()
class myapp:public CWinApp
{
public:
int InitInstance()
{
myframe *p;
p=new myframe;
p->ShowWindow(3);
m_pMainWnd=p;
return 1;

}
};
myapp a;

OUTPUT

RESULT
Thus the Slider Control program was executed and the output was verified.

EX.NO :

TREE VIEW CONTROL

DATE :

AIM
To write a Visual C++ program for creating a TreeView Control using Win32
Application.

ALGORITHM
Step 1: Start the program.
Step 2: Open a new project by selecting File>New>Win32 Application.
Select the location and give the File Name then click Ok ->Finish ->Ok.
Step 3: Open a new source file by selecting File>New>C++ Source files and Click
Ok.
Step 4: Type the required code.
Step 5: Select menu Project>Settings>Microsoft foundation classes choose for Use
MFC in a Shared DLL.
Step 7: Compile and Execute the program.
Step 8: Stop the program.

PROGRAM
#include<afxwin.h>
#include<afxcmn.h>
class myframe:public CFrameWnd
{
private:
CTreeCtrl tree;
public:
myframe()
{
Create(0,"Tree View Control");
}
int OnCreate(LPCREATESTRUCT I)
{
HTREEITEM lang,opersys,c,cpp,java;
CFrameWnd::OnCreate(I);
tree.Create(WS_CHILD|WS_VISIBLE|WS_BORDER|TVS_HASLINES|
TVS_LINESATROOT|TVS_HASBUTTONS|
TVS_SHOWSELALWAYS,CRect(30,30,300,350),this,1);
lang=tree.InsertItem("Computer languages",TVI_ROOT,TVI_SORT);
c=tree.InsertItem("C",lang,TVI_SORT);

tree.InsertItem("TC",c);
tree.InsertItem("QC",c);
tree.InsertItem("MSC",c);
cpp=tree.InsertItem("C++",lang,TVI_SORT);
tree.InsertItem("VC++",cpp);
tree.InsertItem("Botland C++",cpp);
java=tree.InsertItem("java",lang,TVI_SORT);
tree.InsertItem("VJ++",java);
tree.InsertItem("Symentec cafe",java);
tree.InsertItem("Sun JDK",java);
opersys=tree.InsertItem("Operating Systems",TVI_ROOT,TVI_SORT);
tree.InsertItem("Win 3.1",opersys);
tree.InsertItem("Win 95",opersys);
tree.InsertItem("Win NT",opersys);
return 0;
}
int OnNotify(WPARAM w,LPARAM l,LRESULT *r)
{
HTREEITEM h;
CString str;
CWnd::OnNotify(w,l,r);
NM_TREEVIEW *p=(NM_TREEVIEW *)l;
if(p->hdr.code==TVN_SELCHANGED)
{
h=tree.GetSelectedItem();
str=tree.GetItemText(h);
MessageBox(str,"You have selected");

}
return 1;
}
DECLARE_MESSAGE_MAP()
};
BEGIN_MESSAGE_MAP(myframe,CFrameWnd)
ON_WM_CREATE()
END_MESSAGE_MAP()
class myapp:public CWinApp
{
public:
int InitInstance()
{
myframe *p;
p=new myframe;
p->ShowWindow(3);
m_pMainWnd=p;
return 1;
}
};
myapp a;

OUTPUT

RESULT
Thus the TreeView Control program was executed and the output was verified.

EX.NO :

SHAPE

DATE :

AIM
To write a program for draw different shape using Common Dialog Control in VB.

ALGORITHM
Step 1: Create a new project.
Step 2: To design the form by adding ListBox, Command button, Shape and add the
Common Dialog Control into form by Select Project menu-> Components->
Check Microsoft Common Control6.0.
Step 3: Type the required code.
Step 4: Save and Run the program.
Step 5: Stop the program.

PROGRAM
Private Sub Command1_Click()
End
End Sub

Private Sub Form_Load()


List1.AddItem "Rectangle"
List1.AddItem "Square"
List1.AddItem "Oval"
List1.AddItem "Circle"
List1.AddItem "Rounded Rectangle"
List1.AddItem "Rounded Square"
End Sub

Private Sub List1_Click()


Select Case List1.ListIndex
Case 0
Shape1.Shape = 0
cd.ShowColor
Shape1.FillColor = cd.Color
Case 1
cd.ShowColor

Shape1.FillColor = cd.Color
Shape1.Shape = 1
Case 2
cd.ShowColor
Shape1.FillColor = cd.Color
Shape1.Shape = 2
Case 3
cd.ShowColor
Shape1.FillColor = cd.Color
Shape1.Shape = 3
Case 4
cd.ShowColor
Shape1.FillColor = cd.Color
Shape1.Shape = 4
Case 5
cd.ShowColor
Shape1.FillColor = cd.Color
Shape1.Shape = 5
End Select
End Sub

OUTPUT

RESULT
Thus the shape program was executed and the output was verified.

EX.NO :

ESCAPE KEY

DATE :

AIM
To write a program for to press the escape key to close the form in VB.

ALGORITHM
Step 1: Start the program.
Step 2: Create a new project.

Step 3: To design the form to add Label, TextBox, Command button.


Step 4: Type the required code.
Step 5: Save and Run the program.
Step 6: Stop the program.

PROGRAM
Private Sub Command1_Click()
Text1.Text = ""
End Sub

escape
Private Sub Command2_Click()
MsgBox "Press Esc Key"
End Sub

Private Sub Command2_KeyPress(KeyAscii As Integer)


Dim a As Integer
If KeyAscii = vbKeyEscape Then
a = MsgBox("Do You want to end this program", vbYesNo)
If a = vbYes Then
End
Else
Text1.SetFocus
End If
End If
End Sub

OUTPUT

RESULT
Thus the program was executed and the output was verified.

EX.NO :

DATABASE CONNECTIVITY

DATE :
AIM
To create a SDI application with Database Connection.

PROCEDURE
1.
data
i)

Fields

Types

Studname

Text

Grade
Text
ii)
iii)
iv)
Select the database.
Database Name: Student
Table Name: Information

Create a data source and create ODBC


source.
Control Panel->Administrative tool>ODBC data source.
Click add.
Select Microsoft access driver.

2. Create a SDI application using MFC AppWizard ProjectDB.


3. In a second screen of the AppWizard select the option Header Files Only for the
database support.
4. Accept the defaults for the renaming.
5. Create the recordset class.
i)
Choose the recordset class
ii)
Select new from the add class menu
iii)
Give the class name in the dialog box CStudent
iv)
Select CRecordset as base class
v)
Choose the data source stud
6. Add the virtual function for InitialUpdate in the view class.
7. Add the variable CStudent *ptr to the view class.
8. Edit the following functions in the view class.
9.
CProject15View::CProject15View()
{

ptr=new CStudent();
}
CProject15View::CProject15View()
{
ptr->Close();
delete ptr;
}

void CProject15View::OnInitialUpdate()
{
if(ptr->IsOpen())
ptr->Close();
ptr->Open();
}
void CProject15View::OnDraw(CDC *pDC)
{
int x=100;
int y=100;
if(ptr->ISBOF())
{
pDC->TextOut(100,100,Empty record set);
return;
}
ptr->MoveFirst();
while(!ptr->IsEOF())
{
pDC->TextOut(x,y,ptr->m_Studentname);
pDC->TextOut(x+100,y,ptr->m_Regno);
pDC->TextOut(x+150,y,ptr->m_Grade);
y=y+50;
ptr->MoveNext();
}
}
10. Add the student header file in CProject15View.cpp file
#include student.h

RESULT
Thus the program was executed and the output was verified.

EX. NO :

DYNAMIC LINK LIBRARY

DATE :

AIM
To create a dll and link that to the application implicity.
ALGORITHM
Building dll file
Step 1: Create a DLL application by selecting MFCAPPWizard(dll).
Step 2: Give the project name Projdll.
Step 3: In the application wizard screen, Choose-> MFC Shared dll.
Step 4: Click finish button.
Step 5: Include the header file in the projdll headerfile.
#include math.h

Step 6: Include the declaration in projdll header file.


extern "C"_declspec(dllexport)double squareroot(double a);

Step 7: Define the function in projdll.cpp files as follows.


extern "C"_declspec(dllexport)double squareroot(double a)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
if(a>0)
return sqrt(a);
else
{
AfxMessageBox("Square root can't be computed for negative values");
return 0;
}
}
Step 8 : Build the dll.

Creating the Exe file


Step 1: Create a SDI application as projdll1.
Step 2: Select single document interface.
Step 3: Accept the default in the next screens.
Step 4: Choose CFormView as a base class for Cprojdll1View class in the last screen.
Step 5: Click finish.
Step 6: Design the controls in from view.

Control

Caption

ID

Static

Enter the Name

IDC_STATIC

Edit

IDC_NUM

Static

Square root value

IDC_STATIC1

Edit

IDC_RESULT

Button

SQRT

IDC_SQRT

Step 7: Add the member variables for Edit boxes


Control

Variable

IDC_NUM

m_num

IDC_RESULT

m_Result

Step 8: Add the message handler for Edit boxes

void CDllexeView::OnSqrt()
{

// TODO: Add your control notification handler code here


UpdateData(TRUE);
m_result=squareroot(m_num);
UpdateData(FALSE);
}
Step 9: Add the declaration in CProjdll1View file
Extern C_declspec(dllimport)double squareroot(double a);
Step 10: Select Project Settings. In the Dialog box, click the lin tab. Then in the object
Modules text box edit the libray file name Debug\projdll.lib and click Ok.
Step 11: Copy the files projdll.dll and projdll.lib from projdll>Debug folder to
projdll1 folder.
Step 12: Build and execute the application.

OUTPUT

RESULT
Thus the program was executed and the output was verified.

EX.NO :

PROGRAM USING GRAPHICAL DEVICE

DATE :

INTERFACE OBJECTS

AIM
To create a SDI application illustrate the concept of GDI objects.

ALGORITHM
Step 1:Create the SDI application GDIproj.
Step 2:Create the menu GDI in the menu bar using resource editor, and add
the following menu items into GDI.

Menu Item

ID

Pen

ID_GDI_PEN

Brush

ID_GDI_BRUSH

Font

ID_GDI_FONT

Step 3: Add the following member variable in the view class int MenuItem .
Step 4: Add message handlers for menu items Pen, Brush, Font
.
Step 5: Edit the message handlers
void CGDIView::OnGdiPen()
{
MenuItem=1;
Invalidate(true);

}
void CGDIView::OnGdiBrush()
{
MenuItem=2;
Invalidate(true);}
void CGDIView::OnGdiFont()
{
MenuItem=3;
Invalidate(true);
}
Step 6: Edit the code for OnDraw function
void CGDIView::OnDraw(CDC* pDC)
{
CGDIDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
if(MenuItem==1)
{
CPen pen;
pen.CreatePen(PS_DOT,1,RGB(100,100,200));
pDC->SelectObject(pen);
pDC->MoveTo(100,100);
pDC->LineTo(300,300);
pen.DeleteObject();
pen.CreatePen(PS_SOLID,5,RGB(250,100,200));
pDC->SelectObject(pen);
pDC->Ellipse(250,250,500,300);

}
else if(MenuItem==2)
{
CBrush brush;
brush.CreateSolidBrush(RGB(25,10,10));
pDC->SelectObject(brush);
pDC->RoundRect(100,100,200,300,10,10);
CBrush brush1;
brush1.CreateHatchBrush(HS_BDIAGONAL,RGB(0,0,255));
pDC->SelectObject(brush1);
pDC->Ellipse(300,100,400,300);
}
else if(MenuItem==3)
{
CFont font;

font.CreateFont(50,25,0,0,900,0,0,0,ANSI_CHARSET,OUT_DEFAULT_PRECIS,CLIP_DEFA
ULT_PRECIS,DEFAULT_QUALITY,DEFAULT_PITCH|FF_SWISS,"Monotype Corsiva");
pDC->SelectObject(font);
pDC->SetTextColor(RGB(0,10,15));
pDC->TextOut(10,300,"Visual Programming Lab");
}
}
Step 7: Compile and execute the program.

OUTPUT

RESULT

Thus the GDI program was executed and the output was verified.

Anda mungkin juga menyukai