0% found this document useful (0 votes)
48 views

F C S M: in Doc.H: Project Name: Menubar

Project Name: MenuBar FOR CLEAR SUB MENU: In Doc.h // MenuBarDoc.h : interface of the CMenuBarDoc class #if ! defined(AFX_MENUBARDOC_H__AE9845FD_1CE5_4C6A_A189_034CCF5F5AFC__IN CLUDED_) #define AFX_MENUBARDOC_H__AE9845FD_1CE5_4C6A_A189_034CCF5F5AFC__INCLUDED _ #if _MSC_VER > 1000 #pragma once #endif // _MSC_VER > 1000 class CMenuBarDoc : public CDocument { protected: // create from serialization only CMenuBarDoc(); DECLARE_DYNCREATE(CMenuBarDoc) // Attributes public: CString m_str; // Operations

Uploaded by

michael.ferraris
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
48 views

F C S M: in Doc.H: Project Name: Menubar

Project Name: MenuBar FOR CLEAR SUB MENU: In Doc.h // MenuBarDoc.h : interface of the CMenuBarDoc class #if ! defined(AFX_MENUBARDOC_H__AE9845FD_1CE5_4C6A_A189_034CCF5F5AFC__IN CLUDED_) #define AFX_MENUBARDOC_H__AE9845FD_1CE5_4C6A_A189_034CCF5F5AFC__INCLUDED _ #if _MSC_VER > 1000 #pragma once #endif // _MSC_VER > 1000 class CMenuBarDoc : public CDocument { protected: // create from serialization only CMenuBarDoc(); DECLARE_DYNCREATE(CMenuBarDoc) // Attributes public: CString m_str; // Operations

Uploaded by

michael.ferraris
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 9

Project Name: MenuBar

FOR CLEAR SUB MENU:


In Doc.h

// MenuBarDoc.h : interface of the CMenuBarDoc class

#if !
defined(AFX_MENUBARDOC_H__AE9845FD_1CE5_4C6A_A189_034CCF5F5AFC__I
NCLUDED_)
#define
AFX_MENUBARDOC_H__AE9845FD_1CE5_4C6A_A189_034CCF5F5AFC__INCLUD
ED_

#if _MSC_VER > 1000


#pragma once
#endif // _MSC_VER > 1000

class CMenuBarDoc : public CDocument


