78
FORM DESIGN- KEYBOARD AND MOUSE EVENTS 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 + vbAltMask Print "you pressed Shift key+alt key" Case vbAltMask Print "you pressed 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)

vp prgm

Embed Size (px)

Citation preview

Page 1: vp prgm

7/28/2019 vp prgm

http://slidepdf.com/reader/full/vp-prgm 1/78

FORM DESIGN- KEYBOARD AND MOUSE EVENTS

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 + vbAltMask 

Print "you pressed Shift key+alt key"

Case vbAltMask 

Print "you pressed 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)

Page 2: vp prgm

7/28/2019 vp prgm

http://slidepdf.com/reader/full/vp-prgm 2/78

Dim CCode As Integer 

Randomize

CCode = Int(15 * Rnd)

FillStyle = 0

FillColor = QBColor(CCode)

Circle (X, Y), 75

End Sub

Page 3: vp prgm

7/28/2019 vp prgm

http://slidepdf.com/reader/full/vp-prgm 3/78

OUTPUT

RESULT

Page 4: vp prgm

7/28/2019 vp prgm

http://slidepdf.com/reader/full/vp-prgm 4/78

PROGRAM ON USAGE OF DATATYPES, CONTROL ARRAYS

(Implementation of Simple Calculator)

Dim u, v As Variant

Dim Y, n As Variant

Dim flag, flag1 As Integer 

Private Sub Cmd_back_Click()

If flag1 <> True Then

Text1.Text = Left(Text1.Text, Len(Text1.Text) - 1)

If Len(Text1.Text) = 0 Then

Text1.Text = "0"

flag1 = False

End If 

End If 

End Sub

Private Sub Cmd_clear_Click()

Text1.Text = " "

Text1.Text = "0"

flag = False

End Sub

Private Sub Cmd_dot_Click()

If flag <> True Then

Page 5: vp prgm

7/28/2019 vp prgm

http://slidepdf.com/reader/full/vp-prgm 5/78

Text1.Text = Text1.Text + "."

flag = True

End If 

End Sub

Private Sub Cmd_off_Click()

Text1.Enabled = False

For m = 0 To 9

numcmd(m).Enabled = False

 Next m

For k = 0 To 9

opercmd(k).Enabled = False

 Next k 

Cmdon.Enabled = True

Cmd_clear.Enabled = False

Cmd_back.Enabled = False

Text1.Text = " "

End Sub

Private Sub Cmdon_Click()

Text1.Enabled = True

numcmd(m).Enabled = True

For m = 0 To 9

numcmd(m).Enabled = True

 Next m

Page 6: vp prgm

7/28/2019 vp prgm

http://slidepdf.com/reader/full/vp-prgm 6/78

For k = 0 To 9

opercmd(k).Enabled = True

 Next k 

Cmdon.Enabled = True

Cmd_clear.Enabled = True

Cmd_back.Enabled = True

End Sub

Private Sub Form_Load()

Text1.Text = "0"

Text1.Enabled = False

For m = 0 To 9

numcmd(m).Enabled = False

 Next m

For k = 0 To 9

opercmd(k).Enabled = False

 Next k 

Cmdon.Enabled = True

Cmd_clear.Enabled = False

Cmd_back.Enabled = False

End Sub

Private Sub numcmd_Click(Index As Integer)

If Text1.Text = "0" Then

Page 7: vp prgm

7/28/2019 vp prgm

http://slidepdf.com/reader/full/vp-prgm 7/78

Text1.Text = " "

Text1.Text = Text1.Text & numcmd(Index).Caption

Else

Text1.Text = Text1.Text & numcmd(Index).Caption

flag1 = False

End If 

End Sub

Private Sub opercmd_Click(Index As Integer)

If opercmd(Index) <= 10 Then

Select Case Index

Case 0, 1, 2, 3, 4, 5, 6, 7, 8, 9

v = Val(Text1.Text)

Text1.Text = " "

End Select

Select Case Index

Case 0

flag = False

n = 0

Case 1

flag = False

n = 1

Case 2

flag = False

n = 2

Page 8: vp prgm

7/28/2019 vp prgm

http://slidepdf.com/reader/full/vp-prgm 8/78

Case 3

flag = False

n = 3

Case 4

flag = False

n = 4

Case 5

flag = False

Text1.Text = v ^ 2

Case 6

flag = False

Text1.Text = v ^ 3

Case 7

flag = False

Text1.Text = 1 / v

Case 8

flag = False

Text1.Text = v * (-1)

Case 9

flag = False

Y = 1

For i = 1 To v

Y = Y * i

 Next i

Text1.Text = Y

Page 9: vp prgm

7/28/2019 vp prgm

http://slidepdf.com/reader/full/vp-prgm 9/78

Case 10

flag = True

flag1 = True

u = Val(Text1.Text)

If n = 0 Then

Text1.Text = v + u

ElseIf n = 1 Then

Text1.Text = v - u

ElseIf n = 2 Then

Text1.Text = v * u

ElseIf n = 3 Then

Text1.Text = v / u

ElseIf n = 4 Then

Text1.Text = v Mod u

End If 

End Select

End If 

