www.pudn.com > assigment1.zip > LINE_PROPERTY.cpp
// LINE_PROPERTY.cpp : implementation file
//
#include "stdafx.h"
#include "myGraphics.h"
#include "LINE_PROPERTY.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CLINE_PROPERTY dialog
CLINE_PROPERTY::CLINE_PROPERTY(CWnd* pParent /*=NULL*/)
: CDialog(CLINE_PROPERTY::IDD, pParent)
{
//{{AFX_DATA_INIT(CLINE_PROPERTY)
//}}AFX_DATA_INIT
// m_red.SetRange(0,255);
// m_red.SetRangeMin(0);
//CClientDC dc(this);
// int i,j;
// iRed=m_red.GetPos();
// for (i=280;i<330;i++)
// for(j=260;j<310;j++)
// dc.SetPixel(i,j,RGB(0,0,0));
// m_red.SetRange(0,255);
iRed=0;
iGreen=0;
iBlue=0;
m_line_method=0;
m_line_width=0;
}
void CLINE_PROPERTY::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CLINE_PROPERTY)
DDX_Control(pDX, IDC_SLIDER5, m_blue);
DDX_Control(pDX, IDC_SLIDER4, m_green);
DDX_Control(pDX, IDC_SLIDER3, m_red);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CLINE_PROPERTY, CDialog)
//{{AFX_MSG_MAP(CLINE_PROPERTY)
ON_BN_CLICKED(IDC_RADIO1, OnRadio1)
ON_BN_CLICKED(IDC_RADIO2, OnRadio2)
ON_BN_CLICKED(IDC_RADIO3, OnRadio3)
ON_NOTIFY(NM_RELEASEDCAPTURE, IDC_SLIDER3, OnReleasedcaptureSlider3)
ON_WM_CREATE()
ON_WM_SIZE()
ON_NOTIFY(NM_RELEASEDCAPTURE, IDC_SLIDER4, OnReleasedcaptureSlider4)
ON_NOTIFY(NM_RELEASEDCAPTURE, IDC_SLIDER5, OnReleasedcaptureSlider5)
ON_BN_CLICKED(IDC_RADIO4, OnRadio4)
ON_BN_CLICKED(IDC_RADIO5, OnRadio5)
ON_BN_CLICKED(IDC_RADIO6, OnRadio6)
ON_BN_CLICKED(IDC_RADIO7, OnRadio7)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CLINE_PROPERTY message handlers
void CLINE_PROPERTY::OnRadio1()
{
m_line_method=0;
}
void CLINE_PROPERTY::OnRadio2()
{
m_line_method=1;
}
void CLINE_PROPERTY::OnRadio3()
{
m_line_method=2;
}
//DEL void CLINE_PROPERTY::OnReleasedcaptureSlider1(NMHDR* pNMHDR, LRESULT* pResult)
//DEL {
//DEL // TODO: Add your control notification handler code here
//DEL // iRed=m_red.GetPos();
//DEL // glBegin(GL_POLYGON);
//DEL // glVertex2i(0,0);
//DEL // glVertex2i(20,0);
//DEL // glVertex2i(0,20);
//DEL // glVertex2i(20,20);
//DEL // glEnd();
//DEL // glFinish();
//DEL *pResult = 0;
//DEL }
void CLINE_PROPERTY::OnReleasedcaptureSlider3(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
//iRed=m_red.GetP11os();
// CClientDC dc(this);
// CBrush brush(RGB(255,0,0));
// dc.LineTo(111,111);
// int i,j;
// iRed=m_red.GetPos();
// for (i=280;i<330;i++)
// for(j=260;j<310;j++)
// dc.SetPixel(i,j,RGB(m_red.GetPos(),0,0));
//CBrush;
// dc.Rectangle(280,270,330,320);
iRed=m_red.GetPos();DrawColor();
*pResult = 0;
}
BOOL CLINE_PROPERTY::OnInitDialog()
{
CDialog::OnInitDialog();
CClientDC dc(this);
int i,j;
iRed=m_red.GetPos();
for (i=280;i<330;i++)
for(j=260;j<310;j++)
dc.SetPixel(i,j,RGB(0,0,0));
m_red.SetRange(0,255);
m_green.SetRange(0,255);
m_blue.SetRange(0,255);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
BOOL CLINE_PROPERTY::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Add your specialized code here and/or call the base class
// iRed=m_red.GetPos();
// for (i=280;i<330;i++)
// for(j=260;j<310;j++)
// dc.SetPixel(i,j,RGB(0,0,0));
// m_red.SetRange(0,255);
return CDialog::PreCreateWindow(cs);
}
void CLINE_PROPERTY::DrawColor()
{
CClientDC dc(this);
// int i,j;
//用点阵画矩形较慢
// iRed=m_red.GetPos();
// for (i=280;i<330;i++)
// for(j=260;j<310;j++)
// dc.SetPixel(i,j,RGB(iRed,iGreen,iBlue));
//用vc自戴函数,快,无频闪
CRgn rgnA;
CBrush *m_brush=new CBrush(RGB(iRed,iGreen,iBlue)) ;
CPoint ptVertex1[4];
ptVertex1[0].x = 280;
ptVertex1[0].y = 260;
ptVertex1[1].x = 330;
ptVertex1[1].y = 260;
ptVertex1[2].x = 330;
ptVertex1[2].y = 310;
ptVertex1[3].x = 280;
ptVertex1[3].y = 310;
VERIFY(rgnA.CreatePolygonRgn( ptVertex1,4, ALTERNATE));
dc.FillRgn(&rgnA,m_brush);
}
int CLINE_PROPERTY::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CDialog::OnCreate(lpCreateStruct) == -1)
return -1;
// DrawColor();
// TODO: Add your specialized creation code here
return 0;
}
void CLINE_PROPERTY::OnSize(UINT nType, int cx, int cy)
{
CDialog::OnSize(nType, cx, cy);
}
BOOL CLINE_PROPERTY::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext)
{
// TODO: Add your specialized code here and/or call the base class
// DrawColor();
return CDialog::Create(IDD, pParentWnd);
}
void CLINE_PROPERTY::Serialize(CArchive& ar)
{
if (ar.IsStoring())
{ // storing code
}
else
{ // loading code
}
//DrawColor();
}
int CLINE_PROPERTY::DoModal()
{
// TODO: Add your specialized code here and/or call the base class
// DrawColor();
return CDialog::DoModal();
}
void CLINE_PROPERTY::OnReleasedcaptureSlider4(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
iGreen=m_green.GetPos();DrawColor();
*pResult = 0;
}
void CLINE_PROPERTY::OnReleasedcaptureSlider5(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
iBlue=m_blue.GetPos();DrawColor();
*pResult = 0;
}
void CLINE_PROPERTY::OnRadio4()
{
// TODO: Add your control notification handler code here
m_line_width=1;
}
void CLINE_PROPERTY::OnRadio5()
{
// TODO: Add your control notification handler code here
m_line_width=2;
}
void CLINE_PROPERTY::OnRadio6()
{
// TODO: Add your control notification handler code here
m_line_width=4;
}
void CLINE_PROPERTY::OnRadio7()
{
// TODO: Add your control notification handler code here
m_line_width=8;
}