www.pudn.com > JingXiang-Design-Jeff.rar > ForLancet.cpp
// ForLancet.cpp : implementation file
//
#include "stdafx.h"
#include "Design.h"
#include "ForLancet.h"
#include "MainFrm.h"
#include "DesignDoc.h"
#include "DesignView.h"
#include "BMPFILE.h"
//#include "Design.cpp"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// ForLancet dialog
ForLancet::ForLancet(CWnd* pParent /*=NULL*/)
: CDialog(ForLancet::IDD, pParent)
{
// pBMPDataForLancet=new BYTE[BmpInfoHeader.biSizeImage+1024];
//{{AFX_DATA_INIT(ForLancet)
m_Lancet = 0;
m_RangeOfArea = -1;
//}}AFX_DATA_INIT
}
ForLancet::~ForLancet()
{
}
void ForLancet::DoDataExchange(CDataExchange* pDX)
{
IsDataChanged=TRUE;
/* // For Debug
CString Tmp;
Tmp.Format("IsDataChangedForOnOk=%d,IsDataChange=%d",IsDataChangedForOnOk,IsDataChanged);
AfxMessageBox(Tmp);
*/
(CButton*)GetDlgItem(IDAPPLY)->EnableWindow(IsDataChangedForOnOk);
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(ForLancet)
DDX_Text(pDX, IDC_EDIT1, m_Lancet);
DDV_MinMaxInt(pDX, m_Lancet, 0, 255);
DDX_Radio(pDX, IDC_RADIO1, m_RangeOfArea);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(ForLancet, CDialog)
//{{AFX_MSG_MAP(ForLancet)
ON_WM_HSCROLL()
ON_WM_VSCROLL()
ON_EN_CHANGE(IDC_EDIT1, OnChangeEdit1)
ON_BN_CLICKED(IDGOBACK, OnGoback)
ON_BN_CLICKED(IDAUTODETECT, OnAutodetect)
ON_EN_UPDATE(IDC_EDIT1, OnUpdateEdit1)
ON_BN_CLICKED(IDC_RADIO2, OnRadio2)
ON_BN_CLICKED(IDC_RADIO1, OnRadio1)
ON_BN_CLICKED(IDAPPLY, OnApply)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// ForLancet message handlers
int ForLancet::DoModal()
{
CDesignDoc *pDesignDoc;
CMainFrame* pMFrame=(CMainFrame*)(AfxGetApp()->m_pMainWnd);
pDesignDoc=(CDesignDoc*)pMFrame->GetActiveDocument();
m_Lancet=pDesignDoc->BitMap.SwitchForLancet;
m_RangeOfArea=pDesignDoc->BitMap.RangeOfAreaForLancet;
return CDialog::DoModal();
}
BOOL ForLancet::OnInitDialog()
{
CDesignDoc *pDesignDoc;
CMainFrame* pMFrame=(CMainFrame*)(AfxGetApp()->m_pMainWnd);
pDesignDoc=(CDesignDoc*)pMFrame->GetActiveDocument();
pSlider_=(CSliderCtrl*)GetDlgItem(IDC_SLIDER1);
pSlider_->SetRange(0,255);
pSlider_->SetPos(m_Lancet);
///
pSpin_=(CSpinButtonCtrl*)GetDlgItem(IDC_SPIN1);
pSpin_->SetRange(0,255);
pSpin_->SetPos(m_Lancet);
if(!pDesignDoc->BitMap.RectSelected)
{
GetDlgItem(IDC_RADIO2)->EnableWindow(0);
this->m_RangeOfArea=0;
}
HaveAutoDetected=FALSE;
IsDataChanged=TRUE;
IsDataChangedForOnOk=TRUE;
RangeOfAreaBak=pDesignDoc->BitMap.RangeOfAreaForLancet;
// Adjust The Public Buffer To Fit The Data Size
if(pDesignDoc->BitMap.PublicBufferSizeBitMap.BmpInfoHeader.biSizeImage)
{
pDesignDoc->BitMap.PublicBufferSize=pDesignDoc->BitMap.BmpInfoHeader.biSizeImage+FIRSTPUBLICBUFFERSIZE;
BYTE *pTmpNow=new BYTE[pDesignDoc->BitMap.PublicBufferSize];
if(!pTmpNow){ CString Msg;Msg.Format("Mem Alloc Error At File 'ForLancet.cpp',in function 'OnInitDialog()"); return FALSE;}
delete[] pDesignDoc->BitMap.pPublicBuffer;
pDesignDoc->BitMap.pPublicBuffer=pTmpNow;
}
if(!pDesignDoc->BitMap.IsLancet)
memcpy(pDesignDoc->BitMap.pPublicBuffer,pDesignDoc->BitMap.pBMPData,pDesignDoc->BitMap.BmpInfoHeader.biSizeImage);
CDialog::OnInitDialog();
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void ForLancet::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
if(pScrollBar->GetDlgCtrlID()==IDC_SLIDER1)
{
CSliderCtrl *pSlider=(CSliderCtrl*)pScrollBar;
m_Lancet=pSlider->GetPos();
UpdateData(FALSE);
pSpin_->SetPos(m_Lancet);
}
CDialog::OnHScroll(nSBCode, nPos, pScrollBar);
}
void ForLancet::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
if(pScrollBar->GetDlgCtrlID()==IDC_SPIN1)
{
m_Lancet=nPos;
UpdateData(FALSE);
pSlider_->SetPos(m_Lancet);
}
CDialog::OnVScroll(nSBCode, nPos, pScrollBar);
}
void ForLancet::OnChangeEdit1()
{
UpdateData(TRUE);
pSlider_->SetPos(m_Lancet);
pSpin_->SetPos(m_Lancet);
// 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 ForLancet::OnGoback()
{
CDesignDoc *pDesignDoc;
CMainFrame* pMFrame=(CMainFrame*)(AfxGetApp()->m_pMainWnd);
pDesignDoc=(CDesignDoc*)pMFrame->GetActiveDocument();
m_Lancet=pDesignDoc->BitMap.SwitchForLancet;
UpdateData(FALSE);
pSlider_->SetPos(m_Lancet);
pSpin_->SetPos(m_Lancet);
return;
}
void ForLancet::OnAutodetect()
{
CWaitCursor TheCursor;
CDesignDoc *pDesignDoc;
CMainFrame* pMFrame=(CMainFrame*)(AfxGetApp()->m_pMainWnd);
pDesignDoc=(CDesignDoc*)pMFrame->GetActiveDocument();
HaveAutoDetected=TRUE;
this->ReloadImage();
if(pDesignDoc->BitMap.RectSelected&&m_RangeOfArea==1)
pDesignDoc->BitMap.GetRectGrayRatio(pDesignDoc->BitMap.ReallyRectOfBMP);
else
pDesignDoc->BitMap.GetGrayRatio();
this->m_Lancet=pDesignDoc->BitMap.AutoGetSwitchForLancet(0);
pSlider_->SetPos(m_Lancet);
pSpin_->SetPos(m_Lancet);
UpdateData(FALSE);
return;
}
void ForLancet::OnUpdateEdit1()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::OnInitDialog()
// function to send the EM_SETEVENTMASK message to the control
// with the ENM_UPDATE flag ORed into the lParam mask.
// TODO: Add your control notification handler code here
return;
}
void ForLancet::OnRadio2()
{
// For Debug
UpdateData(TRUE);
/*CString Tmp;
Tmp.Format("Radio2=%d",m_RangeOfArea);
AfxMessageBox(Tmp);*/
return;
}
void ForLancet::OnRadio1()
{
UpdateData(TRUE);
}
void ForLancet::OnApply()
{
CDesignDoc *pDesignDoc;
CDesignView *pDesignView;
CMainFrame* pMFrame=(CMainFrame*)(AfxGetApp()->m_pMainWnd);
pDesignView=(CDesignView*)pMFrame->GetActiveView();
pDesignDoc=(CDesignDoc*)pMFrame->GetActiveDocument();
UpdateData();
pDesignDoc->BitMap.RangeRectBak=pDesignDoc->BitMap.ReallyRectOfBMP;
RangeOfAreaBak=this->m_RangeOfArea;
if(m_RangeOfArea==1)
pDesignView->LancetFromSwitch(this->m_Lancet,&(pDesignDoc->BitMap.ReallyRectOfBMP));
else
pDesignView->LancetFromSwitch(this->m_Lancet);
pDesignView->Invalidate();
if(pDesignView->IsHistogramShowed)
{
pDesignView->pHiShow->SendMessage(WM_COMMAND,IDC_REFRESH);
}
pDesignDoc->BitMap.RangeOfAreaForLancet=this->m_RangeOfArea;
this->IsDataChanged=FALSE;
this->HaveAutoDetected=FALSE;
(CButton*)GetDlgItem(IDAPPLY)->EnableWindow(FALSE);
return;
}
void ForLancet::OnOK()
{
// TODO: Add extra validation here
IsDataChangedForOnOk=IsDataChanged;
CDesignDoc *pDesignDoc;
CDesignView *pDesignView;
CMainFrame* pMFrame=(CMainFrame*)(AfxGetApp()->m_pMainWnd);
pDesignView=(CDesignView*)pMFrame->GetActiveView();
pDesignDoc=(CDesignDoc*)pMFrame->GetActiveDocument();
UpdateData();
RangeOfAreaBak=this->m_RangeOfArea;
pDesignDoc->BitMap.RangeRectBak=pDesignDoc->BitMap.ReallyRectOfBMP;
if(IsDataChangedForOnOk)
{
//pDesignView->LancetFromSwitch(this->m_Lancet);
if(m_RangeOfArea==1)
pDesignView->LancetFromSwitch(this->m_Lancet,&(pDesignDoc->BitMap.ReallyRectOfBMP));
else
pDesignView->LancetFromSwitch(this->m_Lancet);
pDesignView->Invalidate();
if(pDesignView->IsHistogramShowed)
{
pDesignView->pHiShow->SendMessage(WM_COMMAND,IDC_REFRESH);
}
}
pDesignDoc->BitMap.RangeOfAreaForLancet=this->m_RangeOfArea;
CDialog::OnOK();
}
BOOL ForLancet::ReloadImage()
{
CDesignDoc *pNowDoc;
CMainFrame* pMFrame=(CMainFrame*)(AfxGetApp()->m_pMainWnd);
pNowDoc=(CDesignDoc*)pMFrame->GetActiveDocument();
if(!pNowDoc->BitMap.IsLancet)
return FALSE;
//pNowDoc->BitMap.SetIsGray(TRUE);
memcpy(pNowDoc->BitMap.pBMPData,pNowDoc->BitMap.pPublicBuffer,pNowDoc->BitMap.BmpInfoHeader.biSizeImage);
//pNowDoc->BitMap.SetIsGray(TRUE);
return TRUE;
}
void ForLancet::OnCancel()
{
CDesignDoc *pDoc;
CMainFrame* pMFrame=(CMainFrame*)(AfxGetApp()->m_pMainWnd);
pDoc=(CDesignDoc*)pMFrame->GetActiveDocument();
if(!HaveAutoDetected||!pDoc->BitMap.IsLancet) //如果没自动选择过,
{CDialog::OnCancel();return;} //或没有二值锐化过,
//不用恢复二值锐化数据!
CWaitCursor WaitCursor;
this->ReloadImage();
if(RangeOfAreaBak==1)
pDoc->BitMap.GetLancet(pDoc->BitMap.SwitchForLancet,&(pDoc->BitMap.RangeRectBak));
else
pDoc->BitMap.GetLancet(pDoc->BitMap.SwitchForLancet);
CDialog::OnCancel();
return;
}