End Sub

Page 10: vp prgm

7/28/2019 vp prgm

http://slidepdf.com/reader/full/vp-prgm 10/78

OUTPUT

RESULT

The program for control arrays was done successfully and the output is verified

Page 11: vp prgm

7/28/2019 vp prgm

http://slidepdf.com/reader/full/vp-prgm 11/78

APPLICATION USING FILE SYSTEM CONTROL

Private Sub Combo1_Change()

Dir1.Enabled = True

Drive1.Enabled = True

File1.Enabled = True

File1.Pattern = Combo1.Text

End Sub

Private Sub Dir1_Change()

File1.Path = Dir1.Path

End Sub

Private Sub Drive1_Change()

Dir1.Path = Drive1.Drive

End Sub

Private Sub File1_Click()

Text1.Text = Dir1.Path & "/" & File1.FileName

End Sub

Private Sub File1_DblClick()

If flag = False Then

If Combo1.Text = "*.jpg" Or Combo1.Text = "*.gif" Or Combo1.Text = "*.bmp" Then

P1.Visible = True

Page 12: vp prgm

7/28/2019 vp prgm

http://slidepdf.com/reader/full/vp-prgm 12/78

RTB.Visible = False

P1.Picture = LoadPicture(Dir1.Path & "/" & File1.FileName)

Else

P1.Visible = False

RTB.Visible = True

RTB.LoadFile (Dir1.Path & "/" & File1.FileName)

End If 

End If 

End Sub

Private Sub Form_Load()

Dir1.Enabled = True

Drive1.Enabled = True

File1.Enabled = True

Optshow.Enabled = True

Opthide.Enabled = True

End Sub

Private Sub Opthide_Click()

If Combo1.Text = "*.jpg" Or Combo1.Text = "*.gif" Or Combo1.Text = "*.bmp" Then

P1.Visible = False

Else

RTB.Visible = False

End If 

End Sub

Page 13: vp prgm

7/28/2019 vp prgm

http://slidepdf.com/reader/full/vp-prgm 13/78

Private Sub Optshow_Click()

If Combo1.Text = "*.jpg" Or Combo1.Text = "*.gif" Or Combo1.Text = "*.bmp" Then

P1.Visible = True

Else

RTB.Visible = True

End If 

flag = False

End Sub

Page 14: vp prgm

7/28/2019 vp prgm

http://slidepdf.com/reader/full/vp-prgm 14/78

OUTPUT

RESULT 

The program for file system controls was done successfully and the output is verified

Page 15: vp prgm

7/28/2019 vp prgm

http://slidepdf.com/reader/full/vp-prgm 15/78

DATABASE APPLICATION USING DATACONTROL

Dim txt As TextBox

Dim x As Integer 

Private Sub Cmdadd_Click()

hidebutton

showtxtbox

Data1.Recordset.AddNew

End Sub

Private Sub Cmdcancel_Click()

showbutton

hidebutton

Data1.Recordset.CancelUpdate

End Sub

Private Sub Cmdcount_Click()

Dim no As Integer 

hidetxtbox

MsgBox ("Number of Record is:" & Data1.Recordset.RecordCount)

End Sub

Private Sub Cmddelt_Click()

a = Data1.Recordset.RecordCount

Page 16: vp prgm

7/28/2019 vp prgm

http://slidepdf.com/reader/full/vp-prgm 16/78

If a <= 0 Then

MsgBox "Record is not available"

Else

reply = MsgBox("Are you sure want to delete", vbInformation + vbYesNo, "vbinformatio")

If reply = vbYes Then

Data1.Recordset.Delete

Data1.Recordset.MovePrevious

MsgBox "Current Record is Deleted"

End If 

End If 

End Sub

Private Sub Cmdedit_Click()

showtxtbox

hidebutton

Data1.Recordset.Edit

End Sub

Private Sub Cmdupdt_Click()

Dim id As Integer 

id = txtid.Text

If txtname.Text = "" Then

MsgBox "Please enter the name"

txtname.SetFocus

flag = True

Page 17: vp prgm

7/28/2019 vp prgm

http://slidepdf.com/reader/full/vp-prgm 17/78

ElseIf txtbasic.Text = "" Then

MsgBox "Please enter the Basic Pay"

txtbasic.SetFocus

flag = True

ElseIf txtda.Text = "" Then

MsgBox "Please enter the DA"

txtda.SetFocus

flag = True

ElseIf txthra.Text = "" Then

MsgBox "Please enter the HRA"

txthra.SetFocus

flag = True

ElseIf txtit.Text = "" Then

MsgBox "Please enter the Income Tax"

txtit.SetFocus

flag = True

ElseIf txtded.Text = "" Then

MsgBox "Please enter the Deduction"

txtded.SetFocus

flag = True

Else

Data1.Recordset.Update

MsgBox "Current Record is saved"

flag = False

hidetxtbox

Page 18: vp prgm

7/28/2019 vp prgm

http://slidepdf.com/reader/full/vp-prgm 18/78

End If 

If flag = False Then

showbutton

End If 

End Sub

Private Sub Form_Load()

showbutton

hidetxtbox

End Sub

