Documentos de Académico
Documentos de Profesional
Documentos de Cultura
Clase 13
Clase 13
Ricardo Castañeda
Clase 13
2015
2
Ing. Ricardo Castañeda
Finish
3
Ing. Ricardo Castañeda
// Operations
public:
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CGraficos1Doc)
public:
virtual BOOL OnNewDocument();
virtual void Serialize(CArchive& ar);
//}}AFX_VIRTUAL
// Implementation
public:
virtual ~CGraficos1Doc();
#ifdef _DEBUG
virtual void AssertValid() const;
virtual void Dump(CDumpContext& dc) const;
#endif
protected:
// Generated message map functions
protected:
//{{AFX_MSG(CGraficos1Doc)
// NOTE - the ClassWizard will add and remove member functions here.
// DO NOT EDIT what you see in these blocks of generated code !
//}}AFX_MSG
DECLARE_MESSAGE_MAP() };
2) El siguiente paso será la declaración de los datos miembro de la clase vista, abrimos el
archivo Graficos1View.h
// Operations
4
Ing. Ricardo Castañeda
public:
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CGraficos1View)
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 ~CGraficos1View();
#ifdef _DEBUG
virtual void AssertValid() const;
virtual void Dump(CDumpContext& dc) const;
#endif
protected:
// Generated message map functions
protected:
//{{AFX_MSG(CGraficos1View)
// NOTE - the ClassWizard will add and remove member functions here.
// DO NOT EDIT what you see in these blocks of generated code !
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
BOOL CGraficos1Doc::OnNewDocument()
{if (!CDocument::OnNewDocument())
return FALSE;
// TODO: add reinitialization code here
// (SDI documents will reuse this document)
m_posicionx;
m_posiciony;
return TRUE;
}
4) Ahora entre a MFC ClassWizard con CTRL+W y se le presentara la siguiente
ventana y haga clic en edit code para escribir lo siguiente:
5
Ing. Ricardo Castañeda
5) Escribir:
void CGraficos1View::OnInitialUpdate()
{ CView::OnInitialUpdate();
// Se obtiene el apuntador al documento
CGraficos1Doc* pDoc = GetDocument();
m_posicionx = pDoc->m_posicionx;
m_posiciony = pDoc->m_posiciony;
}
6) Para desplegar el circulo abra Graficos1View.cpp y localize OnDraw() y escriba el
siguiente codigo:
void CGraficos1View::OnDraw(CDC* pDC)
{ CGraficos1Doc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
// define los limites rectangulares a dibujar
RECT rect;
rect.left = m_posicionx-20;
rect.top = m_posiciony -20;
rect.bottom = m_posiciony + 20;
rect.right = m_posicionx + 20;
// Dibuja el circulo
pDC->Ellipse(&rect);
}
6
Ing. Ricardo Castañeda
CView::OnLButtonDown(nFlags, point);
}
APLICACIÓN DE GRAFICOS 02
La Clase Cfont Crear un nuevo proyecto llamado Graficos2 y dar OK a
continuación seleccionar Single Document y Finísh.
Ahora crear en la clase CGraficos2View la función que recibirá el nombre
ShowFonts(CDC +pDC), para ello hacer clic derecho sobre la clase y elegir Add Member
Function tal como se muestra:
7
Ing. Ricardo Castañeda
Y debe aparecer:
Y escribimos
8
Ing. Ricardo Castañeda
}
Suerte y ejecute
APLICACIÓN DE GRAFICOS 03
DESARROLLEMOS LA SERIE DE FOURIER UTILIZANDO LAS CLASES:
CBrush, CPen y CPaintDC.
9
Ing. Ricardo Castañeda
10
Ing. Ricardo Castañeda
11
Ing. Ricardo Castañeda
CBrush n_brocha;
CBrush *v_brocha;
CPen n_pincel;
CPen *v_pincel;
// Crea superficie de dibujo
dc.SetMapMode(MM_ISOTROPIC); //Escala de sistema
dc.SetWindowExt(500,500);// Tamaño de la ventana
dc.SetViewportExt(m_cxClient, -m_cyClient);// Tamaño del área de dibujo
dc.SetViewportOrg(m_cxClient/20, m_cyClient/2);//establece origen de coordenadas
ang = 0;
yp = 0.0;
n_pincel.CreatePen(BS_SOLID,2,RGB(0,0,0));
v_pincel= dc.SelectObject(&n_pincel);
12
Ing. Ricardo Castañeda
13