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

📄 pendialog.cpp

📁 C++视图的程序
💻 CPP
字号:
// PenDialog.cpp : implementation file
//

#include "stdafx.h"
#include "Draw.h"
#include "PenDialog.h"

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

/////////////////////////////////////////////////////////////////////////////
// CPenDialog dialog


CPenDialog::CPenDialog(CWnd* pParent /*=NULL*/)
	: CDialog(CPenDialog::IDD, pParent)
{
	//{{AFX_DATA_INIT(CPenDialog)
	m_pWidth = 0;
	m_pStyle = -1;
	//}}AFX_DATA_INIT
}


void CPenDialog::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CPenDialog)
	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);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CPenDialog, CDialog)
	//{{AFX_MSG_MAP(CPenDialog)
	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)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CPenDialog message handlers

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

void CPenDialog::OnPaint() 
{
	CPaintDC dc(this); // device context for painting
	
	// TODO: Add your message handler code here
	CPen NewPen;
    CPen *pOldPen;
	switch(m_pStyle)
	{
	case PEN_STYLE_SOLID:
		NewPen.CreatePen(PS_SOLID,m_pWidth,RGB(0,0,0));
		break;
	case PEN_STYLE_DASH:
		NewPen.CreatePen(PS_DASH,m_pWidth,RGB(0,0,0));
		break;
	case PEN_STYLE_DOT:
		NewPen.CreatePen(PS_DOT,m_pWidth,RGB(0,0,0));
		break;
    default:
		NewPen.CreatePen(PS_SOLID,m_pWidth,RGB(0,0,0));
		break;
	}
	pOldPen=dc.SelectObject(&NewPen);
	dc.MoveTo(m_pRectSample.left+10,m_pRectSample.top+25);
	dc.LineTo(m_pRectSample.right-10,m_pRectSample.top+25);
    dc.SelectObject(pOldPen);	
	// Do not call CDialog::OnPaint() for painting messages
}

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

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

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

void CPenDialog::OnChangeWidth() 
{
	// 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
    int tmp;
	tmp=(int)GetDlgItemInt(IDC_WIDTH);
	if((tmp>0)&&(tmp<7))
	{
		m_pWidth=tmp;
		InvalidateRect(&m_pRectSample);
		UpdateWindow();
	}	
}

⌨️ 快捷键说明

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