Private Sub txtbasic_Change()

cal

End Sub

Private Sub txtbasic_KeyUp(KeyCode As Integer, Shift As Integer)

f1 = IsNumeric(txtbasic.Text)

If f1 = False Then

MsgBox "Please enter Numbers only"

txtbasic.Text = ""

txtbasic.SetFocus

End If 

End Sub

Private Sub txtbasic_LostFocus()

Page 19: vp prgm

7/28/2019 vp prgm

http://slidepdf.com/reader/full/vp-prgm 19/78

If Val(txtbasic.Text) <= 10000 Then

txtit.Text = (3 / 100) * 10000

txtded.Text = (4 / 100) * 10000

ElseIf Val(txtbasic.Text) > 10000 And Val(txtbasic.Text) <= 25000 Then

txtit.Text = (5 / 100) * 10000

txtded.Text = (6 / 100) * 10000

ElseIf Val(txtbasic.Text) > 25000 Then

txtit.Text = (7 / 100) * 10000

txtded.Text = (8 / 100) * 10000

End If 

End Sub

Private Sub txtda_Change()

cal

End Sub

Private Sub txtda_KeyUp(KeyCode As Integer, Shift As Integer)

f1 = IsNumeric(txtda.Text)

If f1 = False Then

MsgBox "Please enter Numbers only"

txtda.Text = ""

txtda.SetFocus

End If 

End Sub

Page 20: vp prgm

7/28/2019 vp prgm

http://slidepdf.com/reader/full/vp-prgm 20/78

Private Sub txthra_Change()

cal

End Sub

Private Sub txthra_KeyUp(KeyCode As Integer, Shift As Integer)

f1 = IsNumeric(txthra.Text)

If f1 = False Then

MsgBox "Please enter Numbers only"

txthra.Text = ""

txthra.SetFocus

End If 

End Sub

Private Sub txtid_KeyUp(KeyCode As Integer, Shift As Integer)

f1 = IsNumeric(txtid.Text)

If f1 = False Then

MsgBox "Please enter Numbers only"

txtid.Text = ""

txtid.SetFocus

End If 

End Sub

Private Sub txtname_KeyUp(KeyCode As Integer, Shift As Integer)

f1 = IsNumeric(txtname.Text)

If f1 = False Then

Page 21: vp prgm

7/28/2019 vp prgm

http://slidepdf.com/reader/full/vp-prgm 21/78

MsgBox "Please enter String only"

txtname.Text = ""

txtname.SetFocus

End If 

End Sub

Private Sub cal()

a = Val(txtbasic.Text) + Val(txtda.Text) + Val(txthra.Text)

 b = Val(txtit.Text) + Val(txtded.Text)

txtsal.Text = a - b

End Sub

Private Sub hidetxtbox()

txtname.Enabled = False

txtid.Enabled = False

txtbasic.Enabled = False

txtda.Enabled = False

txthra.Enabled = False

txtit.Enabled = False

txtded.Enabled = False

txtsal.Enabled = False

End Sub

Private Sub showtxtbox()

txtname.Enabled = True

txtid.Enabled = True

txtbasic.Enabled = True

txtda.Enabled = True

Page 22: vp prgm

7/28/2019 vp prgm

http://slidepdf.com/reader/full/vp-prgm 22/78

txthra.Enabled = True

End Sub

Private Sub hidebutton()

Cmdupdt.Visible = True

Cmdadd.Visible = True

Cmdcancel.Visible = False

Cmdedit.Visible = False

Cmddelt.Visible = False

End Sub

Private Sub showbutton()

Cmdupdt.Visible = True

Cmdadd.Visible = True

Cmdcancel.Visible = True

Cmdedit.Visible = True

Cmddelt.Visible = True

End Sub

Page 23: vp prgm

7/28/2019 vp prgm

http://slidepdf.com/reader/full/vp-prgm 23/78

OUTPUT

RESULT

The program for data controls was done successfully and the output is verified

Page 24: vp prgm

7/28/2019 vp prgm

http://slidepdf.com/reader/full/vp-prgm 24/78

WINDOW CREATION

//app.h

class CAppApp : public CWinApp

{

 public:

CAppApp();

 public:

virtual BOOL InitInstance();

};

// app.cpp

#include "app.h"

#include<afxwin.h>

#include "frame.h"

BOOL CAppApp::InitInstance()

{

frame *p;

 p=new frame;

m_pMainWnd=p;

 p->ShowWindow(SW_SHOWNORMAL);

return TRUE;

}

//Frame.h

class frame : public CFrameWnd

{

 public:

Page 25: vp prgm

7/28/2019 vp prgm

http://slidepdf.com/reader/full/vp-prgm 25/78

frame();

//void OnPaint();

DECLARE_MESSAGE_MAP()

};

//Frame.cpp

#include<afxwin.h>

#include "frame.h"

BEGIN_MESSAGE_MAP(frame, CFrameWnd)

ON_WM_PAINT()

END_MESSAGE_MAP()

void frame::OnPaint()

{

CPaintDC dc(this); // device context for painting

dc.TextOut(100,100,"Welcome to MCA",14);

}

Frame:frame()

