www.pudn.com > XRayImg.rar > AjustBright.cpp


// AjustBright.cpp : implementation file
//

#include "stdafx.h"
#include "XRayImg.h"
#include "AjustBright.h"

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

/////////////////////////////////////////////////////////////////////////////
// CAjustBright dialog


CAjustBright::CAjustBright(CWnd* pParent /*=NULL*/)
: CDialog(CAjustBright::IDD, pParent)
{
//{{AFX_DATA_INIT(CAjustBright)
//}}AFX_DATA_INIT
m_bCreated=FALSE;
}


void CAjustBright::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAjustBright)
DDX_Control(pDX, IDC_PIC_OLD, m_picOld);
DDX_Control(pDX, IDC_PIC_NEW, m_picNew);

DDX_Control(pDX, IDC_EDIT3, m_edt1);
DDX_Control(pDX, IDC_EDIT2, m_edt2);
DDX_Control(pDX, IDC_EDIT1, m_edt3);
DDX_Text(pDX, IDC_EDIT1, m_iEdt1);
DDV_MinMaxInt(pDX, m_iEdt1, -100, 100);
DDX_Text(pDX, IDC_EDIT2, m_iEdt2);
DDV_MinMaxInt(pDX, m_iEdt2, 0, 200);
DDX_Text(pDX, IDC_EDIT3, m_iEdt3);
DDV_MinMaxInt(pDX, m_iEdt3, 0, 100);

DDX_Control(pDX, IDC_SLIDER1,m_slider1 );
DDX_Control(pDX, IDC_SLIDER2,m_slider2 );
DDX_Control(pDX, IDC_SLIDER3,m_slider3 );

DDX_Control(pDX, IDC_SPIN1,m_spin1 );
DDX_Control(pDX, IDC_SPIN2,m_spin2 );
DDX_Control(pDX, IDC_SPIN3,m_spin3 );

//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAjustBright, CDialog)
//{{AFX_MSG_MAP(CAjustBright)
ON_BN_CLICKED(IDC_DEFAULT, OnDefault)
ON_NOTIFY(NM_RELEASEDCAPTURE, IDC_SLIDER1, OnReleasedcaptureSlider1)
ON_EN_CHANGE(IDC_EDIT1, OnChangeEdit1)
ON_NOTIFY(NM_RELEASEDCAPTURE, IDC_SLIDER2, OnReleasedcaptureSlider2)
ON_EN_CHANGE(IDC_EDIT2, OnChangeEdit2)
ON_NOTIFY(NM_RELEASEDCAPTURE, IDC_SLIDER3, OnReleasedcaptureSlider3)
ON_EN_CHANGE(IDC_EDIT3, OnChangeEdit3)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CAjustBright message handlers
//***************************************************************
//函数功能: init
// 1) 设置参数
// 2) 创建完毕标志
//
//说明:
//***************************************************************
BOOL CAjustBright::OnInitDialog()
{
CDialog::OnInitDialog();

// TODO: Add extra initialization here
OnDefault();

m_bCreated=TRUE;

return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}

//***************************************************************
//函数功能: 调整亮度
// 1)
// 2)
//
//说明:
//***************************************************************
void CAjustBright::OnReleasedcaptureSlider1(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
m_iEdt1=m_slider1.GetPos();
if( !UpdateData(FALSE) ) return;

m_picNew.AdjustBCG(m_iEdt1,m_iEdt2,(float)m_iEdt3/10);

*pResult = 0;
}

void CAjustBright::OnChangeEdit1()
{
// 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.
if(!m_bCreated) return;

this->UpdateData(TRUE);
m_slider1.SetPos(m_iEdt1);

m_picNew.AdjustBCG(m_iEdt1,m_iEdt2,(float)m_iEdt3/10);

}

//***************************************************************
//函数功能: 调整对比度
// 1)
// 2)
//
//说明:
//***************************************************************
void CAjustBright::OnReleasedcaptureSlider2(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
m_iEdt2=m_slider2.GetPos();
if( !UpdateData(FALSE) ) return;

m_picNew.AdjustBCG(m_iEdt1,m_iEdt2,(float)m_iEdt3/10);

*pResult = 0;
}

void CAjustBright::OnChangeEdit2()
{
// 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.
if(!m_bCreated) return;

this->UpdateData(TRUE);
m_slider2.SetPos(m_iEdt2);

m_picNew.AdjustBCG(m_iEdt1,m_iEdt2,(float)m_iEdt3/10);

}

//***************************************************************
//函数功能: 调整GAMMA
// 1)
// 2)
//
//说明:
//***************************************************************
void CAjustBright::OnReleasedcaptureSlider3(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
m_iEdt3=m_slider3.GetPos();
if( !UpdateData(FALSE) ) return;

m_picNew.AdjustBCG(m_iEdt1,m_iEdt2,(float)m_iEdt3/10);

*pResult = 0;
}

void CAjustBright::OnChangeEdit3()
{
// 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.
if(!m_bCreated) return;

this->UpdateData(TRUE);
m_slider3.SetPos(m_iEdt3);

m_picNew.AdjustBCG(m_iEdt1,m_iEdt2,(float)m_iEdt3/10);

}
//***************************************************************
//函数功能: 设置初始化或复位参数
// 1) 设置初始化参数
// 2) 复位调整状态
//
//说明:
//***************************************************************
void CAjustBright::OnDefault()
{
// TODO: Add your control notification handler code here
CWaitCursor wait;

m_picNew.SetUndoID(IDS_DI_UNDO_ADJUST_BRIGHTNESS);

m_slider1.SetRange(-100,100,TRUE);
m_spin1.SetRange(-100,100);
m_iEdt1=0;
m_slider1.SetPos(0);

m_slider2.SetRange(0,200);
m_spin2.SetRange(0,200);
m_iEdt2=100;
m_slider2.SetPos(100);

m_slider3.SetRange(0,100);
m_spin3.SetRange(0,100);
m_iEdt3=10;
m_slider3.SetPos(10);

this->UpdateData(FALSE);

m_picNew.ResetColor();
}

//***************************************************************
//函数功能: 保存数据到视图中
// 1)
// 2)
//
//说明:
//***************************************************************
void CAjustBright::OnOK()
{
// TODO: Add extra validation here
BOOL bRst;
bRst=this->UpdateData(TRUE);
if( !bRst ) return;

bRst=g_theApp.ChangeDocDibSource(IDS_DI_UNDO_ADJUST_BRIGHTNESS,
m_iEdt1,m_iEdt2,m_iEdt3);
if(!bRst)
{
::AfxMessageBox(_T("颜色调整失败"),MB_OK+MB_APPLMODAL+MB_ICONSTOP);
return ;
}

CDialog::OnOK();
}

//***************************************************************
//函数功能: 结束
// 1)
// 2)
//
//说明:
//***************************************************************
void CAjustBright::OnCancel()
{
// TODO: Add extra cleanup here

CDialog::OnCancel();
}