⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 draw1view.cpp

📁 用c++编写的简单的绘图程序
💻 CPP
📖 第 1 页 / 共 3 页
字号:
	   break;
   case ID_IMAGE_ZOOM://放大镜放大情况
            currectZoom=2*currectZoom;
		    pDC->SetWindowOrg(0,0);
  	        pDC->SetViewportOrg(0,0);
            SetAllObectScal();
            currectZoom=1.0;
            OnDraw(pDC);
	   break;
 
   }
	ReleaseDC(pDC);//释放DC资源
	CView::OnLButtonDown(nFlags, point);
}

//鼠标右键按下事件
//用于缩小图形(全)
void CDRAW1View::OnRButtonDown(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	CDC* pDC = GetDC();//获得DC
	if(curretHandObj==ID_IMAGE_ZOOM)
	{
	  currectZoom=0.5*currectZoom;
      pDC->SetWindowOrg(0,0);
  	  pDC->SetViewportOrg(0,0);
      SetAllObectScal();
      currectZoom=1.0;
      OnDraw(pDC); 
	}
	
	CScrollView::OnRButtonDown(nFlags, point);
}

//鼠标左键按上事件
//创建图形对象,向链表中加入该对象
void CDRAW1View::OnLButtonUp(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	CDC* pDC = GetDC();//获得DC
	OnPrepareDC(pDC);//设置DC的滚动属性,与ScollView的滚动有关
	pDC->DPtoLP(&point);//转换当前点为逻辑位置坐标
	CDRAW1Doc* pDoc = GetDocument();
     int count=0;
    currectName=GiveName();//给对象自动命名
	
	//获取名字复合框的句柄
	CMainFrame* pMainFrm;
	CComboBox *p_ComBox;
    pMainFrm=(CMainFrame *)AfxGetApp()->GetMainWnd();
    p_ComBox=(CComboBox *)pMainFrm->m_wndDlgBar.GetDlgItem(ID_OBJ_NAME_BOX);

   switch(curretHandObj)
   {
   case ID_IMAGE_PEN:
		 createObject->Draw(pDC);
         createObject->SetName(currectName);
         createObject->SetId(GiveID());//给该对象设定ID
         objectAll->AddTail(createObject);//向表尾加入该对象
		 if(currectObject!=NULL)//检测之前对象是否为空,否则反激活之前对象
		{
			 currectObject->Activation(pDC,currectBkColor);
			 currectObject->Draw(pDC);
		 }
        currectObject=createObject;//更新当前对象
        currectObject->Activation(pDC,curretColor);//激活当前对象

        p_ComBox->AddString(currectName);//向名字复合框中添加该对象名字
        count=objectAll->GetCount();
        p_ComBox->SetCurSel(count-1);//选中对象名字
 
        currectName="";
		::ClipCursor(NULL);//释放鼠标锁定
		currectState=OBJECT_STATE_EDITING;//设置当前状态为编辑
	   break;
   case ID_IMAGE_ZOOM:
		::ClipCursor(NULL);//释放鼠标锁定
	   break;
   }

	ReleaseDC(pDC);//释放DC资源
	CView::OnLButtonUp(nFlags, point);
}

//鼠标移动事件
void CDRAW1View::OnMouseMove(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	CDC* pDC = GetDC();
	OnPrepareDC(pDC);
	pDC->DPtoLP(&point);
	//保证对象处于创建状态
	if(createObject&&(currectState==OBJECT_STATE_CREATING))
		createObject->MoveAt(pDC, point.x, point.y);	
	ReleaseDC(pDC);//释放DC资源
	CView::OnMouseMove(nFlags, point);
}

////////////////////////////////////////////////////////////////////////////
//以下为工具栏事件

/////////////////////////////////////////////////////////////////////
//以下为运作方式事件方法
//运作方式为放大镜
void CDRAW1View::OnImageZoom() 
{
	// TODO: Add your command handler code here
	curretHandObj=ID_IMAGE_ZOOM;
}

void CDRAW1View::OnUpdateImageZoom(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	 pCmdUI->SetCheck(curretHandObj==ID_IMAGE_ZOOM);
}
//运作方式为画笔
void CDRAW1View::OnImagePen() 
{
	// TODO: Add your command handler code here
   curretHandObj=ID_IMAGE_PEN;
	
}
void CDRAW1View::OnUpdateImagePen(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
    pCmdUI->SetCheck(curretHandObj==ID_IMAGE_PEN);
	
}
//////////////////////////////////////////////
//以下为图形类型事件方法
//图形为直线的事件方法
void CDRAW1View::OnShapeStrLine() 
{
	// TODO: Add your command handler code here
   curretShape=ID_SHAPE_STR_LINE;
	
}
void CDRAW1View::OnUpdateShapeStrLine(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
pCmdUI->SetCheck(curretShape==ID_SHAPE_STR_LINE);
	
}

//图形为四边形的事件方法
void CDRAW1View::OnShapeRectangle() 
{
	// TODO: Add your command handler code here
   curretShape=ID_SHAPE_RECTANGLE;
	
}
void CDRAW1View::OnUpdateShapeRectangle(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->SetCheck(curretShape==ID_SHAPE_RECTANGLE);
}

//图形为圆的事件方法
void CDRAW1View::OnShapeCircle() 
{
	// TODO: Add your command handler code here
  curretShape=ID_SHAPE_CIRCLE;
	
}
void CDRAW1View::OnUpdateShapeCircle(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->SetCheck(curretShape==ID_SHAPE_CIRCLE);	
}