{

Create(0,”frame”);

}

Page 26: vp prgm

7/28/2019 vp prgm

http://slidepdf.com/reader/full/vp-prgm 26/78

OUTPUT

RESULT

The program for window creation using VC++ was done successfully and the output is verified

Page 27: vp prgm

7/28/2019 vp prgm

http://slidepdf.com/reader/full/vp-prgm 27/78

DRAWING DIFFERENT TYPES OF BRUSHES USING GDI

void CBrushView::OnPaint()

{

CPaintDC dc(this); // device context for painting

CPen pen;

 pen.CreatePen(PS_DASH,3,RGB(0,0,255));

dc.SelectObject(&pen);

CBrush brush;

 brush.CreateSolidBrush(RGB(255,0,0));

dc.Rectangle(50,2,250,105);

dc.SelectObject(&brush);

 brush.DeleteObject();

 brush.CreateHatchBrush(0,RGB(2500,0,0));

dc.SelectObject(&brush);

dc.Rectangle(50,150,250,250);

 brush.DeleteObject();

 brush.CreateHatchBrush(HS_CROSS,RGB(2500,0,250));

dc.Rectangle(50,300,250,400);

dc.SelectObject(&brush);

 brush.DeleteObject();

 pen.DeleteObject();

 pen.CreatePen(PS_SOLID,3,RGB(0,255,0));

CBitmap bitmap;

 bitmap.LoadBitmap(IDB_BITMAP1);

 brush.CreatePatternBrush(&bitmap);

Page 28: vp prgm

7/28/2019 vp prgm

http://slidepdf.com/reader/full/vp-prgm 28/78

dc.SelectObject(&brush);

dc.Rectangle(300,5,500,105);

 brush.DeleteObject();

 bitmap.DeleteObject();

 bitmap.LoadBitmap(IDB_BITMAP2);

brush.CreatePatternBrush(&bitmap);

dc.SelectObject(&brush);

dc.Rectangle(300,150,500,250);

 brush.DeleteObject();

 bitmap.DeleteObject();

 bitmap.LoadBitmap(IDB_BITMAP3);

 brush.CreatePatternBrush(&bitmap);

dc.SelectObject(&brush);

dc.Rectangle(300,300,500,400);

 brush.DeleteObject();

 bitmap.DeleteObject();

}

Page 29: vp prgm

7/28/2019 vp prgm

http://slidepdf.com/reader/full/vp-prgm 29/78

OUTPUT

RESULT

The program for drawing different types of brushes using VC++ was done successfully and the

output is verified

Page 30: vp prgm

7/28/2019 vp prgm

http://slidepdf.com/reader/full/vp-prgm 30/78

Page 31: vp prgm

7/28/2019 vp prgm

http://slidepdf.com/reader/full/vp-prgm 31/78

DRAWING DIFFERENT TYPES OF SHAPES USING GDI

void CShapeView::OnDraw(CDC* pDC)

{

CShapeDoc* pDoc = GetDocument();

ASSERT_VALID(pDoc);

 pDC->TextOut(200,50,"Drawing different shapes");

 pDC->MoveTo(200,70);

 pDC->LineTo(405,70);

 pDC->MoveTo(200,73);

 pDC->LineTo(405,73);

 pDC->SelectStockObject(GRAY_BRUSH);

 pDC->Ellipse(200,200,300,300);

 pDC->SelectStockObject(4);

 pDC->RoundRect(400,80,550,200,100,100);

 pDC->Arc(20,90,90,40,40,10,50,70);

 pDC->SelectStockObject (0);

}

Page 32: vp prgm

7/28/2019 vp prgm

http://slidepdf.com/reader/full/vp-prgm 32/78

OUTPUT

RESULT

The program for drawing different types of shapes using GDI was done successfully and the

output is verified

Page 33: vp prgm

7/28/2019 vp prgm

http://slidepdf.com/reader/full/vp-prgm 33/78

SIMPLE DIALOG BASED APPLICATION- CALCULATOR 

void CCalculatorDlg::OnCal()

{

UpdateData(true);

if(m_bAdd==TRUE)

{

m_iresult=m_inum1+m_inum2;

UpdateData(FALSE);

}

else if(m_bSub==TRUE)

{

m_iresult=m_inum1-m_inum2;

UpdateData(FALSE);

}

else if(m_bMul==TRUE)

{

m_iresult=m_inum1*m_inum2;

UpdateData(FALSE);

}

else if(m_bDiv==TRUE)

{

m_iresult=m_inum1/m_inum2;

UpdateData(FALSE);

}

}

Page 34: vp prgm

7/28/2019 vp prgm

http://slidepdf.com/reader/full/vp-prgm 34/78

void CCalculatorDlg::OnClear()

{

m_inum1=0;

m_inum2=0;

m_iresult='0';

m_bAdd=FALSE;

m_bSub=FALSE;

m_bMul=FALSE;

m_bDiv=FALSE;

UpdateData(FALSE);

}

Page 35: vp prgm

7/28/2019 vp prgm

http://slidepdf.com/reader/full/vp-prgm 35/78

OUTPUT

RESULT

The program for simple dialog based application was done successfully and the output is

