📄 毕业设计view.cpp
字号:
// 毕业设计View.cpp : implementation of the CMyView class
//
#include "stdafx.h"
#include "毕业设计.h"
#include "毕业设计Doc.h"
#include "毕业设计View.h"
#include "SetColDlg.h"
#include "SetAguDlg.h"
#include "SMSetDlg.h"
#include "MySetDlg.h"
#include "SetDlg2.h"
#include "ZoomSetDlg.h"
#include "MoveSetDlg.h"
#include "TurnSetDLg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
extern CBmpDat * pbmpdat;
extern int * psaved;
/////////////////////////////////////////////////////////////////////////////
// CMyView
IMPLEMENT_DYNCREATE(CMyView, CFormView)
BEGIN_MESSAGE_MAP(CMyView, CFormView)
//{{AFX_MSG_MAP(CMyView)
ON_COMMAND(ID_FILE_NEW, OnFileNew)
ON_COMMAND(ID_FILE_OPEN, OnFileOpen)
ON_COMMAND(ID_FILE_SAVE, OnFileSave)
ON_COMMAND(ID_FILE_SAVE_AS, OnFileSaveAs)
ON_WM_PAINT()
ON_COMMAND(ID_MBY, OnMby)
ON_COMMAND(ID_MFD, OnMfd)
ON_COMMAND(ID_MLB, OnMlb)
ON_COMMAND(ID_MMH, OnMmh)
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONUP()
ON_WM_MOUSEMOVE()
ON_WM_RBUTTONDOWN()
ON_WM_RBUTTONUP()
ON_COMMAND(ID_MLU, OnMlu)
ON_COMMAND(ID_MLD, OnMld)
ON_COMMAND(ID_MENUITEM32778, OnMenuitem32778)
ON_COMMAND(ID_MENUITEM32779, OnMenuitem32779)
ON_COMMAND(ID_MENUITEM32780, OnMenuitem32780)
ON_COMMAND(ID_MENUITEM32781, OnMenuitem32781)
ON_COMMAND(ID_MENUITEM32782, OnMenuitem32782)
ON_COMMAND(ID_MENUITEM32783, OnMenuitem32783)
ON_COMMAND(ID_MENUITEM32784, OnMenuitem32784)
ON_COMMAND(ID_MENUITEM32785, OnMenuitem32785)
ON_COMMAND(ID_MENUITEM32786, OnMenuitem32786)
ON_COMMAND(ID_MENUITEM32787, OnMenuitem32787)
ON_COMMAND(ID_MENUITEM32788, OnMenuitem32788)
ON_COMMAND(ID_MENUITEM32771, OnMenuitem32771)
ON_COMMAND(ID_MENUITEM32790, OnMenuitem32790)
//}}AFX_MSG_MAP
// Standard printing commands
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMyView construction/destruction
CMyView::CMyView()
: CFormView(CMyView::IDD)
,texttool(this)
{
//{{AFX_DATA_INIT(CMyView)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// TODO: add construction code here
saved = -1;
contyp = 0;
cnum = 6;
lbd = FALSE;
rbd = FALSE;
tx[5] = 0;
psaved = &saved;
texttool.Create(IDD_DIALOG6);
}
CMyView::~CMyView(){
}
void CMyView::DoDataExchange(CDataExchange* pDX){
CFormView::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CMyView)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BOOL CMyView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CFormView::PreCreateWindow(cs);
}
void CMyView::OnInitialUpdate()
{
CFormView::OnInitialUpdate();
GetParentFrame()->RecalcLayout();
ResizeParentToFit();
CPaintDC dc(this);
bmp = new CBmpDat(&dc);
bmp->New(500,350);
pbmpdat = bmp;
UINT ID = IDB_B1;
for(int i = 0;i<cnum;i++){
con[i].Create(i,ID+i*2,ID+i*2+1,&dc,i%2*40+10,i/2*40+10,30);
}
}
/////////////////////////////////////////////////////////////////////////////
// CMyView printing
BOOL CMyView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CMyView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CMyView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
void CMyView::OnPrint(CDC* pDC, CPrintInfo* /*pInfo*/)
{
// TODO: add customized printing code here
}
/////////////////////////////////////////////////////////////////////////////
// CMyView diagnostics
#ifdef _DEBUG
void CMyView::AssertValid() const
{
CFormView::AssertValid();
}
void CMyView::Dump(CDumpContext& dc) const
{
CFormView::Dump(dc);
}
CMyDoc* CMyView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMyDoc)));
return (CMyDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CMyView message handlers
void CMyView::OnFileNew()
{
// TODO: Add your command handler code here
// MessageBox("New");
if(saved == 1){
int i = MessageBox("文件已修改,是否保存?","提示",MB_YESNOCANCEL);
if(i == 6){
bmp->Save();
}
else if(i == 2){
return;
}
}
bmp->New(bmp->GetW(),bmp->GetH());
Invalidate(TRUE);
saved = -1;
}
void CMyView::OnFileOpen()
{
// TODO: Add your command handler code here
// MessageBox("Open");
if(saved == 1){
int i = MessageBox("文件已修改,是否保存?","提示",MB_YESNOCANCEL);
if(i == 6){
saved = bmp->Save();
}
else if(i == 2){
return;
}
}
CPaintDC pdc(this);
CFileDialog ff(true,NULL,NULL,OFN_OVERWRITEPROMPT,"*.bmp|*.bmp|",NULL);
if(ff.DoModal()==IDOK){
CString path = ff.GetPathName();
bmp->Open(path);
saved = 0;
Invalidate(TRUE);
}
}
void CMyView::OnFileSave()
{
// TODO: Add your command handler code here
// MessageBox("Save");
saved = bmp->Save();
}
void CMyView::OnFileSaveAs()
{
// TODO: Add your command handler code here
CFileDialog ff(false,NULL,NULL,OFN_OVERWRITEPROMPT,"*.bmp|*.bmp|",NULL);
if(ff.DoModal()==IDOK){
CString path = ff.GetPathName();
StringEnd(path,".bmp");
bmp->Save(path);
saved = 0;
Invalidate(TRUE);
}
}
void CMyView::OnPaint()
{
CPaintDC dc(this); // device context for painting
// TODO: Add your message handler code here
for(int i = 0;i<cnum;i++){
dc.BitBlt(con[i].GetX(),con[i].GetY(),30,30,con[i].GetDC(contyp),0,0,SRCCOPY);
}
CBitmap bp,*bop;
bp.LoadBitmap(IDB_PC);
CDC pd;
pd.CreateCompatibleDC(&dc);
bop = pd.SelectObject(&bp);
bop->DeleteObject();
CPen pe1,pe2;
pe1.CreatePen(PS_SOLID,35,bmp->bgcol);
pd.SelectObject(&pe1);
pd.MoveTo(50,27);
pd.LineTo(51,27);
pe2.CreatePen(PS_SOLID,35,bmp->pecol);
pd.SelectObject(&pe2);
pd.MoveTo(25,22);
pd.LineTo(26,22);
dc.BitBlt(12,300,75,50,&pd,0,0,SRCCOPY);
dc.MoveTo(99,0);
dc.LineTo(99,1000);
dc.BitBlt(100,0,bmp->GetW(),bmp->GetH(),bmp->GetDC(),0,0,SRCCOPY);
// Do not call CFormView::OnPaint() for painting messages
}
void CMyView::OnLButtonDown(UINT nFlags, CPoint point) {
//鼠标左键盘按下时
if(rbd){//如果右键也按下的
rbd = FALSE;
bmp->Cancel();//撤消所作的工作
Invalidate(FALSE);
tx[5] = 0;
}
else if(point.x<100){
for(int i = 0;i<cnum;i++){
if(con[i].InIt(point.x,point.y)){//选择画图工具
if(contyp == 4&&i!=4){
bmp->BeiFen();
saved = 1;
tx[5] = 0;
}
if(i == 5&&contyp!=5){//选择的是文字工具时,要打开文字工具对话框
texttool.Set(&contyp,contyp,bmp);
texttool.SetXY(0,0);
tx[9] = contyp;contyp = i;
Invalidate(FALSE);
texttool.ShowWindow(SW_RESTORE);
}
else if(i != 5){
if(contyp == 5){
texttool.Close();
}
contyp = i;
Invalidate(FALSE);
}
return;
}
}
if(point.x>30&&point.x<50&&point.y>310&&point.y<330){
CColorDialog cscd(bmp->pecol);//选择前景颜色
if(cscd.DoModal() == IDOK){
bmp->SetPen(cscd.GetColor());
Invalidate(FALSE);
}
}
if(point.x>55&&point.x<75&&point.y>320&&point.y<340){
CColorDialog cscd(bmp->bgcol);//选择背景颜色
if(cscd.DoModal() == IDOK){
bmp->bgcol = cscd.GetColor();
Invalidate(FALSE);
}
}
}
else{
if(point.x<bmp->GetW()+100&&point.y<bmp->GetH()){
//绘图区域
lbd = TRUE;
if(contyp == 3){//填充
bmp->TC(point.x-100,point.y);
Invalidate(FALSE);
}
else if(contyp == 2){//擦除
bmp->Clear(point.x-100,point.y);
Invalidate(FALSE);
}
else if(contyp == 4){//曲线
if(tx[5]==0){//第一点(第二点在释放时记录)
lbd = TRUE;
tx[2] = tx[1] = tx[0] = point.x-100;
ty[2] = ty[1] = ty[0] = point.y;
}
else if(tx[5] == 1){//第三点
tx[1] = tx[2] = point.x - 100;
ty[1] = ty[2] = point.y;
bmp->ReBezier(tx,ty);
Invalidate(FALSE);
}
else{//第四点
tx[2] = point.x - 100;
ty[2] = point.y;
bmp->ReBezier(tx,ty);
Invalidate(FALSE);
}
}
else if(contyp == 5){//文字
if(texttool.Select(point.x-100,point.y)){
tx[0] = point.x-100;
ty[0] = point.y;
}
else{
lbd = FALSE;
}
}
else{
lbd = TRUE;
tx[1] = tx[0] = point.x-100;
ty[1] = ty[0] = point.y;
}
}
}
CFormView::OnLButtonDown(nFlags, point);
}
void CMyView::OnLButtonUp(UINT nFlags, CPoint point) {
// TODO: Add your message handler code here and/or call default
if(lbd){
lbd = FALSE;
if(contyp==0){//画笔
bmp->Line(tx[1],ty[1],point.x-100,point.y);
bmp->Darw(point.x-100,point.y);
bmp->BeiFen();
saved = 1;
}
else if(contyp == 1){//画直线
bmp->ReLine(tx[0],ty[0],point.x-100,point.y,1,0);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -