📄 zoomindlg.cpp
字号:
// ZoomInDlg.cpp : implementation file
//
#include "stdafx.h"
#include "MYFUSION.h"
#include "ZoomInDlg.h"
#include "MainFrm.h"
#include "MYFUSIONDoc.h"
#include "MYFUSIONView.h"
#include "BitMapDC.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CZoomInDlg dialog
CZoomInDlg::CZoomInDlg(CWnd* pParent /*=NULL*/)
: CDialog(CZoomInDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CZoomInDlg)
m_ZoomStr = _T("");
//}}AFX_DATA_INIT
pbmp=NULL;
m_ImageMeasure=AfxGetApp()->LoadCursor(IDC_MEASURE);
bIndest=FALSE;
bActiveView = FALSE;
DIBInMid = CPoint(-1,-1);
bMoveWithMouse = TRUE;
rcDest = CRect(-1,-1,-1,-1);
rcDestTheory = CRect(-1,-1,-1,-1);
bEditChanged= FALSE;
pView = NULL;
}
CZoomInDlg::~CZoomInDlg()
{
if(pbmp!=NULL)
delete pbmp;
}
void CZoomInDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CZoomInDlg)
DDX_Control(pDX, IDC_ZOOM_COMBO, m_ZoomCombo);
DDX_CBString(pDX, IDC_POINTPOSITION, m_PointInfo);
DDX_CBString(pDX, IDC_ZOOM_COMBO, m_ZoomStr);
DDV_MaxChars(pDX, m_ZoomStr, 4);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CZoomInDlg, CDialog)
ON_WM_CONTEXTMENU()
//{{AFX_MSG_MAP(CZoomInDlg)
ON_WM_DESTROY()
ON_WM_CLOSE()
ON_WM_PAINT()
ON_COMMAND(ID_DEFAULT_SIZE_ZOOMIN, OnDefaultSizeZoomIn)
ON_COMMAND(ID_DEFAULT_LOCATION_ZOOMIN, OnDefaultLocationZoomIn)
ON_COMMAND(ID_HIDE_ZOOMINDLG, OnHideZoomZInDlg)
ON_WM_SIZE()
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONUP()
ON_WM_MOUSEMOVE()
ON_WM_SETCURSOR()
ON_CBN_SELCHANGE(IDC_ZOOM_COMBO, OnSelchangeZoomCombo)
ON_CBN_EDITCHANGE(IDC_ZOOM_COMBO, OnEditchangeZoomCombo)
//}}AFX_MSG_MAP
ON_MESSAGE(WM_REDRAWZOOMIN,RedrawZoomIn)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CZoomInDlg message handlers
BOOL CZoomInDlg::OnInitDialog()
{
CDialog::OnInitDialog();
bpbmpChanged = FALSE;
bRedrawControl = FALSE;
CRect ZoomInPos;
ZoomInPos.left = AfxGetApp()->GetProfileInt("ZOONINDLG","NavPosLeft",-1);
ZoomInPos.right = AfxGetApp()->GetProfileInt("ZOONINDLG","NavPosRight",32767);
ZoomInPos.top = AfxGetApp()->GetProfileInt("ZOONINDLG","NavPosTop",-1);
ZoomInPos.bottom = AfxGetApp()->GetProfileInt("ZOONINDLG","NavPosBottom",32767);
ZoomInZoom = AfxGetApp()->GetProfileInt("ZOONINDLG","ZoomInZoom",-1);
if(ZoomInZoom < 1 )
ZoomInZoom = 3;
if(ZoomInZoom > 16)
ZoomInZoom = 16;
int nFullWidth=::GetSystemMetrics(SM_CXSCREEN);
int nFullHeight=::GetSystemMetrics(SM_CYSCREEN);
if(ZoomInPos.left<0 || ZoomInPos.right<0 || ZoomInPos.top<0 || ZoomInPos.bottom<0
|| ZoomInPos.left>=nFullWidth-100 || ZoomInPos.top>=nFullHeight-100
|| ZoomInPos.Width()<ZoomWndWidth || ZoomInPos.Height()<ZoomWndHeight )
{
CMDIFrameWnd* pAppFrame = (CMDIFrameWnd*) AfxGetApp()->m_pMainWnd;
ASSERT(pAppFrame->IsKindOf(RUNTIME_CLASS( CMDIFrameWnd )));
CRect rc;
pAppFrame->GetClientRect(&rc);
pAppFrame->ClientToScreen(&rc);//Screen Coordinate
//create ZoomInigationDialog with cx=ZoomWndWidth and cy=ZoomWndHeight
SetWindowPos(&(this->wndTop),rc.right-(ZoomWndWidth+2),rc.top+(NavWndHeight+50),ZoomWndWidth,ZoomWndHeight,SWP_NOACTIVATE);
}
else
{
SetWindowPos(&(this->wndTop),ZoomInPos.left,ZoomInPos.top,ZoomInPos.Width(),ZoomInPos.Height(),SWP_NOACTIVATE);
}
//draw control
CRect clientRect;
GetClientRect(&clientRect);
m_ZoomCombo.MoveWindow(3,clientRect.bottom-21,55,15,TRUE);
m_ZoomCombo.SetCurSel(ZoomInZoom-1);
GetDlgItem(IDC_POINTPOSITION)->MoveWindow(62,clientRect.bottom-17,130,15,TRUE);
bInit = TRUE;
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CZoomInDlg::OnDestroy()
{
CDialog::OnDestroy();
// TODO: Add your message handler code here and/or call default
CRect NavPos;
GetWindowRect(&NavPos);
//wirte ZoomInigation Dialog position in REGISTER before quit the system
AfxGetApp()->WriteProfileInt("ZOONINDLG","NavPosLeft",NavPos.left);
AfxGetApp()->WriteProfileInt("ZOONINDLG","NavPosRight",NavPos.right);
AfxGetApp()->WriteProfileInt("ZOONINDLG","NavPosTop",NavPos.top);
AfxGetApp()->WriteProfileInt("ZOONINDLG","NavPosBottom",NavPos.bottom);
AfxGetApp()->WriteProfileInt("ZOONINDLG","ZoomInZoom",ZoomInZoom);
}
void CZoomInDlg::OnClose()
{
ShowWindow(SW_HIDE);
UpdateWindow();
CDialog::OnClose();
}
//在对话框中控制回车键的操作,使其不起作用
void CZoomInDlg::OnOK()
{
if(bEditChanged)
{
UpdateData(TRUE);
float nValue=(float)atof(m_ZoomStr);
if(nValue>=1.0f && nValue<=16.0f)
ZoomInZoom=(int)(nValue+0.5);
else if(nValue>=100.0f && nValue<=1600.0f)
ZoomInZoom=(int)(nValue/100+0.5);
else if(nValue<1.0f){
AfxMessageBox("100%到1600%之间的数字有效。\n匹配最接近的数字!",MB_ICONSTOP);
ZoomInZoom=1;
}
else if(nValue>1600.0f){
AfxMessageBox("100%到1600%之间的数字有效。\n匹配最接近的数字!",MB_ICONSTOP);
ZoomInZoom=16;
}
else{
AfxMessageBox("100%到1600%之间的数字有效。\n匹配最合理的数字!",MB_ICONSTOP);
ZoomInZoom=3;
}
m_ZoomCombo.SetCurSel(ZoomInZoom-1);
bpbmpChanged=TRUE;
bRedrawControl=TRUE;
PostMessage(WM_REDRAWZOOMIN);
bEditChanged= FALSE;
}
}
void CZoomInDlg::OnCancel()
{
CMainFrame * pAppFrame = (CMainFrame*) AfxGetApp()->m_pMainWnd;
//退出全屏显示
if( pAppFrame->m_bFullScreenMode)
pAppFrame->FullScreenModeOff();
// CDialog::OnCancel();
}
void CZoomInDlg::OnPaint()
{
CPaintDC dc(this);
CDC * pDC = GetDC();
CRect clientRect;
GetClientRect(&clientRect);
CRect realRect;
//draw control
// m_PointInfo.MoveWindow(62,clientRect.bottom-17,130,15,TRUE);
pDC->MoveTo(clientRect.left+3,clientRect.bottom-25);
pDC->LineTo(clientRect.right-3,clientRect.bottom-25);
if(pView==NULL)
{
if(bRedrawControl)
{
COLORREF bkColor=GetSysColor(COLOR_BTNFACE);
pDC->FillSolidRect(clientRect,bkColor);
//draw control
// m_PointInfo.MoveWindow(62,clientRect.bottom-17,130,15,TRUE);
bRedrawControl = FALSE;
}
bActiveView = FALSE;
rcDest = CRect(-1,-1,-1,-1);
COLORREF bkColor=GetSysColor(COLOR_BTNFACE);
FillSolidRectUser( pDC, clientRect, CRect(0,0,0,0),bkColor);
pDC->MoveTo(clientRect.left+3,clientRect.bottom-25);
pDC->LineTo(clientRect.right-3,clientRect.bottom-25);
return;
}
CMDIFrameWnd * pAppFrame = (CMDIFrameWnd *) AfxGetApp()->m_pMainWnd;
CMDIChildWnd * pChild=(CMDIChildWnd* )pView->GetParentFrame();
//当没有图象显示时,应该控制不显示
if(pChild == NULL)
{
bActiveView = FALSE;
return;
}
if(pView == NULL) return;
CMYFUSIONDoc* pDoc=(CMYFUSIONDoc *)pView->GetDocument();
if(pDoc == NULL) return;
if(bpbmpChanged)
{
HDIB hDIB;
hDIB = pDoc->m_hDIB;
DocSize=pDoc->m_sizeDoc;
if(hDIB==NULL) return;
if(DIBInMid==CPoint(-1,-1)) return;
rcDest.top=clientRect.top + 2;
rcDest.left=clientRect.left + 2;
rcDest.right=clientRect.right - 2;
rcDest.bottom=clientRect.bottom - 27;
rcDIB.top = DIBInMid.y - (int)( rcDest.Height() / 2.0 / ZoomInZoom + 0.5);
rcDIB.bottom = DIBInMid.y + (int)( rcDest.Height() / 2.0 / ZoomInZoom + 0.5);
rcDIB.left = DIBInMid.x - (int)( rcDest.Width() / 2.0 / ZoomInZoom + 0.5);
rcDIB.right = DIBInMid.x + (int)( rcDest.Width() / 2.0 / ZoomInZoom + 0.5);
if(rcDIB.top < 0){
rcDest.top -= (int)(rcDIB.top * ZoomInZoom + 0.5);
rcDIB.top = 0;
}
if(rcDIB.left < 0){
rcDest.left -= (int)(rcDIB.left * ZoomInZoom + 0.5);
rcDIB.left = 0;
}
if(rcDIB.bottom > DocSize.cy){
rcDest.bottom -= (int)( (rcDIB.bottom-DocSize.cy) * ZoomInZoom + 0.5);
rcDIB.bottom = DocSize.cy;
}
if(rcDIB.right > DocSize.cx){
rcDest.right -= (int)( (rcDIB.right-DocSize.cx) * ZoomInZoom + 0.5);
rcDIB.right = DocSize.cx;
}
rcDestTheory.left=rcDest.left;
rcDestTheory.top=rcDest.top;
rcDestTheory.right=rcDest.left+rcDIB.Width()*ZoomInZoom;
rcDestTheory.bottom=rcDest.top+rcDIB.Height()*ZoomInZoom;
//NOTE:we need do some additional adjustment
if(ZoomInZoom != 1.0){
rcDIB.top = DocSize.cy - rcDIB.top ;
rcDIB.bottom = DocSize.cy - rcDIB.bottom ;}
rcDIB.NormalizeRect();
if(pbmp!=NULL) delete pbmp;
bmpSize.cx = clientRect.Width();
bmpSize.cy = clientRect.Height()-25;
CBitmapDC bitmapDC(bmpSize.cx,bmpSize.cy,pDC);
PaintDIB(bitmapDC.m_hDC, &rcDestTheory, hDIB, &rcDIB, pDoc->m_palDIB );
COLORREF bkColor=GetSysColor(COLOR_BTNFACE);
FillSolidRectUser(&bitmapDC, CRect(0,0,bmpSize.cx,bmpSize.cy), rcDestTheory,bkColor);
pbmp=bitmapDC.Close();
DrawBitmap(pbmp, pDC, CRect(0,0,bmpSize.cx,bmpSize.cy), CPoint(0,0));
bpbmpChanged = FALSE;
}
else
{
DrawBitmap(pbmp, pDC, CRect(0,0,clientRect.Width()-2,clientRect.Height()-27), CPoint(0,0));
COLORREF bkColor=GetSysColor(COLOR_BTNFACE);
FillSolidRectUser(pDC, CRect(0,0,clientRect.Width()+2,clientRect.Height()+27), rcDestTheory,bkColor);
}
//画图象显示区域的基准线
if(!bIndest)
{
CPen Pen1,*pOldPen;
Pen1.CreatePen(PS_SOLID,1,RGB(255,0,0));
pOldPen = pDC->SelectObject(&Pen1);
pDC->MoveTo((int)(clientRect.left+3+clientRect.Width()/2),clientRect.top);
pDC->LineTo((int)(clientRect.left+3+clientRect.Width()/2),clientRect.bottom-25);
pDC->MoveTo(clientRect.left+2,(int)((clientRect.bottom-25)/2));
pDC->LineTo(clientRect.right-2,(int)((clientRect.bottom-25)/2));
pDC->MoveTo((int)(clientRect.left+3+clientRect.Width()/2),
(int)((clientRect.bottom-25)/2));
pDC->SelectStockObject(NULL_BRUSH);
pDC->Ellipse((int)(clientRect.left+3+clientRect.Width()/2)-7,
(int)((clientRect.bottom-25)/2)-7,
(int)(clientRect.left+3+clientRect.Width()/2)+7,
(int)((clientRect.bottom-25)/2)+7);
pDC->SelectObject(pOldPen);
}
pDC->MoveTo(clientRect.left+3,clientRect.bottom-25);
pDC->LineTo(clientRect.right-3,clientRect.bottom-25);
/* CPen * OldPen;
CPen FlatPen(PS_DOT,1,RGB(255,0,0));
OldPen=pDC->SelectObject(&FlatPen);
pDC->MoveTo(20,50);
pDC->SelectObject(OldPen);*/
ReleaseDC(pDC);
}
void CZoomInDlg::RedrawZoomIn()
{
CDC * pDC = GetDC();
CRect clientRect;
GetClientRect(&clientRect);
if(pView==NULL)
{
if(bRedrawControl)
{
COLORREF bkColor=GetSysColor(COLOR_BTNFACE);
pDC->FillSolidRect(clientRect,bkColor);
//draw control
// m_PointInfo.MoveWindow(62,clientRect.bottom-17,130,15,TRUE);
bRedrawControl = FALSE;
}
bActiveView = FALSE;
rcDest = CRect(-1,-1,-1,-1);
COLORREF bkColor=GetSysColor(COLOR_BTNFACE);
FillSolidRectUser( pDC, clientRect, CRect(0,0,0,0),bkColor);
pDC->MoveTo(clientRect.left+3,clientRect.bottom-25);
pDC->LineTo(clientRect.right-3,clientRect.bottom-25);
return;
}
CMDIFrameWnd * pAppFrame = (CMDIFrameWnd *) AfxGetApp()->m_pMainWnd;
CMDIChildWnd * pChild=(CMDIChildWnd* )pView->GetParentFrame();
//当没有图象显示时,应该控制不显示
if(pChild == NULL)
{
if(bRedrawControl)
{
COLORREF bkColor=GetSysColor(COLOR_BTNFACE);
pDC->FillSolidRect(clientRect,bkColor);
//draw control
// m_PointInfo.MoveWindow(62,clientRect.bottom-17,130,15,TRUE);
bRedrawControl = FALSE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -