www.gusucode.com > VC++遥感原理与数字摄影测量实习源码程序 > VC++遥感原理与数字摄影测量实习源码程序\code\ImageProcess\BMPDlg.cpp

    // BMPDlg.cpp : implementation file
// Download by http://www.NewXing.com

#include "stdafx.h"
#include "ImageProcess.h"
#include "BMPDlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// CBMPDlg dialog


CBMPDlg::CBMPDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CBMPDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CBMPDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	m_dBmp.Empty();
	m_nHMax = 100;
	m_nHMax = 0;
	m_nVMax = 100;
	m_nVMin = 0;
}


void CBMPDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CBMPDlg)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CBMPDlg, CDialog)
	//{{AFX_MSG_MAP(CBMPDlg)
	ON_WM_PAINT()
	ON_WM_DESTROY()
	ON_WM_HSCROLL()
	ON_WM_VSCROLL()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CBMPDlg message handlers

void CBMPDlg::OnPaint() 
{
	CPaintDC dc(this); // device context for painting
	
	// TODO: Add your message handler code here
	if (m_dBmp.IsEmpty())
		return;
	
	CPoint point(1,1);
	CSize size;
	CRect rect;
	GetClientRect(&rect);
	size  = m_dBmp.GetDimensions();
	
	m_dBmp.Draw(&dc, point, size);

//	GetScrollBarCtrl(SB_HORZ)->SetScrollRange(0,size.cx,TRUE);
//	CWnd::SetScrollRange(SB_HORZ,0,size.cx,TRUE);
	// Do not call CDialog::OnPaint() for painting messages
}

BOOL CBMPDlg::OnEraseBkgnd( CDC* pDC )
{
	return FALSE;
}

void CBMPDlg::OnDestroy()
{
	CDialog::OnDestroy();
	
	// TODO: Add your message handler code here
	m_dBmp.Empty();
}

BOOL CBMPDlg::LoadBitmap(LPCTSTR lpszPathName)
{
	CFile file;
	if(!file.Open(lpszPathName,CFile::modeRead|CFile::shareDenyWrite))
	{
		file.Close();
		return FALSE;
	}
	if(!m_dBmp.Read(&file))
	{
		file.Close();
		return FALSE;
	}
	m_nHMax = m_dBmp.GetDimensions().cx;
	m_nVMax = m_dBmp.GetDimensions().cy;
	SetScrollRange(SB_HORZ, 0, m_nHMax);
	SetScrollRange(SB_VERT, 0, m_nVMax);
	file.Close();
	return TRUE;	
}

CScrollBar* CBMPDlg::GetScrollBarCtrl(int nBar) const
{
	// TODO: Add your specialized code here and/or call the base class
	
	return CDialog::GetScrollBarCtrl(nBar);
}

BOOL CBMPDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	SetScrollRange(SB_HORZ, 0, 50);
	SetScrollRange(SB_VERT, 0, 50);

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

void CBMPDlg::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) 
{
	// TODO: Add your message handler code here and/or call default
	int nCurPos;
	int nPrevPos;
	CRect rect;

	GetClientRect(&rect);
	nPrevPos  =  GetScrollPos(SB_HORZ);
	nCurPos  =  nPrevPos;
	switch(nSBCode)
	{
	case SB_LEFT:
		SetScrollPos(SB_HORZ, 0);
		ScrollWindow(0, 0);
		break;
	case SB_RIGHT:
		SetScrollPos(SB_HORZ, 100);
		ScrollWindow(-rect.Width(), 0);
		break;
	case SB_PAGELEFT:
		nCurPos = nPrevPos - 10;
		if(nCurPos < 0)
			nCurPos = 0;
		SetScrollPos(SB_HORZ, nCurPos);
		break;
	case SB_PAGERIGHT:
		nCurPos = nPrevPos + 10;
		if(nCurPos > m_nHMax)
			nCurPos = m_nHMax;
		SetScrollPos(SB_HORZ, nCurPos);
		break;
	case SB_THUMBPOSITION:
		SetScrollPos(SB_HORZ, nPos);
		break;
	case SB_THUMBTRACK:
		break;
	case SB_LINELEFT:
		nCurPos = nPrevPos - 2;
		if(nCurPos < 0)
			nCurPos = 0;
		SetScrollPos(SB_HORZ, nCurPos);
		break;
	case SB_LINERIGHT:
		nCurPos = nPrevPos + 2;
		if(nCurPos > m_nHMax)
			nCurPos = m_nHMax;
		SetScrollPos(SB_HORZ, nCurPos);
		break;
	case SB_ENDSCROLL:
		break;
	default:
		break;
	}
	nCurPos = GetScrollPos(SB_HORZ);
	ScrollWindow(rect.Width() * (nPrevPos - nCurPos) / m_nHMax, 0);

	CDialog::OnHScroll(nSBCode, nPos, pScrollBar);
//	InvalidateRect(rect,TRUE);
}

void CBMPDlg::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) 
{
	// TODO: Add your message handler code here and/or call default
	int nCurPos;
	int nPrevPos;
	CRect rect;
    
	GetClientRect(&rect);
	nPrevPos = GetScrollPos(SB_VERT);
	nCurPos = nPrevPos;
	switch(nSBCode)
	{
	case SB_LEFT:
		SetScrollPos(SB_VERT, 0);
		ScrollWindow(0, 0);
		break;
	case SB_RIGHT:
		SetScrollPos(SB_VERT, m_nVMax);
		ScrollWindow(-rect.Height(), 0);
		break;
	case SB_PAGELEFT:
		nCurPos = nPrevPos - 10;
		if(nCurPos < 0)
			nCurPos = 0;
		SetScrollPos(SB_VERT, nCurPos);
		break;
	case SB_PAGERIGHT:
		nCurPos = nPrevPos + 10;
		if(nCurPos > m_nVMax)
			nCurPos = m_nVMax;
		SetScrollPos(SB_VERT, nCurPos);
		break;
	case SB_THUMBPOSITION:
		SetScrollPos(SB_VERT, nPos);
		break;
	case SB_THUMBTRACK:
		break;
	case SB_LINELEFT:
		nCurPos = nPrevPos - 2;
		if(nCurPos < 0)
			nCurPos = 0;
		SetScrollPos(SB_VERT, nCurPos);
		break;
	case SB_LINERIGHT:
		nCurPos = nPrevPos + 2;
		if(nCurPos > m_nVMax)
			nCurPos = m_nVMax;
		SetScrollPos(SB_VERT,  nCurPos);
		break;
	case SB_ENDSCROLL:
		break;
	}
	nCurPos  =  GetScrollPos(SB_VERT);
	ScrollWindow(0, rect.Height() * (nPrevPos - nCurPos) / m_nVMax);

	CDialog::OnVScroll(nSBCode, nPos, pScrollBar);
}