用VS2010 MFC
.设计单文档窗口程序,满足以下要求:
(1)带有快捷菜单,包括Line、Ellipse、Rectangle菜单项;
(2)点击其中某个菜单项后,在客户区输出相应图形;
(3)图形类型与坐标可保存在文档中。
2.设计单文档窗口程序,满足以下要求:
(1)在主菜单中增加一个菜单项,点击该菜单项后,打开一个对话框;
(2)在该对话框中,有一个编辑框控件,其中可输入文本;
(3)点击“确定”按钮后,关闭对话框,并在客户区输出编辑框控件内容。
用VS2010 MFC
.设计单文档窗口程序,满足以下要求:
(1)带有快捷菜单,包括Line、Ellipse、Rectangle菜单项;
(2)点击其中某个菜单项后,在客户区输出相应图形;
(3)图形类型与坐标可保存在文档中。
2.设计单文档窗口程序,满足以下要求:
(1)在主菜单中增加一个菜单项,点击该菜单项后,打开一个对话框;
(2)在该对话框中,有一个编辑框控件,其中可输入文本;
(3)点击“确定”按钮后,关闭对话框,并在客户区输出编辑框控件内容。
其他人如果需要,从 https://download.csdn.net/download/caozhy/11115001 下载
// Q756748View.cpp : implementation of the CQ756748View class
//
#include "stdafx.h"
// SHARED_HANDLERS can be defined in an ATL project implementing preview, thumbnail
// and search filter handlers and allows sharing of document code with that project.
#ifndef SHARED_HANDLERS
#include "Q756748.h"
#endif
#include "Q756748Doc.h"
#include "Q756748View.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// CQ756748View
IMPLEMENT_DYNCREATE(CQ756748View, CView)
BEGIN_MESSAGE_MAP(CQ756748View, CView)
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, &CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, &CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, &CQ756748View::OnFilePrintPreview)
ON_WM_CONTEXTMENU()
ON_WM_RBUTTONUP()
ON_COMMAND(ID_CONTEXT_ELLIPSE, &CQ756748View::OnContextEllipse)
ON_COMMAND(ID_CONTEXT_LINE, &CQ756748View::OnContextLine)
ON_COMMAND(ID_CONTEXT_RECTANGLE, &CQ756748View::OnContextRectangle)
END_MESSAGE_MAP()
// CQ756748View construction/destruction
CQ756748View::CQ756748View()
{
// TODO: add construction code here
}
CQ756748View::~CQ756748View()
{
}
BOOL CQ756748View::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
// CQ756748View drawing
void CQ756748View::OnDraw(CDC * pDC)
{
CQ756748Doc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
if (!pDoc)
return;
// TODO: add draw code for native data here
Shape * list = pDoc->shapelist;
CPen pen;
pen.CreatePen(PS_SOLID, 1, RGB(255, 0, 0));
CPen *oldPen;
CRect rect;
while (list != NULL)
{
switch (list->type)
{
case 0:
pDC->SelectObject(pen);
pDC->MoveTo(list->a, list->b);
pDC->LineTo(list->c, list->d);
break;
case 2:
rect = CRect(list->a, list->b, list->c, list->d);
pDC->SelectObject(pen);
pDC->Rectangle(&rect);
break;
case 1:
rect = CRect(list->a, list->b, list->c, list->d);
pDC->SelectObject(pen);
pDC->Ellipse(&rect);
break;
}
list = list->next;
}
}
// CQ756748View printing
void CQ756748View::OnFilePrintPreview()
{
#ifndef SHARED_HANDLERS
AFXPrintPreview(this);
#endif
}
BOOL CQ756748View::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CQ756748View::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CQ756748View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
void CQ756748View::OnRButtonUp(UINT /* nFlags */, CPoint point)
{
ClientToScreen(&point);
OnContextMenu(this, point);
}
void CQ756748View::OnContextMenu(CWnd* /* pWnd */, CPoint point)
{
#ifndef SHARED_HANDLERS
theApp.GetContextMenuManager()->ShowPopupMenu(IDR_POPMENU, point.x, point.y, this, TRUE);
#endif
}
// CQ756748View diagnostics
#ifdef _DEBUG
void CQ756748View::AssertValid() const
{
CView::AssertValid();
}
void CQ756748View::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CQ756748Doc* CQ756748View::GetDocument() const // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CQ756748Doc)));
return (CQ756748Doc*)m_pDocument;
}
#endif //_DEBUG
// CQ756748View message handlers
void CQ756748View::OnContextEllipse()
{
// TODO: Add your command handler code here
CQ756748Doc * doc = (CQ756748Doc *)GetDocument();
CPoint point;
GetCursorPos(&point);
ScreenToClient(&point);
int _x = point.x;
int _y = point.y;
doc->AddShape(1, _x, _y, _x + 130, _y + 90);
doc->UpdateAllViews(NULL);
}
void CQ756748View::OnContextLine()
{
// TODO: Add your command handler code here
CQ756748Doc * doc = (CQ756748Doc *)GetDocument();
CPoint point;
GetCursorPos(&point);
ScreenToClient(&point);
int _x = point.x;
int _y = point.y;
doc->AddShape(0, _x, _y, _x + 120, _y);
doc->UpdateAllViews(NULL);
}
void CQ756748View::OnContextRectangle()
{
// TODO: Add your command handler code here
CQ756748Doc * doc = (CQ756748Doc *)GetDocument();
CPoint point;
GetCursorPos(&point);
ScreenToClient(&point);
int _x = point.x;
int _y = point.y;
doc->AddShape(2, _x, _y, _x + 150, _y + 100);
doc->UpdateAllViews(NULL);
}
// Q756748Doc.cpp : implementation of the CQ756748Doc class
//
#include "stdafx.h"
// SHARED_HANDLERS can be defined in an ATL project implementing preview, thumbnail
// and search filter handlers and allows sharing of document code with that project.
#ifndef SHARED_HANDLERS
#include "Q756748.h"
#endif
#include "Q756748Doc.h"
#include <propkey.h>
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// CQ756748Doc
IMPLEMENT_DYNCREATE(CQ756748Doc, CDocument)
BEGIN_MESSAGE_MAP(CQ756748Doc, CDocument)
END_MESSAGE_MAP()
// CQ756748Doc construction/destruction
CQ756748Doc::CQ756748Doc()
{
// TODO: add one-time construction code here
}
CQ756748Doc::~CQ756748Doc()
{
}
BOOL CQ756748Doc::OnNewDocument()
{
if (!CDocument::OnNewDocument())
return FALSE;
// TODO: add reinitialization code here
// (SDI documents will reuse this document)
shapelist = NULL;
return TRUE;
}
void CQ756748Doc::AddShape(int type, int a, int b, int c, int d)
{
if (shapelist == NULL)
{
shapelist = new Shape;
shapelist->type = type;
shapelist->a = a;
shapelist->b = b;
shapelist->c = c;
shapelist->d = d;
shapelist->next = NULL;
}
else
{
Shape * pcurr = shapelist;
while (pcurr->next != NULL) pcurr = pcurr->next;
pcurr->next = new Shape;
pcurr = pcurr->next;
pcurr->type = type;
pcurr->a = a;
pcurr->b = b;
pcurr->c = c;
pcurr->d = d;
pcurr->next = NULL;
}
}
// CQ756748Doc serialization
void CQ756748Doc::Serialize(CArchive& ar)
{
if (ar.IsStoring())
{
// TODO: add storing code here
int i = 0;
Shape * pcurr = shapelist;
while (pcurr != NULL)
{
i++;
pcurr = pcurr->next;
}
ar << i;
pcurr = shapelist;
while (pcurr != NULL)
{
ar << pcurr->type << pcurr->a << pcurr->b << pcurr->c << pcurr->d;
pcurr = pcurr->next;
}
}
else
{
// TODO: add loading code here
int i = 0;
ar >> i;
if (i == 0) { shapelist = NULL; return; }
shapelist = new Shape;
shapelist->next = NULL;
Shape * shapelist1 = shapelist;
ar >> shapelist->type >> shapelist->a >> shapelist->b >> shapelist->c >> shapelist->d;
Shape * pcurr = shapelist->next;
for (int x = 0; x < i - 1; x++)
{
shapelist1->next = new Shape;
shapelist1 = shapelist1->next;
shapelist1->next = NULL;
ar >> shapelist1->type >> shapelist1->a >> shapelist1->b >> shapelist1->c >> shapelist1->d;
}
}
}
#ifdef SHARED_HANDLERS
// Support for thumbnails
void CQ756748Doc::OnDrawThumbnail(CDC& dc, LPRECT lprcBounds)
{
// Modify this code to draw the document's data
dc.FillSolidRect(lprcBounds, RGB(255, 255, 255));
CString strText = _T("TODO: implement thumbnail drawing here");
LOGFONT lf;
CFont* pDefaultGUIFont = CFont::FromHandle((HFONT) GetStockObject(DEFAULT_GUI_FONT));
pDefaultGUIFont->GetLogFont(&lf);
lf.lfHeight = 36;
CFont fontDraw;
fontDraw.CreateFontIndirect(&lf);
CFont* pOldFont = dc.SelectObject(&fontDraw);
dc.DrawText(strText, lprcBounds, DT_CENTER | DT_WORDBREAK);
dc.SelectObject(pOldFont);
}
// Support for Search Handlers
void CQ756748Doc::InitializeSearchContent()
{
CString strSearchContent;
// Set search contents from document's data.
// The content parts should be separated by ";"
// For example: strSearchContent = _T("point;rectangle;circle;ole object;");
SetSearchContent(strSearchContent);
}
void CQ756748Doc::SetSearchContent(const CString& value)
{
if (value.IsEmpty())
{
RemoveChunk(PKEY_Search_Contents.fmtid, PKEY_Search_Contents.pid);
}
else
{
CMFCFilterChunkValueImpl *pChunk = NULL;
ATLTRY(pChunk = new CMFCFilterChunkValueImpl);
if (pChunk != NULL)
{
pChunk->SetTextValue(PKEY_Search_Contents, value, CHUNK_TEXT);
SetChunkValue(pChunk);
}
}
}
#endif // SHARED_HANDLERS
// CQ756748Doc diagnostics
#ifdef _DEBUG
void CQ756748Doc::AssertValid() const
{
CDocument::AssertValid();
}
void CQ756748Doc::Dump(CDumpContext& dc) const
{
CDocument::Dump(dc);
}
#endif //_DEBUG
// CQ756748Doc commands
void CMyDlg::OnBnClickedOk()
{
// TODO: Add your control notification handler code here
UpdateData();
value = m_value;
CDialogEx::OnOK();
}
// Q756748_2View.cpp : implementation of the CQ756748_2View class
//
#include "stdafx.h"
// SHARED_HANDLERS can be defined in an ATL project implementing preview, thumbnail
// and search filter handlers and allows sharing of document code with that project.
#ifndef SHARED_HANDLERS
#include "Q756748_2.h"
#endif
#include "Q756748_2Doc.h"
#include "Q756748_2View.h"
#include "MyDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// CQ756748_2View
IMPLEMENT_DYNCREATE(CQ756748_2View, CView)
BEGIN_MESSAGE_MAP(CQ756748_2View, CView)
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, &CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, &CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, &CQ756748_2View::OnFilePrintPreview)
ON_WM_CONTEXTMENU()
ON_WM_RBUTTONUP()
ON_COMMAND(ID_EDIT_32771, &CQ756748_2View::OnEdit32771)
END_MESSAGE_MAP()
// CQ756748_2View construction/destruction
CQ756748_2View::CQ756748_2View()
{
// TODO: add construction code here
}
CQ756748_2View::~CQ756748_2View()
{
}
BOOL CQ756748_2View::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
// CQ756748_2View drawing
void CQ756748_2View::OnDraw(CDC* pDC)
{
CQ756748_2Doc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
if (!pDoc)
return;
pDC->TextOut(100, 100, m_str);
// TODO: add draw code for native data here
}
// CQ756748_2View printing
void CQ756748_2View::OnFilePrintPreview()
{
#ifndef SHARED_HANDLERS
AFXPrintPreview(this);
#endif
}
BOOL CQ756748_2View::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CQ756748_2View::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CQ756748_2View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
void CQ756748_2View::OnRButtonUp(UINT /* nFlags */, CPoint point)
{
ClientToScreen(&point);
OnContextMenu(this, point);
}
void CQ756748_2View::OnContextMenu(CWnd* /* pWnd */, CPoint point)
{
#ifndef SHARED_HANDLERS
theApp.GetContextMenuManager()->ShowPopupMenu(IDR_POPUP_EDIT, point.x, point.y, this, TRUE);
#endif
}
// CQ756748_2View diagnostics
#ifdef _DEBUG
void CQ756748_2View::AssertValid() const
{
CView::AssertValid();
}
void CQ756748_2View::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CQ756748_2Doc* CQ756748_2View::GetDocument() const // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CQ756748_2Doc)));
return (CQ756748_2Doc*)m_pDocument;
}
#endif //_DEBUG
// CQ756748_2View message handlers
void CQ756748_2View::OnEdit32771()
{
// TODO: Add your command handler code here
CMyDlg dlg;
if (dlg.DoModal() == IDOK)
m_str = dlg.value;
GetDocument()->UpdateAllViews(NULL);
}