Вы находитесь на странице: 1из 14

PROGRAM NO:

AIM: Write a program to display a message with document view architecture


STEPS:
1. Open Visual C++ from with in Microsoft Visual Studio.
2. In the new file menu, select new project.
3. click on project, select MFC Application wizard[exe].
4. Write the name of the project and location in the respective places.
5. Click next and finish.

Source code:

In “welcomeDoc.h”

class CWelcomeDoc : public CDocument


{
protected: // create from serialization only
CWelcomeDoc();
DECLARE_DYNCREATE(CWelcomeDoc)
public:
CString kavita;
}

In “welcomeDoc.cpp”

CWelcomeDoc::CWelcomeDoc()
{
kavita="***Welcome to vc++***";
// TODO: add one-time construction code here

In “welcomeView.cpp”

void CWelcomeView::OnDraw(CDC* pDC)


{
CWelcomeDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
pDC->TextOut(0,0,pDoc->kavita);
// TODO: add draw code for native data here
}
Screen Shots:
PROGRAM NO:

AIM: Write a program to display a message without using document view


architecture

STEPS:
1. Open Visual C++ from with in Microsoft Visual Studio.
2. In the new file menu, select new project.
3. click on project, select MFC Application wizard[exe].
4. Write the name of the project and location in the respective places.
5. Click next and finish.
6. Do the coding as follows

Source code:

In “welcome2View.cpp”

void CWelcome2View::OnDraw(CDC* pDC)


{
CWelcome2Doc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
CString aditya;
aditya="WELCOME TO VC++";
pDC->TextOut(0,0,aditya);
// TODO: add draw code for native data here
}
Screen Shots:
PROGRAM NO:

AIM: Write a program to input string from the user using OnChar function

STEPS:
1. Open Visual C++ from with in Microsoft Visual Studio.
2. In the new file menu, select new project.
3. click on project, select MFC Application wizard[exe].
4. Write the name of the project and location in the respective places.
5. Click next and finish.
6. Do the coding as folows

Source code:

In “kavita3Doc.h”

class CKavita3Doc : public CDocument


{
public:
CString kavita;
}

In “kavita3Doc.cpp”

CKavita3Doc::CKavita3Doc()
{
kavita="";
}
In “kavita3View.cpp”

void CKavita3View::OnDraw(CDC* pDC)


{
CKavita3Doc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
pDC->TextOut(0,0,pDoc->kavita);
}
void CKavita3View::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
CKavita3Doc* pDoc = GetDocument();
ASSERT_VALID(pDoc);

pDoc->kavita+=nChar;
Invalidate();
CView::OnChar(nChar, nRepCnt, nFlags);
}
Screen Shots :
PROGRAM NO:

AIM: Write a program to input string from the user using OnChar function
And display it at the center
STEPS:
1. Open Visual C++ from with in Microsoft Visual Studio.
2. In the new file menu, select new project.
3. click on project, select MFC Application wizard[exe].
4. Write the name of the project and location in the respective places.
5. Click next and finish.
6. Do the coding as folows

Source code:

In “centerDoc.h”

class CCenterDoc : public CDocument


{public:
CString kavita;}

In “centerDoc.cpp”

CCenterDoc::CCenterDoc()
{ kavita="";}

}In “centerView.cpp”

void CCenterView::OnDraw(CDC* pDC)


{ CCenterDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
CRect rect;
GetWindowRect(rect);
int x=rect.Width()/2;
int y=rect.Height()/2;
CSize size=pDC->GetTextExtent(pDoc->kavita);
x-=size.cx/2;
y-=size.cy/2;
pDC->TextOut(x,y,pDoc->kavita);
}void CCenterView::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{ CenterDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
pDoc->kavita+=nChar;
Invalidate();
CView::OnChar(nChar, nRepCnt, nFlags);
}
Screen Shots :
PROGRAM NO:

AIM: Write a program to display message in the text box while clicking on button
STEPS:
1. Open Visual C++ from with in Microsoft Visual Studio.
2. In the new file menu, select new project.
3. click on project, select MFC Application wizard[exe].
4. Write the name of the project and location in the respective places.
5. For the project type select Dialogue based
6. Click next and finish.
7. Drag and drop a button and a text box.
8. Goto ->view->class Wizard->member variables,
9. Make new variable for text box named m_text.
10. Click on the button and do the coding as folows

Source code:

In “button_textDlg.cpp”

void CButton_textDlg::OnButton1()
{
m_text.SetWindowText(CString("***WELCOME TO MY DIALOGUE***"));
// TODO: Add your control notification handler code here

}
Screen Shots :
PROGRAM NO:

AIM: Write a program to display message in the text box while double clicking on
list item or selecting an item from combo box
STEPS:
11. Open Visual C++ from with in Microsoft Visual Studio.
12. In the new file menu, select new project.
13. click on project, select MFC Application wizard[exe].
14. Write the name of the project and location in the respective places.
15. For the project type select Dialogue based
16. Click next and finish.
17. Drag and drop a list box, combo box and a text box.
18. Goto ->view->class Wizard.
19. Select object ids for combo1 and list1 and set their messages to CBN_SELCHANGE and
LBN_DBLCLK.
20. Goto member variables and make variables for text box as string and other two as
control. Write coding as.

Source code:

In “combo_listDlg.cpp”

BOOL CCombo_listDlg::OnInitDialog()
{
CDialog::OnInitDialog();
m_combo.AddString("combo1");
m_combo.AddString("combo2");
m_combo.AddString("combo3");
m_combo.AddString("combo4");
m_list.AddString("list1");
m_list.AddString("list2");
m_list.AddString("list3");
m_list.AddString("list4");
}
void CCombo_listDlg::OnSelchangeCombo1()
{
m_combo.GetLBText(m_combo.GetCurSel(),m_text);
UpdateData(false);
}
void CCombo_listDlg::OnDblclkList1()
{
m_list.GetText(m_list.GetCurSel(),m_text);
UpdateData(false);
}
Screen Shots :
PROGRAM NO:
Aim :- Short note on Visual C++
VISUAL C++ is a high level programming language which evolved from the earlier C++
version called Turbo c++. It is a very easy programming language to learn who knows C++. The
code look a lot like English Language.

VISUAL C++ is a VISUAL and events driven Programming Language. These are the main
divergence from the old C++. In C++ programming is done in a text-only environment and the
program is executed sequentially. In VC++, programming is done in a graphical environment. In
the C++, you have to write program code for each graphical object you wish to create and you
need to make it fictitiously and display it on screen, including its position and its color. However,
In VC++ , you just need to drag and drop any graphical object anywhere on the form, and you
can change its color any time using the properties windows.

Features of Visual C++

 Full set of objects - you 'draw' the application


 Lots of icons and pictures for your use
 Response to mouse and keyboard actions
 Clipboard and printer access
 Full array of mathematical, string handling, and graphics functions
 Can handle fixed and dynamic variable and control arrays
 Sequential and random access file support
 Useful debugger and error-handling facilities
 Powerful database access tools
 Package & Deployment Wizard makes distributing your applications simple
Openening a new project :

A new project is opened as follows. From the file menu click new and then select new project of
whichever category is needed.

Вам также может понравиться