verified

Page 36: vp prgm

7/28/2019 vp prgm

http://slidepdf.com/reader/full/vp-prgm 36/78

SINGLE DOCUMENT INTERFACE

// SDIView.cpp

#include "stdafx.h"

#include "SDI.h"

#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)

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()

{

}

CSDIView::~CSDIView()

Page 37: vp prgm

7/28/2019 vp prgm

http://slidepdf.com/reader/full/vp-prgm 37/78

{

}

// CSDIView drawing

void CSDIView::OnDraw(CDC* pDC)

{

CSDIDoc* pDoc = GetDocument();

ASSERT_VALID(pDoc);

 pDC->TextOut(0,0,"Hello");

 pDC->SelectStockObject(GRAY_BRUSH);

 pDC->Ellipse(CRect(50,50,100,100));

// TODO: add draw code for native data here

}

// CSDIView printing

BOOL CSDIView::OnPreparePrinting(CPrintInfo* pInfo)

{

return DoPreparePrinting(pInfo);

}

void CSDIView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)

{

}

void CSDIView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)

{

Page 38: vp prgm

7/28/2019 vp prgm

http://slidepdf.com/reader/full/vp-prgm 38/78

}

// CSDIView diagnostics

#ifdef _DEBUG

void CSDIView::AssertValid() const

{

CView::AssertValid();

}

void CSDIView::Dump(CDumpContext& dc) const

{

CView::Dump(dc);

}

CSDIDoc* CSDIView::GetDocument() // non-debug version is inline

{

ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CSDIDoc)));

return (CSDIDoc*)m_pDocument;

}

#endif //_DEBUG

Page 39: vp prgm

7/28/2019 vp prgm

http://slidepdf.com/reader/full/vp-prgm 39/78

OUTPUT

RESULT

The program for single document interface using VC++ was done successfully and the output is

verified

Page 40: vp prgm

7/28/2019 vp prgm

http://slidepdf.com/reader/full/vp-prgm 40/78

Page 41: vp prgm

7/28/2019 vp prgm

http://slidepdf.com/reader/full/vp-prgm 41/78

}

CMDIView::~CMDIView()

{

}

BOOL CMDIView::PreCreateWindow(CREATESTRUCT& cs)

{

return CView::PreCreateWindow(cs);

}

// CMDIView drawing

void CMDIView::OnDraw(CDC* pDC)

{

CMDIDoc* pDoc = GetDocument();

ASSERT_VALID(pDoc);

 pDC->TextOut(0,0,"Hello");

 pDC->SelectStockObject(GRAY_BRUSH);

 pDC->Ellipse(CRect(50,50,100,100));

}

// CMDIView printing

BOOL CMDIView::OnPreparePrinting(CPrintInfo* pInfo)

{

return DoPreparePrinting(pInfo);

}

void CMDIView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)

Page 42: vp prgm

7/28/2019 vp prgm

http://slidepdf.com/reader/full/vp-prgm 42/78

{

}

void CMDIView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)

{

}

// CMDIView diagnostics

#ifdef _DEBUG

void CMDIView::AssertValid() const

{

CView::AssertValid();

}

void CMDIView::Dump(CDumpContext& dc) const

{

CView::Dump(dc);

}

CMDIDoc* CMDIView::GetDocument() // non-debug version is inline

{

ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMDIDoc)));

return (CMDIDoc*)m_pDocument;

}

#endif //_DEBUG

Page 43: vp prgm

7/28/2019 vp prgm

http://slidepdf.com/reader/full/vp-prgm 43/78

OUTPUT

RESULT

The program for multiple document interface using VC++ was done successfully and the output

is verified

Page 44: vp prgm

7/28/2019 vp prgm

http://slidepdf.com/reader/full/vp-prgm 44/78

READING AND WRITING INTO DOCUMENTS

void CReadDoc::Serialize(CArchive& ar)

{ if(ar.IsStoring())

{ ar<<m_sDocName;

ar<<m_sDocGrade;

}

else

{ ar>>m_sDocName;

ar>>m_sDocGrade;

}

}

//ReadView.cpp

void CReadView::OnSave()

{ CReadDoc*pDoc=GetDocument();

UpdateData(true);

 pDoc->m_sDocName=m_sName;

 pDoc->m_sDocGrade=m_sGrade;

 pDoc->SetModifiedFlag(true);

UpdateData(false);

}

void CReadView::OnClear()

{ UpdateData(true);

m_sName=" ";

m_sGrade=" ";

UpdateData(false); }

Page 45: vp prgm

7/28/2019 vp prgm

http://slidepdf.com/reader/full/vp-prgm 45/78

OUTPUT

RESULT

The program for reading and writing into documents using VC++ was done successfully and the

output is verified

Page 46: vp prgm

7/28/2019 vp prgm

http://slidepdf.com/reader/full/vp-prgm 46/78

CREATION OF MODELESS DIALOG

#include<afxwin.h>

#include<afxdlgs.h>

#include "resource.h"

class mydlg:public CDialog

{

 public:

mydlg():CDialog()

{}