//图形为椭圆的事件方法
void CDRAW1View::OnShapeEllipse() 
{
	// TODO: Add your command handler code here
   curretShape=ID_SHAPE_ELLIPSE;
	
}
void CDRAW1View::OnUpdateShapeEllipse(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->SetCheck(curretShape==ID_SHAPE_ELLIPSE);
	
}

//图形为正方形的事件方法
void CDRAW1View::OnShapeSquare() 
{
	// TODO: Add your command handler code here
    curretShape=ID_SHAPE_SQUARE;
	
}
void CDRAW1View::OnUpdateShapeSquare(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
		pCmdUI->SetCheck(curretShape==ID_SHAPE_SQUARE);
}

//图形为三角形的事件方法
void CDRAW1View::OnShapeTriangle() 
{
	// TODO: Add your command handler code here

	   curretShape=ID_SHAPE_TRIANGLE;
}

void CDRAW1View::OnUpdateShapeTriangle(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
		pCmdUI->SetCheck(curretShape==ID_SHAPE_TRIANGLE);
	
}
//////////////////////////////////
//三种边框的事件
//小边框事件方法
void CDRAW1View::OnBorderScaleSmall() 
{
	// TODO: Add your command handler code here

	currectBordarScal=BORDAR_SMALL;
}
void CDRAW1View::OnUpdateBorderScaleSmall(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->SetCheck(currectBordarScal==BORDAR_SMALL);
}
//中等边框事件方法
void CDRAW1View::OnBorderScaleMiddle() 
{
	// TODO: Add your command handler code here
	currectBordarScal=BORDAR_MIDDLE;
	
}

void CDRAW1View::OnUpdateBorderScaleMiddle(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
		pCmdUI->SetCheck(currectBordarScal==BORDAR_MIDDLE);
}
//大边框事件方法
void CDRAW1View::OnBorderScaleLarge() 
{
	// TODO: Add your command handler code here
	currectBordarScal=BORDAR_LARGE;
	
}

void CDRAW1View::OnUpdateBorderScaleLarge(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
		pCmdUI->SetCheck(currectBordarScal==BORDAR_LARGE);
}
//////////////////////////////////////////////////////
//前景色事件方法

//前景色为黑色事件方法
void CDRAW1View::OnColorBlack() 
{
	// TODO: Add your command handler code here
  curretColor=BLACK;
	
}
void CDRAW1View::OnUpdateColorBlack(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->SetCheck(curretColor==BLACK);
}
//前景色为红色事件方法
void CDRAW1View::OnColorRed() 
{
	// TODO: Add your command handler code here
	  curretColor=RED;
}

void CDRAW1View::OnUpdateColorRed(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
		pCmdUI->SetCheck(curretColor==RED);
}

//前景色为黄色事件方法
void CDRAW1View::OnColorYellow() 
{
	// TODO: Add your command handler code here
  curretColor=YELLOW;
	
}
void CDRAW1View::OnUpdateColorYellow(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->SetCheck(curretColor==YELLOW);
}

//前景色为绿色事件方法
void CDRAW1View::OnColorGreen() 
{
	// TODO: Add your command handler code here
	  curretColor=GREEN;
}
void CDRAW1View::OnUpdateColorGreen(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->SetCheck(curretColor==GREEN);	
}

//前景色为蓝色事件方法
void CDRAW1View::OnColorBlue() 
{
	// TODO: Add your command handler code here
		  curretColor=BLUE;
}

void CDRAW1View::OnUpdateColorBlue(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->SetCheck(curretColor==BLUE);
}
//前景色为白色事件方法
void CDRAW1View::OnColorWhite() 
{
	// TODO: Add your command handler code here
	  curretColor=WHITE;
}


void CDRAW1View::OnUpdateColorWhite(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
		pCmdUI->SetCheck(curretColor==WHITE);
}

//前景色更多事件方法(更多前景色)
void CDRAW1View::OnColorMore() 
{
	// TODO: Add your command handler code here
    onMore=1;
	CColorDialog dialog;
	dialog.m_cc.Flags |= CC_PREVENTFULLOPEN | CC_RGBINIT;
	dialog.m_cc.rgbResult = curretColor;
	if(dialog.DoModal() == IDOK)
	{
		curretColor = dialog.GetColor();
	}
	onMore=0;
}

void CDRAW1View::OnUpdateColorMore(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->SetCheck(onMore==1);
}
//////////////////////////////
//背景色事件方法
//改变背景色事件方法
void CDRAW1View::OnBkColor() 
{
	// TODO: Add your command handler code here
    CDC*  pDC=GetDC();
	CColorDialog dialog;
	dialog.m_cc.Flags |= CC_PREVENTFULLOPEN | CC_RGBINIT;
	dialog.m_cc.rgbResult = currectBkColor;
	if(dialog.DoModal() == IDOK)
	{
		currectBkColor = dialog.GetColor();
	}
   OnEraseBkgnd(pDC);
}

void CDRAW1View::OnUpdateBkColor(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
  pCmdUI->ContinueRouting();
	
}
////////////////////////////////////////////////////////////
//填充与否事件方法

//不填充的事件方法
void CDRAW1View::OnFillFalse() 
{
	// TODO: Add your command handler code here
   currectFill=false;
	
}

void CDRAW1View::OnUpdateFillFalse(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->SetCheck(currectFill==false);
	
}
//填充的事件方法
void CDRAW1View::OnFillTrue() 
{
	// TODO: Add your command handler code here
	currectFill=true;
}

void CDRAW1View::OnUpdateFillTrue(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
		pCmdUI->SetCheck(currectFill==true);
}




























⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -