F C S M: in Doc.H: Project Name: Menubar
F C S M: in Doc.H: Project Name: Menubar
#if !
defined(AFX_MENUBARDOC_H__AE9845FD_1CE5_4C6A_A189_034CCF5F5AFC__I
NCLUDED_)
#define
AFX_MENUBARDOC_H__AE9845FD_1CE5_4C6A_A189_034CCF5F5AFC__INCLUD
ED_
// 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:
//{{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
#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
// CMenuBarDoc diagnostics
#ifdef _DEBUG
void CMenuBarDoc::AssertValid() const
{
CDocument::AssertValid();
}
// CMenuBarDoc commands
void CMenuBarDoc::OnEditClear()
{
m_str.Empty();
}
#if !
defined(AFX_MENUBARVIEW_H__2326118B_AED0_4940_94D1_61D55F69E218__I
NCLUDED_)
#define
AFX_MENUBARVIEW_H__2326118B_AED0_4940_94D1_61D55F69E218__INCLUD
ED_
// 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()
};
//{{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
#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()
{
}
// CMenuBarView drawing
// CMenuBarView printing
// CMenuBarView diagnostics
#ifdef _DEBUG
void CMenuBarView::AssertValid() const
{
CView::AssertValid();
}
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::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