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

📄 pendlg.cpp

📁 一个vc编写的小游戏
💻 CPP
字号:
// PenDlg.cpp : implementation file
//

#include "stdafx.h"
#include "MYDLG.h"
#include "PenDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CPenDlg dialog


CPenDlg::CPenDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CPenDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CPenDlg)
	m_pWidth = 0;
	m_pStyle = -1;
	m_Tu = _T("");

	//}}AFX_DATA_INIT
	m_pColor=RGB(0,0,0);
	m_pQx = 50;
	m_pQy = 70;
	m_pZx = 90;
	m_pZy = 130;
	
}


void CPenDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CPenDlg)
	DDX_Control(pDX, IDC_SLIDER3, m_slider);
	DDX_Control(pDX, IDC_NUMBER, m_pHuatu);
	DDX_Control(pDX, IDC_WIDTH, m_pWidthEdit);
	DDX_Text(pDX, IDC_WIDTH, m_pWidth);
	DDV_MinMaxInt(pDX, m_pWidth, 1, 6);
	DDX_Radio(pDX, IDC_SOLID, m_pStyle);
	DDX_CBString(pDX, IDC_NUMBER, m_Tu);
	DDX_Text(pDX, IDC_qidianX, m_pQx);
	DDX_Text(pDX, IDC_qidianY, m_pQy);
	DDX_Text(pDX, IDC_zhongdianX, m_pZx);
	DDX_Text(pDX, IDC_zhongdianY, m_pZy);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CPenDlg, CDialog)
	//{{AFX_MSG_MAP(CPenDlg)
	ON_WM_PAINT()
	ON_BN_CLICKED(IDC_DASH, OnDash)
	ON_BN_CLICKED(IDC_DOT, OnDot)
	ON_BN_CLICKED(IDC_SOLID, OnSolid)
	ON_EN_CHANGE(IDC_WIDTH, OnChangeWidth)
	ON_BN_CLICKED(IDC_yanse, Onyanse)
	ON_CBN_SELCHANGE(IDC_NUMBER, OnSelchangeNumber)
	ON_WM_HSCROLL()
	ON_EN_CHANGE(IDC_qidianX, OnChangeqidianX)
	ON_EN_CHANGE(IDC_qidianY, OnChangeqidianY)
	ON_EN_CHANGE(IDC_zhongdianX, OnChangezhongdianX)
	ON_EN_CHANGE(IDC_zhongdianY, OnChangezhongdianY)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CPenDlg message handlers

BOOL CPenDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	GetDlgItem(IDC_SAMPLE)->GetWindowRect(&m_pRectSample);
    ScreenToClient(&m_pRectSample);
    m_pWidthEdit.LimitText(1);// TODO: Add extra initialization here
	m_slider.SetRange(0,50);
    m_slider.SetTicFreq(10);
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CPenDlg::OnPaint() 
{
	CPaintDC dc(this); // device context for painting
	
	CPen NewPen,*pOldPen;
    switch(m_pStyle)
	{
    case PEN_STYLE_SOLID:
    NewPen.CreatePen(PS_SOLID,m_pWidth,m_pColor);
    break;
    case PEN_STYLE_DASH:
    NewPen.CreatePen(PS_DASH,m_pWidth,m_pColor);
    break;
    case PEN_STYLE_DOT:
    NewPen.CreatePen(PS_DOT,m_pWidth,m_pColor);
    break;
	default:
    NewPen.CreatePen(PS_SOLID,m_pWidth,m_pColor);
    break;
	}
    pOldPen=dc.SelectObject(&NewPen);
	
	if(m_Tu=="Line")
	{
       dc.MoveTo(m_pRectSample.left+m_pQx,m_pRectSample.top+m_pQy);
       dc.LineTo(m_pRectSample.left+m_pZx,m_pRectSample.top+m_pZy);
	   //InvalidateRect(&m_pRectSample);
	}
	if(m_Tu=="Rectangle")
	{
		dc.Rectangle(m_pRectSample.left+m_pQx,m_pRectSample.top+m_pQy,m_pRectSample.left+m_pZx,m_pRectSample.top+m_pZy);
		//InvalidateRect(&m_pRectSample);
	}
	if(m_Tu=="Ellipse")
	{
		dc.Ellipse(m_pRectSample.left+m_pQx,m_pRectSample.top+m_pQy,m_pRectSample.left+m_pZx,m_pRectSample.top+m_pZy);
		//InvalidateRect(&m_pRectSample);
	}

    dc.SelectObject(pOldPen);// TODO: Add your message handler code here
	// Do not call CDialog::OnPaint() for painting messages
}

