www.pudn.com > DigtalImageProc.rar > BitmapRect.cpp
// BitmapRect.cpp : implementation file
//
#include "stdafx.h"
#include "BitmapRect.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CBitmapRect
CBitmapRect::CBitmapRect()
{
}
CBitmapRect::~CBitmapRect()
{
//ModifyStyle(0,WS_HSCROLL|WS_VSCROLL|ES_READONLY|ES_MULTILINE);
}
BEGIN_MESSAGE_MAP(CBitmapRect, CEdit)
//{{AFX_MSG_MAP(CBitmapRect)
ON_WM_PAINT()
ON_WM_MOUSEMOVE()
ON_WM_VSCROLL()
ON_WM_HSCROLL()
ON_WM_LBUTTONDOWN()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CBitmapRect message handlers
void CBitmapRect::OnPaint()
{
CPaintDC dc(this); // device context for painting
// TODO: Add your message handler code here
CRect rect;
GetClientRect(&rect);
if(ViewBmp.flag)
{
if(ViewBmp.GetHeight() < rect.Height() || ViewBmp.GetWidth() < rect.Width())
{
CBrush br(RGB(255,255,255));
dc.FillRect(&rect,&br);
}
ViewBmp.Display(0,0,&dc);
}
else
{
CBrush br(RGB(255,255,255));
dc.FillRect(&rect,&br);
}
}
HCURSOR hc = LoadCursor(NULL,IDC_ARROW);
void CBitmapRect::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
SetCursor(hc);
//CEdit::OnMouseMove(nFlags, point);
}
void CBitmapRect::SetBitmap(memBitmap &Bitmap)
{
orgBmp = Bitmap;
ShowScrollBar(SB_BOTH);
CRect rect;
GetClientRect(&rect);
int w = rect.Width(),h = rect.Height();
int cx = orgBmp.GetWidth(),cy = orgBmp.GetHeight();
if(cx > w)
{
this->EnableScrollBar(SB_HORZ);
this->SetScrollRange(SB_HORZ,0,cx-w);
}
else
EnableScrollBar(SB_HORZ,ESB_DISABLE_BOTH);
if(cy > h)
{
this->EnableScrollBar(SB_VERT);
this->SetScrollRange(SB_VERT,0,cy-h);
}
else
EnableScrollBar(SB_VERT,ESB_DISABLE_BOTH);
SetScrollPos(SB_HORZ,0);
SetScrollPos(SB_VERT,0);
if(!ViewBmp.flag)
ViewBmp.CreateDirect(min(w,cx),min(h,cy));
else
ViewBmp.ChangeSize(min(w,cx),min(h,cy));
ViewBmp.CopyRect(0,0,orgBmp);
InvalidateRect(&rect);
UpdateWindow();
}
void CBitmapRect::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
// TODO: Add your message handler code here and/or call default
int minpos;
int maxpos;
GetScrollRange(SB_VERT,&minpos, &maxpos);
maxpos = GetScrollLimit(SB_VERT);
// Get the current position of scroll box.
int curpos = GetScrollPos(SB_VERT);
// Determine the new position of scroll box.
switch (nSBCode)
{
case SB_TOP: // Scroll to far left.
curpos = minpos;
break;
case SB_BOTTOM: // Scroll to far right.
curpos = maxpos;
break;
case SB_ENDSCROLL: // End scroll.
break;
case SB_LINEUP: // Scroll left.
if (curpos > minpos)
curpos--;
break;
case SB_LINEDOWN: // Scroll right.
if (curpos < maxpos)
curpos++;
break;
case SB_PAGEUP: // Scroll one page left.
{
// Get the page size.
SCROLLINFO info;
GetScrollInfo(SB_VERT,&info, SIF_ALL);
if (curpos > minpos)
curpos = max(minpos, curpos - (int) info.nPage);
}
break;
case SB_PAGEDOWN: // Scroll one page right.
{
// Get the page size.
SCROLLINFO info;
GetScrollInfo(SB_VERT,&info, SIF_ALL);
if (curpos < maxpos)
curpos = min(maxpos, curpos + (int) info.nPage);
}
break;
case SB_THUMBPOSITION: // Scroll to absolute position. nPos is the position
curpos = nPos; // of the scroll box at the end of the drag operation.
break;
case SB_THUMBTRACK: // Drag scroll box to specified position. nPos is the
curpos = nPos; // position that the scroll box has been dragged to.
break;
}
// Set the new position of the thumb
SetScrollPos(SB_VERT,curpos);
ViewBmp.CopyRect(GetScrollPos(SB_HORZ),curpos,orgBmp);
CRect rect;
GetClientRect(&rect);
//GetParent()->
InvalidateRect(&rect);
UpdateWindow();
//CEdit::OnVScroll(nSBCode, nPos, pScrollBar);
}
void CBitmapRect::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
// TODO: Add your message handler code here and/or call default
int minpos;
int maxpos;
GetScrollRange(SB_HORZ,&minpos, &maxpos);
maxpos = GetScrollLimit(SB_HORZ);
// Get the current position of scroll box.
int curpos = GetScrollPos(SB_HORZ);
// Determine the new position of scroll box.
switch (nSBCode)
{
case SB_LEFT: // Scroll to far left.
curpos = minpos;
break;
case SB_RIGHT: // Scroll to far right.
curpos = maxpos;
break;
case SB_ENDSCROLL: // End scroll.
break;
case SB_LINELEFT: // Scroll left.
if (curpos > minpos)
curpos--;
break;
case SB_LINERIGHT: // Scroll right.
if (curpos < maxpos)
curpos++;
break;
case SB_PAGELEFT: // Scroll one page left.
{
// Get the page size.
SCROLLINFO info;
GetScrollInfo(SB_HORZ,&info, SIF_ALL);
if (curpos > minpos)
curpos = max(minpos, curpos - (int) info.nPage);
}
break;
case SB_PAGERIGHT: // Scroll one page right.
{
// Get the page size.
SCROLLINFO info;
GetScrollInfo(SB_HORZ,&info, SIF_ALL);
if (curpos < maxpos)
curpos = min(maxpos, curpos + (int) info.nPage);
}
break;
case SB_THUMBPOSITION: // Scroll to absolute position. nPos is the position
curpos = nPos; // of the scroll box at the end of the drag operation.
break;
case SB_THUMBTRACK: // Drag scroll box to specified position. nPos is the
curpos = nPos; // position that the scroll box has been dragged to.
break;
}
SetScrollPos(SB_HORZ,curpos);
ViewBmp.CopyRect(curpos,GetScrollPos(SB_VERT),orgBmp);
CRect rect;
GetClientRect(&rect);
//GetParent()->
InvalidateRect(&rect);
UpdateWindow();
}
void CBitmapRect::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
//CEdit::OnLButtonDown(nFlags, point);
}
void CBitmapRect::Close()
{
CRect rect;
orgBmp.Release();
ViewBmp.Release();
GetClientRect(&rect);
InvalidateRect(&rect);
UpdateWindow();
}