 public:

BOOL OnInitDialog()

{

return TRUE;

}

void circle()

{

CClientDC d(this);

CBrush mybrush(RGB(255,0,0));

d.SelectObject(&mybrush);

d.Ellipse(10,10,300,300);

MessageBox("circle clicked","circle");

}

void square()

{

CClientDC d(this);

Page 47: vp prgm

7/28/2019 vp prgm

http://slidepdf.com/reader/full/vp-prgm 47/78

CBrush mybrush(RGB(255,0,0));

d.SelectObject(&mybrush);

d.Rectangle(10,10,300,300);

MessageBox("square clicked","square");

}

void OnOk()

{

EndDialog(TRUE);

}

void OnCancel()

{

EndDialog(FALSE);

}

DECLARE_MESSAGE_MAP()

};

BEGIN_MESSAGE_MAP(mydlg,CDialog)

ON_COMMAND(101,circle)

ON_COMMAND(102,square)

END_MESSAGE_MAP()

class mywin:public CFrameWnd

{

 public:

mywin()

{

Create(0,"MFC_WINDOW");

Page 48: vp prgm

7/28/2019 vp prgm

http://slidepdf.com/reader/full/vp-prgm 48/78

}

void OnRButtonDown()

{

CDialog *dlg;

dlg=new mydlg();

dlg->Create(IDD_DIALOG1);

dlg->ShowWindow(1);

}

DECLARE_MESSAGE_MAP()

};

BEGIN_MESSAGE_MAP(mywin,CFrameWnd)

ON_WM_RBUTTONDOWN()

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;

Page 49: vp prgm

7/28/2019 vp prgm

http://slidepdf.com/reader/full/vp-prgm 49/78

OUTPUT

RESULT

The program for creation of modeless dialog using VC++ was done successfully and the output

is verified

Page 50: vp prgm

7/28/2019 vp prgm

http://slidepdf.com/reader/full/vp-prgm 50/78

PROGRESS CONTROL

#include<afxwin.h>

#include<afxcmn.h>

#include "resource.h"

class sortdialog:public CDialog

{

 private:

CString fname;

 public:

sortdialog(int n):CDialog(n)

{

fname="Enter file to be sorted";

}

void DoDataExchange(CDataExchange *p)

{

DDX_Text(p,IDC_EDIT1,fname);

MessageBox(fname,"hai");

}

void OnOk()

{

CString str[100],temp;

CStdioFile fp,fw;

CProgressCtrl *c;

UpdateData(TRUE);

int count=0;

Page 51: vp prgm

7/28/2019 vp prgm

http://slidepdf.com/reader/full/vp-prgm 51/78

MessageBox("hai inside on ok");

c=(CProgressCtrl *)GetDlgItem(IDC_PROGRESS1);

c->SetStep(5);

if(fp.Open(fname,CFile::modeReadWrite))

{

fp.SeekToBegin();

while(fp.ReadString(str[count])!=NULL)

count++;

for(int j=0;j<count-1;j++)

{

for(int k=j+1;k<count;k++)

{

if(str[j]>str[k])

{

temp=str[j];

str[j]=str[k];

str[k]=temp;

}

}

c->StepIt();

Sleep(100);

}

fp.SeekToBegin();

fw.Open("sorted.txt",CFile::modeReadWrite);

for(int i=0;i<count;i++)

Page 52: vp prgm

7/28/2019 vp prgm

http://slidepdf.com/reader/full/vp-prgm 52/78

{

fw.WriteString(str[i]);

}

fp.Close();

fw.Close();

}

else

MessageBox(fname,"cannot open file");

EndDialog(IDOK);

}

DECLARE_MESSAGE_MAP()

};

BEGIN_MESSAGE_MAP(sortdialog,CDialog)

ON_COMMAND(IDOK,OnOk)

END_MESSAGE_MAP()

class myframe:public CFrameWnd

{

 public:

myframe()

{

Create(0,"progressbar",WS_OVERLAPPEDWINDOW,rectDefault,0,MAKEINTRESOURCE(I

DR_MENU1));

}

void sort()

Page 53: vp prgm

7/28/2019 vp prgm

http://slidepdf.com/reader/full/vp-prgm 53/78

{

sortdialog *d;

d=new sortdialog(IDD_DIALOG1);

d->DoModal();

}

DECLARE_MESSAGE_MAP()

};

BEGIN_MESSAGE_MAP(myframe,CFrameWnd)

ON_COMMAND(101,sort)

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;

Page 54: vp prgm

7/28/2019 vp prgm

http://slidepdf.com/reader/full/vp-prgm 54/78

OUTPUT

RESULT

The program for progress control using VC++ was done successfully and the output is verified

Page 55: vp prgm

7/28/2019 vp prgm

http://slidepdf.com/reader/full/vp-prgm 55/78

Page 56: vp prgm

7/28/2019 vp prgm

http://slidepdf.com/reader/full/vp-prgm 56/78

TREEVIEW

#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("GC",c);

tree.InsertItem("MSC",c);

cpp=tree.InsertItem("C++",lang,TVI_SORT);

Page 57: vp prgm

7/28/2019 vp prgm

http://slidepdf.com/reader/full/vp-prgm 57/78