void CPenDlg::OnDash() 
{
	if (IsDlgButtonChecked(IDC_DASH))
	{ 
		m_pStyle=PEN_STYLE_DASH;
        InvalidateRect(&m_pRectSample);
        UpdateWindow();
	}// TODO: Add your control notification handler code here
	
}

void CPenDlg::OnDot() 
{
	if (IsDlgButtonChecked(IDC_DOT))
	{ 
		m_pStyle=PEN_STYLE_DOT;
        InvalidateRect(&m_pRectSample);
        UpdateWindow();
	}// TODO: Add your control notification handler code here
	
}

void CPenDlg::OnSolid() 
{
	if (IsDlgButtonChecked(IDC_SOLID))
	{ 
		m_pStyle=PEN_STYLE_SOLID;
        InvalidateRect(&m_pRectSample);
        UpdateWindow();
	}// TODO: Add your control notification handler code here
	
}

void CPenDlg::OnChangeWidth() 
{
	int tmp;
    tmp=(int)GetDlgItemInt(IDC_WIDTH);
    if ((tmp>0)&&(tmp<7))
	{
      m_pWidth=tmp;
      InvalidateRect(&m_pRectSample);
      UpdateWindow();
	}// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	
}




void CPenDlg::Onyanse() 
{
	CColorDialog ColorDialog;
	if(ColorDialog.DoModal()==IDOK)
	{
	   m_pColor=ColorDialog.GetColor();
	   InvalidateRect(NULL);// TODO: Add your control notification handler code here
	}
}

void CPenDlg::OnSelchangeNumber() 
{
	m_pHuatu.GetLBText(m_pHuatu.GetCurSel( ),m_Tu);
    InvalidateRect(&m_pRectSample);// TODO: Add your control notification handler code here
	
}

void CPenDlg::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) 
{
	m_pQx=m_pQx-5;
	m_pQy=m_pQy-5;
	m_pZx=m_pZx+5;
	m_pZy=m_pZy+5;// TODO: Add your message handler code here and/or call default
	InvalidateRect(&m_pRectSample);
	UpdateData(false);//与相对的变量同时更新
	CDialog::OnHScroll(nSBCode, nPos, pScrollBar);
}

void CPenDlg::OnChangeqidianX() 
{
	int tmp;
    tmp=(int)GetDlgItemInt(IDC_qidianX);
    m_pQx=tmp;
    InvalidateRect(&m_pRectSample);
    UpdateWindow();
   // TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here  
	
}

void CPenDlg::OnChangeqidianY() 
{
	int tmp;
    tmp=(int)GetDlgItemInt(IDC_qidianY);
    m_pQy=tmp;
    InvalidateRect(&m_pRectSample);
    UpdateWindow();// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	
}

void CPenDlg::OnChangezhongdianX() 
{
	int tmp;
    tmp=(int)GetDlgItemInt(IDC_zhongdianX);
    m_pZx=tmp;
    InvalidateRect(&m_pRectSample);
    UpdateWindow();// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	
}

void CPenDlg::OnChangezhongdianY() 
{
	int tmp;
    tmp=(int)GetDlgItemInt(IDC_zhongdianY);
    m_pZy=tmp;
    InvalidateRect(&m_pRectSample);
    UpdateWindow();// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	
}

⌨️ 快捷键说明

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