【VC开源代码栏目提醒】:网学会员为需要VC开源代码的朋友们搜集整理了DRAWDLG.CPP相关资料,希望对各位网友有所帮助!
// DrawDlg.cpp : implementation file
//
#include "stdafx.h"
#include "ControlerDraw.h"
#include "DrawDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CDrawDlg dialog
CDrawDlg::CDrawDlg(CWnd* pParent /*=NULL*/)
: CDialog(CDrawDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CDrawDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
m_bzoomin = false ;
m_bcircle = false ;
m_bline = false ;
m_brectangle = false ;
}
void CDrawDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDrawDlg)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CDrawDlg, CDialog)
//{{AFX_MSG_MAP(CDrawDlg)
ON_WM_PAINT()
ON_BN_CLICKED(IDC_DRAW_CIRCLE, OnDrawCircle)
ON_BN_CLICKED(IDC_DRAW_LINE, OnDrawLine)
ON_BN_CLICKED(IDC_DRAW_RECTANGLE, OnDrawRectangle)
ON_BN_CLICKED(IDC_DRAW_ZOOM, OnDrawZoom)
ON_BN_CLICKED(IDC_DRAW_CLEAR, OnDrawClear)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDrawDlg message handlers
void CDrawDlg::OnPaint()
{
CPaintDC dc(this) ;
// TODO: Add your message handler code here
if(m_bline)
{
m_Elementname = LINE ;
DrawElement() ;
}
if(m_bcircle)
{
m_Elementname = CIRCLE ;
DrawElement() ;
}
if(m_brectangle)
{
m_Elementname = RECTANGLE ;
DrawElement() ;
}
// Do not call CDialog::OnPaint() for painting messages
}
void CDrawDlg::OnDrawCircle()
{
//确定当前的所绘制的图形类型为圆;
m_Elementname=CIRCLE ;
m_bcircle=true ;
DrawElement() ;
}
void CDrawDlg::OnDrawLine()
{
//确定当前的所绘制的图形类型为直线;
m_Elementname=LINE ;
m_bline = true ;
DrawElement() ;
}
void CDrawDlg::OnDrawRectangle()
{
//确定当前的所绘制的图形类型为矩形;
m_Elementname = RECTANGLE ;
m_brectangle = true ;
DrawElement() ;
}
void CDrawDlg::OnDrawZoom()
{
//确定当前操作为缩放;
m_Operationname = ZOOM ;
m_bzoomin= !m_bzoomin ;
Operation() ;
}
void CDrawDlg::OnDrawClear()
{
//确定当前操作为清除所绘制的所有图形;
m_bzoomin = false ;
m_Operationname = CLEAR ;
Operation() ;
}
void CDrawDlg::DrawElement()
{
//获得ID号为IDC_DRAWBOX的控件的CWnd指针,
//并使用它得到相应的设备环境;
CWnd *pWnd=GetDlgItem(IDC_DRAWBOX);
CDC *pDC=pWnd->GetDC() ;
//获得该控件的矩形区域;
::GetClientRect(pWnd->m_hWnd,conRect) ;
//将索引值为NULL_BRUSH的GDI库存对象选进设备环境;
pDC->SelectStockObject(NULL_BRUSH) ;
// pDC->SetROP2(R2_NOT) ;
// pWnd->Invalidate() ;
//进行缩放后的显示;
if(m_Operationname==ZOOM && m_bzoomin)
{
pDC->SetMapMode(MM_ISOTROPIC) ;
pDC->SetWindowExt(100,100) ;
pDC->SetViewportExt(conRect.right-20,conRect.bottom-20) ;
}
//设置视口原点;
pDC->SetViewportOrg(conRect.right/2,conRect.bottom/2) ;
//判断成员变量m_Elementname的值,以便确定绘制对象的类型;
switch(m_Elementname)
{
case CIRCLE:
//绘制圆形;
pDC->Ellipse(-50,-50,50,50) ;
break;
case LINE:
//绘制交叉直线;
pDC->MoveTo(-50,-50) ;
pDC->LineTo(50,50) ;
pDC->MoveTo(50,-50) ;
pDC->LineTo(-50,50) ;
break;
case RECTANGLE:
//绘制矩形;
pDC->Rectangle(-50,-50,50,50) ;
break;
default:;
}
pWnd->ReleaseDC(pDC) ;
}
void CDrawDlg::Operation()
{
DrawElement() ;
//根据成员变量m_Operationname的值,以便执行何种操作;
switch(m_Operationname)
{
case ZOOM:
//重新绘制窗口,功能类似于视图类的OnDraw函数;
// OnPaint() ;
DrawElement() ;
break;
case CLEAR:
//清除所绘制的图形;
m_Elementname =BECLEARED ;
m_bline=false;
m_bcircle=false ;
m_brectangle = false ;
break;
default:;
}
//强行调用OnPaint()成员函数对控件窗口进行重绘;
this->Invalidate() ;
}
上一篇:
CopyHk.pas
下一篇:
不规则零件优化排样的神经网络混合优化算法