{
protected: // create from serialization only
CMenuBarDoc();
DECLARE_DYNCREATE(CMenuBarDoc)

// Attributes
public:
CString m_str;
// Operations
public:

// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CMenuBarDoc)
public:
virtual BOOL OnNewDocument();
virtual void Serialize(CArchive& ar);
//}}AFX_VIRTUAL

// Implementation
public:
virtual ~CMenuBarDoc();
#ifdef _DEBUG
virtual void AssertValid() const;
virtual void Dump(CDumpContext& dc) const;
#endif

protected:

// Generated message map functions


protected:
//{{AFX_MSG(CMenuBarDoc)
afx_msg void OnEditClear();
afx_msg void OnUpdateEditClear(CCmdUI* pCmdUI);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the
previous line.

#endif // !
defined(AFX_MENUBARDOC_H__AE9845FD_1CE5_4C6A_A189_034CCF5F5AFC__I
NCLUDED_)

In Doc.cpp

// MenuBarDoc.cpp : implementation of the CMenuBarDoc class


//

#include "stdafx.h"
#include "MenuBar.h"

#include "MenuBarDoc.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

// CMenuBarDoc

IMPLEMENT_DYNCREATE(CMenuBarDoc, CDocument)

BEGIN_MESSAGE_MAP(CMenuBarDoc, CDocument)
//{{AFX_MSG_MAP(CMenuBarDoc)
ON_COMMAND(ID_EDIT_CLEAR, OnEditClear)
ON_UPDATE_COMMAND_UI(ID_EDIT_CLEAR, OnUpdateEditClear)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

// CMenuBarDoc construction/destruction

CMenuBarDoc::CMenuBarDoc()
{
// TODO: add one-time construction code here

CMenuBarDoc::~CMenuBarDoc()
{
}
BOOL CMenuBarDoc::OnNewDocument()
{
if (!CDocument::OnNewDocument())
return FALSE;
m_str="hello";
return TRUE;
}

// CMenuBarDoc serialization

void CMenuBarDoc::Serialize(CArchive& ar)


{
if (ar.IsStoring())
{
// TODO: add storing code here
}
else
{
// TODO: add loading code here
}
}

// CMenuBarDoc diagnostics

#ifdef _DEBUG
void CMenuBarDoc::AssertValid() const
{
CDocument::AssertValid();
}

void CMenuBarDoc::Dump(CDumpContext& dc) const


{
CDocument::Dump(dc);
}
#endif //_DEBUG

// CMenuBarDoc commands

void CMenuBarDoc::OnEditClear()
{
m_str.Empty();
}

void CMenuBarDoc::OnUpdateEditClear(CCmdUI* pCmdUI)


{
pCmdUI->Enable(!m_str.IsEmpty());
}
FOR EDIT CONTROL:
In View.h

// MenuBarView.h : interface of the CMenuBarView class

#if !
defined(AFX_MENUBARVIEW_H__2326118B_AED0_4940_94D1_61D55F69E218__I
NCLUDED_)
#define
AFX_MENUBARVIEW_H__2326118B_AED0_4940_94D1_61D55F69E218__INCLUD
ED_

#if _MSC_VER > 1000


#pragma once
#endif // _MSC_VER > 1000

class CMenuBarView : public CView


{
protected: // create from serialization only
CMenuBarView();
DECLARE_DYNCREATE(CMenuBarView)

// Attributes
public:
CRichEditCtrl m_rich;
CMenuBarDoc* GetDocument();

// Operations
public:

// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CMenuBarView)
public:
virtual void OnDraw(CDC* pDC); // overridden to draw this view
virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
protected:
virtual BOOL OnPreparePrinting(CPrintInfo* pInfo);
virtual void OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo);
virtual void OnEndPrinting(CDC* pDC, CPrintInfo* pInfo);
//}}AFX_VIRTUAL

// Implementation
public:
virtual ~CMenuBarView();
#ifdef _DEBUG
virtual void AssertValid() const;
virtual void Dump(CDumpContext& dc) const;
#endif

protected:
// Generated message map functions
protected:
//{{AFX_MSG(CMenuBarView)
afx_msg void OnSize(UINT nType, int cx, int cy);
afx_msg void OnTranferGetdatafromdoc();
afx_msg void OnTranferStoredatatodoc();
afx_msg void OnContextMenu(CWnd* pWnd, CPoint point);
afx_msg void OnColorGreen();
afx_msg void OnColorRed();
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
afx_msg void OnUpdateTranferStoredatatodoc(CCmdUI* pCmdUI);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};

#ifndef _DEBUG // debug version in MenuBarView.cpp


inline CMenuBarDoc* CMenuBarView::GetDocument()
{ return (CMenuBarDoc*)m_pDocument; }
#endif

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the
previous line.

#endif // !
defined(AFX_MENUBARVIEW_H__2326118B_AED0_4940_94D1_61D55F69E218__I
NCLUDED_)

In View.cpp

// MenuBarView.cpp : implementation of the CMenuBarView class


//

#include "stdafx.h"
#include "MenuBar.h"

#include "MenuBarDoc.h"
#include "MenuBarView.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

// CMenuBarView

IMPLEMENT_DYNCREATE(CMenuBarView, CView)

BEGIN_MESSAGE_MAP(CMenuBarView, CView)
//{{AFX_MSG_MAP(CMenuBarView)
ON_WM_SIZE()
ON_COMMAND(ID_TRANFER_GETDATAFROMDOC,
OnTranferGetdatafromdoc)
ON_COMMAND(ID_TRANFER_STOREDATATODOC,
OnTranferStoredatatodoc)
ON_WM_CONTEXTMENU()
ON_COMMAND(ID_COLOR_GREEN, OnColorGreen)
ON_COMMAND(ID_COLOR_RED, OnColorRed)
ON_WM_CREATE()
ON_UPDATE_COMMAND_UI(ID_TRANFER_STOREDATATODOC,
OnUpdateTranferStoredatatodoc)
//}}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()

// CMenuBarView construction/destruction

CMenuBarView::CMenuBarView()
{
// TODO: add construction code here

CMenuBarView::~CMenuBarView()
{
}

BOOL CMenuBarView::PreCreateWindow(CREATESTRUCT& cs)


{
return CView::PreCreateWindow(cs);
}

// CMenuBarView drawing

void CMenuBarView::OnDraw(CDC* pDC)


{
CMenuBarDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
}

// CMenuBarView printing

BOOL CMenuBarView::OnPreparePrinting(CPrintInfo* pInfo)


{
// default preparation
return DoPreparePrinting(pInfo);
}

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


{

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


{
// TODO: add cleanup after printing
}

// CMenuBarView diagnostics

#ifdef _DEBUG
void CMenuBarView::AssertValid() const
{
CView::AssertValid();
}

void CMenuBarView::Dump(CDumpContext& dc) const


{
CView::Dump(dc);
}

CMenuBarDoc* CMenuBarView::GetDocument() // non-debug version is inline


{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMenuBarDoc)));
return (CMenuBarDoc*)m_pDocument;
}
#endif //_DEBUG

// CMenuBarView message handlers

void CMenuBarView::OnSize(UINT nType, int cx, int cy)


{
CView::OnSize(nType, cx, cy);
m_rich.SetWindowPos(&wndTop,0,0,400,400,SWP_SHOWWINDOW);
// TODO: Add your message handler code here
}

void CMenuBarView::OnTranferGetdatafromdoc()
{
// TODO: Add your command handler code here
CMenuBarDoc *pDOC=GetDocument();
m_rich.SetWindowText(pDOC->m_str);
m_rich.SetModify(FALSE);
}

void CMenuBarView::OnTranferStoredatatodoc()
{
// TODO: Add your command handler code here
CMenuBarDoc *pDOC=GetDocument();
m_rich.GetWindowText(pDOC->m_str);
m_rich.SetModify(FALSE);
}
FOR POP MENU:

void CMenuBarView::OnContextMenu(CWnd* pWnd, CPoint point)


{
// TODO: Add your message handler code here
CMenu menu;
menu.LoadMenu(IDR_MENU1);
menu.GetSubMenu(0)-
>TrackPopupMenu(TPM_LEFTALIGN,point.x,point.y,this);
}

void CMenuBarView::OnColorGreen()
{
// TODO: Add your command handler code here
CDC *pDC=GetDC();
pDC->SetTextColor(RGB(0,255,0));
pDC->TextOut(100,100,"VC++");
ReleaseDC(pDC);
}
void CMenuBarView::OnColorRed()
{
// TODO: Add your command handler code here
CDC *pDC=GetDC();
pDC->SetTextColor(RGB(255,0,0));
pDC->TextOut(100,100,"VC++");
ReleaseDC(pDC);
}
int CMenuBarView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CView::OnCreate(lpCreateStruct) == -1)
return -1;
CRect rect(0,0,0,0);
m_rich.Create(ES_MULTILINE|WS_VISIBLE|WS_VSCROLL,rect,this,1);
// TODO: Add your specialized creation code here

return 0;
}
void CMenuBarView::OnUpdateTranferStoredatatodoc(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->Enable(m_rich.GetModify());
}
OUTPUT

You might also like