www.gusucode.com > VC++增强型“画图版”及图像处理程序源码程序 > VC++增强型“画图版”及图像处理程序源码程序\code\SetColDlg.cpp

    // SetColDlg.cpp : implementation file
// Downlaod by http://www.NewXing.com

#include "stdafx.h"
#include "毕业设计.h"
#include "SetColDlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// CSetColDlg dialog


CSetColDlg::CSetColDlg(BYTE r,BYTE g,BYTE b,CWnd* pParent /*=NULL*/)
	: CDialog(CSetColDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CSetColDlg)
	//}}AFX_DATA_INIT
	pr = r;
	pg = g;
	pb = b;
	or = r;
	og = g;
	ob = b;
	mr = r;
	mg = g;
	mb = b;
}


void CSetColDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CSetColDlg)
	DDX_Text(pDX, IDC_EDIT1, mr);
	DDX_Text(pDX, IDC_EDIT2, mg);
	DDX_Text(pDX, IDC_EDIT3, mb);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CSetColDlg, CDialog)
	//{{AFX_MSG_MAP(CSetColDlg)
	ON_WM_PAINT()
	ON_WM_LBUTTONDBLCLK()
	ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
	ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
	ON_EN_KILLFOCUS(IDC_EDIT1, OnOK)
	ON_EN_KILLFOCUS(IDC_EDIT2, OnOK)
	ON_EN_KILLFOCUS(IDC_EDIT3, OnOK)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CSetColDlg message handlers
void CSetColDlg::OnOK(){
	GetValue();
}

void CSetColDlg::GetValue(){
	UpdateData();
	pr = mr>255?255:mr;
	pg = mg>255?255:mg;
	pb = mb>255?255:mb;
	mr = pr,mg = pg,mb = pb;
	UpdateData(FALSE);
	this->Invalidate();
}

BOOL CSetColDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CSetColDlg::OnPaint() 
{
	CPaintDC dc(this); // device context for painting
	
	// TODO: Add your message handler code here
	int i,j;
//	for(int i = 0;i<256;i++){
//		for(int j = 0;j<256;j++){
//			dc.SetPixel(i+10,j+10,RGB(i,j,0));
//		}
//	}
	CDC dp;
	CBitmap cbp;
	dp.CreateCompatibleDC(&dc);
	cbp.LoadBitmap(IDB_BITMAP1);
	dp.SelectObject(&cbp);
	dc.BitBlt(10,10,256,256,&dp,0,0,SRCCOPY);

	dc.MoveTo(pr,pg+10);
	dc.LineTo(pr+20,pg+10);
	dc.MoveTo(pr+10,pg);
	dc.LineTo(pr+10,pg+20);

	for(i = 0;i<256;i++){
		for(j = 0;j<30;j++){
			dc.SetPixel(j+280,i+10,RGB(pr,pg,i));
		}
	}
	dc.MoveTo(270,pb+10);
	dc.LineTo(280,pb+10);

	for(i = 0;i<50;i++){
		for(j = 0;j<80;j++){
			if(i<25){
				dc.SetPixel(j+330,i+10,RGB(pr,pg,pb));
			}
			else{
				dc.SetPixel(j+330,i+10,RGB(or,og,ob));
			}
		}
	}
	// Do not call CDialog::OnPaint() for painting messages
}

void CSetColDlg::OnLButtonDblClk(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	if(point.x>=10&&point.x<266&&point.y>=10&&point.y<266){
		pr = point.x-10;
		pg = point.y-10;
		mr = pr;
		mg = pg;
		UpdateData(FALSE);
		this->Invalidate();
	}
	if(point.x>=280&&point.x<310&&point.y>=10&&point.y<266){
		pb = point.y-10;
		mb = pb;
		UpdateData(FALSE);
		this->Invalidate();
	}
	CDialog::OnLButtonDblClk(nFlags, point);
}

void CSetColDlg::OnButton2() 
{
	// TODO: Add your control notification handler code here
	OnCancel();
}

void CSetColDlg::OnButton1() 
{
	// TODO: Add your control notification handler code here
	GetValue();
	CDialog::OnOK();
}