tree.InsertItem("VC++",cpp);

tree.InsertItem("Borland C++",cpp);

 java=tree.InsertItem("java",lang,TVI_SORT);

tree.InsertItem("VJ++",java);

tree.InsertItem("Symantec.cafe",java);

tree.InsertItem("sun.JDK",java);

opersys=tree.InsertItem("Operating system",TVI_ROOT,TVI_SORT);

tree.InsertItem("win3.1",opersys);

tree.InsertItem("win 95",opersys);

tree.InsertItem("winNT",opersys);

return 0;

}

int OnNotify(WPARAM W,LPARAM I,LRESULT *r)

{

HTREEITEM h;

CString str;

CWnd::OnNotify(W,I,r);

 NM_TREEVIEW*p=(NM_TREEVIEW*)I;

if(p->hdr.code==TVN_SELCHANGED)

{

h=tree.GetSelectedItem();

str=tree.GetItemText(h);

MessageBox(str,"you have selected");

}

Page 58: vp prgm

7/28/2019 vp prgm

http://slidepdf.com/reader/full/vp-prgm 58/78

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;

Page 59: vp prgm

7/28/2019 vp prgm

http://slidepdf.com/reader/full/vp-prgm 59/78

OUTPUT

RESULT

The program for tree view using VC++ was done successfully and the output is verified

Page 60: vp prgm

7/28/2019 vp prgm

http://slidepdf.com/reader/full/vp-prgm 60/78

SLIDER CONTROL

#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("SLIDERDISPLAY",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);

Page 61: vp prgm

7/28/2019 vp prgm

http://slidepdf.com/reader/full/vp-prgm 61/78

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;

Page 62: vp prgm

7/28/2019 vp prgm

http://slidepdf.com/reader/full/vp-prgm 62/78

}

}

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;

Page 63: vp prgm

7/28/2019 vp prgm

http://slidepdf.com/reader/full/vp-prgm 63/78

OUTPUT

RESULT

The program for slider control using VC++ was done successfully and the output is verified

Page 64: vp prgm

7/28/2019 vp prgm

http://slidepdf.com/reader/full/vp-prgm 64/78

SPLITTER WINDOW

// Splitter1Doc.cpp : implementation of the CSplitter1Doc class

#include "stdafx.h"

#include "Splitter1.h"

#include "Splitter1Doc.h"

#ifdef _DEBUG

#define new DEBUG_NEW

#undef THIS_FILE

static char THIS_FILE[] = __FILE__;

#endif 

// CSplitter1Doc

IMPLEMENT_DYNCREATE(CSplitter1Doc, CDocument)

BEGIN_MESSAGE_MAP(CSplitter1Doc, CDocument)

//{{AFX_MSG_MAP(CSplitter1Doc)

// 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()

// CSplitter1Doc construction/destruction

CSplitter1Doc::CSplitter1Doc()

{

}

CSplitter1Doc::~CSplitter1Doc()

{

}

Page 65: vp prgm

7/28/2019 vp prgm

http://slidepdf.com/reader/full/vp-prgm 65/78

BOOL CSplitter1Doc::OnNewDocument()

{

if (!CDocument::OnNewDocument())

return FALSE;

return TRUE;

}

// CSplitter1Doc serialization

void CSplitter1Doc::Serialize(CArchive& ar)

{

if (ar.IsStoring())

{

}

else

{

}

}

// CSplitter1Doc diagnostics

#ifdef _DEBUG

void CSplitter1Doc::AssertValid() const

{ CDocument::AssertValid();

}

void CSplitter1Doc::Dump(CDumpContext& dc) const

{ CDocument::Dump(dc);

}#endif //_DEBUG

Page 66: vp prgm

7/28/2019 vp prgm

http://slidepdf.com/reader/full/vp-prgm 66/78

OUTPUT

RESULT

The program for splitter windows using VC++ was done successfully and the output is verified

Page 67: vp prgm

7/28/2019 vp prgm

http://slidepdf.com/reader/full/vp-prgm 67/78

OUTPUT

Page 68: vp prgm

7/28/2019 vp prgm

http://slidepdf.com/reader/full/vp-prgm 68/78

OUTPUT

Page 69: vp prgm

7/28/2019 vp prgm

http://slidepdf.com/reader/full/vp-prgm 69/78

CREATING ACTIVEX CONTROL

// activexDlg.cpp : implementation file

//

#include "stdafx.h"

#include "activex.h"

#include "activexDlg.h"

#ifdef _DEBUG

#define new DEBUG_NEW

#undef THIS_FILE

static char THIS_FILE[] = __FILE__;

#endif 

/////////////////////////////////////////////////////////////////////////////

// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog

{

 public:

CAboutDlg();

// Dialog Data

//{{AFX_DATA(CAboutDlg)

enum { IDD = IDD_ABOUTBOX };

//}}AFX_DATA

Page 70: vp prgm

7/28/2019 vp prgm

http://slidepdf.com/reader/full/vp-prgm 70/78

// ClassWizard generated virtual function overrides

//{{AFX_VIRTUAL(CAboutDlg)

 protected:

virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support

//}}AFX_VIRTUAL

// Implementation

 protected:

//{{AFX_MSG(CAboutDlg)

//}}AFX_MSG

DECLARE_MESSAGE_MAP()

};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)

