More Related Content
More from Razvan Raducanu, PhD
More from Razvan Raducanu, PhD (20)
MFC Menu
- 9. MainFrm.cpp
void CMainFrame::OnColorsGreen()
{
// TODO: Add your command handler code here
CMenuDoc* pDoc = (CMenuDoc*)GetActiveDocument();
pDoc->m_crColor = RGB(0, 255, 0);
}
void CMainFrame::OnColorsBlue()
{
// TODO: Add your command handler code here
CMenuDoc* pDoc = (CMenuDoc*)GetActiveDocument();
pDoc->m_crColor = RGB(0, 0, 255);
}
- 10. MenuDoc.h
class CMenuDoc : public CDocument
{
protected: // create from serialization only
CMenuDoc() noexcept;
DECLARE_DYNCREATE(CMenuDoc)
// Attributes
public:
COLORREF m_crColor;
// Operations
public:
……………………….
- 16. void CMenuView::OnDeseneRectangle()
{
// TODO: Add your command handler code here
CClientDC dc(this);
CMenuDoc* pDoc = (CMenuDoc*)GetDocument();
m_color = pDoc->m_crColor;
CPen pen(m_pen, m_width, m_color);
dc.SelectObject(&pen);
dc.Rectangle(10, 10, 200, 200);
}
- 19. void CMenuView::OnDeseneEllipse()
{
// TODO: Add your command handler code here
CClientDC dc(this);
CMenuDoc* pDoc = (CMenuDoc*)GetDocument();
m_color = pDoc->m_crColor;
CPen pen(m_pen, m_width, m_color);
dc.SelectObject(&pen);
dc.Ellipse(10, 10, 200, 200);
}
- 31. MenuView.cpp
void CMenuView::OnDeseneProperties()
{
// TODO: Add your command handler code here
CPropertiesDlg dlg;
CString str_pen,str_width;
int result = dlg.DoModal();
if (result == IDOK) {
str_pen = dlg.m_edit1;
str_width = dlg.m_edit2;
m_pen = _wtoi(str_pen);
m_width = _wtoi(str_width);;
}
}
Add in header:
#include "CPropertiesDlg.h“
#include <stdlib.h>