{

//{{AFX_DATA_INIT(CAboutDlg)

//}}AFX_DATA_INIT

}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)

{

CDialog::DoDataExchange(pDX);

//{{AFX_DATA_MAP(CAboutDlg)

//}}AFX_DATA_MAP

}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)

//{{AFX_MSG_MAP(CAboutDlg)

Page 71: vp prgm

7/28/2019 vp prgm

http://slidepdf.com/reader/full/vp-prgm 71/78

// No message handlers

//}}AFX_MSG_MAP

END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////

// CActivexDlg dialog

CActivexDlg::CActivexDlg(CWnd* pParent /*=NULL*/)

: CDialog(CActivexDlg::IDD, pParent)

{

//{{AFX_DATA_INIT(CActivexDlg)

// NOTE: the ClassWizard will add member initialization here

//}}AFX_DATA_INIT

// Note that LoadIcon does not require a subsequent DestroyIcon in Win32

m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);

}

void CActivexDlg::DoDataExchange(CDataExchange* pDX)

{

CDialog::DoDataExchange(pDX);

//{{AFX_DATA_MAP(CActivexDlg)

DDX_Control(pDX, IDC_CALENDAR1, m_calender);

//}}AFX_DATA_MAP

}

BEGIN_MESSAGE_MAP(CActivexDlg, CDialog)

//{{AFX_MSG_MAP(CActivexDlg)

ON_WM_SYSCOMMAND()

ON_WM_PAINT()

Page 72: vp prgm

7/28/2019 vp prgm

http://slidepdf.com/reader/full/vp-prgm 72/78

ON_WM_QUERYDRAGICON()

ON_BN_CLICKED(IDC_BUTTON1, OnNextMonth)

ON_BN_CLICKED(IDC_BUTTON2, OnPrevMonth)

ON_BN_CLICKED(IDC_BUTTON3, OnNextYear)

ON_BN_CLICKED(IDC_BUTTON4, OnPrevYear)

ON_BN_CLICKED(IDC_BUTTON5, OnTomorrow)

ON_BN_CLICKED(IDC_BUTTON6, OnYesterday)

ON_BN_CLICKED(IDC_BUTTON7, OnNextWeek)

ON_BN_CLICKED(IDC_BUTTON8, OnPrevWeek)

//}}AFX_MSG_MAP

END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////

// CActivexDlg message handlers

BOOL CActivexDlg::OnInitDialog()

{

CDialog::OnInitDialog();

// Add "About..." menu item to system menu.

// IDM_ABOUTBOX must be in the system command range.

ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);

ASSERT(IDM_ABOUTBOX < 0xF000);

CMenu* pSysMenu = GetSystemMenu(FALSE);

Page 73: vp prgm

7/28/2019 vp prgm

http://slidepdf.com/reader/full/vp-prgm 73/78

if (pSysMenu != NULL)

{

CString strAboutMenu;

strAboutMenu.LoadString(IDS_ABOUTBOX);

if (!strAboutMenu.IsEmpty())

{

 pSysMenu->AppendMenu(MF_SEPARATOR);

 pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX,

strAboutMenu);

}

}

// Set the icon for this dialog. The framework does this automatically

// when the application's main window is not a dialog

SetIcon(m_hIcon, TRUE); // Set big icon

SetIcon(m_hIcon, FALSE); // Set small icon

// TODO: Add extra initialization here

return TRUE; // return TRUE unless you set the focus to a control

}

void CActivexDlg::OnSysCommand(UINT nID, LPARAM lParam)

{

if ((nID & 0xFFF0) == IDM_ABOUTBOX)

Page 74: vp prgm

7/28/2019 vp prgm

http://slidepdf.com/reader/full/vp-prgm 74/78

Page 75: vp prgm

7/28/2019 vp prgm

http://slidepdf.com/reader/full/vp-prgm 75/78

CRect rect;

GetClientRect(&rect);

int x = (rect.Width() - cxIcon + 1) / 2;

int y = (rect.Height() - cyIcon + 1) / 2;

// Draw the icon

dc.DrawIcon(x, y, m_hIcon);

}

else

{

CDialog::OnPaint();

}

}

// The system calls this to obtain the cursor to display while the user drags

// the minimized window.

HCURSOR CActivexDlg::OnQueryDragIcon()

{

return (HCURSOR) m_hIcon;

}

void CActivexDlg::OnNextMonth()

{

m_calender.NextMonth();

}

Page 76: vp prgm

7/28/2019 vp prgm

http://slidepdf.com/reader/full/vp-prgm 76/78

Page 77: vp prgm

7/28/2019 vp prgm

http://slidepdf.com/reader/full/vp-prgm 77/78

void CActivexDlg::OnPrevWeek()

{

m_calender.PreviousWeek();

}

void CActivexDlg::OnCancel()

{

CDialog::OnCancel();

}

Page 78: vp prgm

7/28/2019 vp prgm

http://slidepdf.com/reader/full/vp-prgm 78/78

OUTPUT

RESULT