📄 zoomindlg.cpp
字号:
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;
}
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 - 25;
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()-25), CPoint(0,0));
COLORREF bkColor=GetSysColor(COLOR_BTNFACE);
FillSolidRectUser(pDC, CRect(0,0,clientRect.Width()+2,clientRect.Height()+25), rcDestTheory,bkColor);
}
if(bRedrawControl)
{
COLORREF bkColor=GetSysColor(COLOR_BTNFACE);
pDC->FillSolidRect(CRect(0,clientRect.bottom - 25,clientRect.right,clientRect.bottom),bkColor);
//draw control
// m_PointInfo.MoveWindow(62,clientRect.bottom-17,130,15,TRUE);
bRedrawControl = FALSE;
}
//画图象显示区域的基准线
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+1);
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->SetPixel((int)(clientRect.left+3+clientRect.Width()/2),(int)((clientRect.bottom-25)/2),RGB(0,255,0));
pDC->SelectObject(pOldPen);
//状态条显示
double xZoom,yZoom;
xZoom=yZoom=(double)ZoomInZoom;
CPoint pos;
pos.x=(int)(clientRect.left+3+clientRect.Width()/2);
pos.y=(int)((clientRect.bottom-25)/2);
double lfptDIBOffx,lfptDIBOffy; //鼠标点在当前图象上的位置
lfptDIBOffx = rcDIB.left + (pos.x-rcDestTheory.left-ZoomInZoom/2)/xZoom;
if(ZoomInZoom == 1.0f)
lfptDIBOffy = rcDIB.top + (pos.y-rcDestTheory.top)/yZoom;
else
lfptDIBOffy = DocSize.cy - rcDIB.bottom + (pos.y-rcDestTheory.top-ZoomInZoom/2 )/yZoom;
CString str;
str.Format("X=%.2lf Y=%.2lf",lfptDIBOffx,lfptDIBOffy);
GetDlgItem(IDC_POINTPOSITION)->SetWindowText(str);
}
pDC->MoveTo(clientRect.left+3,clientRect.bottom-25);
pDC->LineTo(clientRect.right-3,clientRect.bottom-25);
ReleaseDC(pDC);
}
LRESULT CZoomInDlg::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
//control the window not too small
if(message==WM_SIZING)
{
LPRECT lpRect=(LPRECT)lParam;
if(lpRect->right-lpRect->left < ZoomWndWidth )
{
if(wParam==WMSZ_LEFT||wParam==WMSZ_BOTTOMLEFT||wParam==WMSZ_TOPLEFT)
lpRect->left+=(lpRect->right-lpRect->left-ZoomWndWidth);
if(wParam==WMSZ_RIGHT||wParam==WMSZ_BOTTOMRIGHT||wParam==WMSZ_TOPRIGHT)
lpRect->right-=(lpRect->right-lpRect->left-ZoomWndWidth);
}
if(lpRect->bottom-lpRect->top < ZoomWndHeight )
{
if(wParam==WMSZ_TOP||wParam==WMSZ_TOPRIGHT||wParam==WMSZ_TOPLEFT)
lpRect->top+=(lpRect->bottom-lpRect->top-ZoomWndHeight);
if(wParam==WMSZ_BOTTOM||wParam==WMSZ_BOTTOMRIGHT||wParam==WMSZ_BOTTOMLEFT)
lpRect->bottom-=(lpRect->bottom-lpRect->top-ZoomWndHeight);
}
}
//move to default location
if(message==WM_MOVING)
{
LPRECT lpRect=(LPRECT)lParam;
CMDIFrameWnd* pAppFrame = (CMDIFrameWnd*) AfxGetApp()->m_pMainWnd;
ASSERT(pAppFrame->IsKindOf(RUNTIME_CLASS( CMDIFrameWnd )));
CRect rc;
pAppFrame->GetClientRect(&rc);
pAppFrame->ClientToScreen(&rc);//Screen Coordinate
CRect NavRect;
GetWindowRect(&NavRect);//Screen Coordinate
CRect DefaultRect;
DefaultRect.left=rc.right-NavRect.Width()-2;
DefaultRect.right=DefaultRect.left+NavRect.Width();
DefaultRect.top=rc.top+(NavWndHeight+50);
DefaultRect.bottom=DefaultRect.top+NavRect.Height();
if(abs(DefaultRect.left-lpRect->left)<=5
&& abs(DefaultRect.right-lpRect->right)<=5
&& abs(DefaultRect.top-lpRect->top)<=5
&& abs(DefaultRect.bottom-lpRect->bottom)<=5 )
{
lpRect->left=DefaultRect.left;
lpRect->right=DefaultRect.right;
lpRect->top=DefaultRect.top;
lpRect->bottom=DefaultRect.bottom;
}
}
return CDialog::WindowProc(message, wParam, lParam);
}
void CZoomInDlg::OnContextMenu(CWnd*, CPoint point)
{ // CG: This block was added by the Pop-up Menu component { if (point.x == -1 && point.y == -1){ //keystroke invocation CRect rect; GetClientRect(rect); ClientToScreen(rect); point = rect.TopLeft(); point.Offset(5, 5); } CMenu menu; VERIFY(menu.LoadMenu(CG_IDR_POPUP_ZOOM_IN_DLG)); CMenu* pPopup = menu.GetSubMenu(0); ASSERT(pPopup != NULL); CWnd* pWndPopupOwner = this; while (pWndPopupOwner->GetStyle() & WS_CHILD) pWndPopupOwner = pWndPopupOwner->GetParent(); pPopup->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, point.x, point.y, pWndPopupOwner); }
}
void CZoomInDlg::OnDefaultSizeZoomIn()
{
CRect NavRect;
GetWindowRect(&NavRect);//Screen Coordinate
int nFullWidth=::GetSystemMetrics(SM_CXSCREEN);
int nFullHeight=::GetSystemMetrics(SM_CYSCREEN);
if( NavRect.left >= nFullWidth-100 || NavRect.top >= nFullHeight-100 )
SetWindowPos(&(this->wndTop),NavRect.left,NavRect.top,ZoomWndWidth,ZoomWndHeight,SWP_SHOWWINDOW );// SWP_NOACTIVATE
else
SetWindowPos(&(this->wndTop),NavRect.right-ZoomWndWidth,NavRect.top,ZoomWndWidth,ZoomWndHeight,SWP_SHOWWINDOW );// SWP_NOACTIVATE
//draw control
CRect clientRect;
GetClientRect(&clientRect);
m_ZoomCombo.MoveWindow(3,clientRect.bottom-21,55,15,TRUE);
bpbmpChanged=TRUE;
bRedrawControl = TRUE;
PostMessage(WM_REDRAWZOOMIN);
}
void CZoomInDlg::OnDefaultLocationZoomIn()
{
CMDIFrameWnd* pAppFrame = (CMDIFrameWnd*) AfxGetApp()->m_pMainWnd;
ASSERT(pAppFrame->IsKindOf(RUNTIME_CLASS( CMDIFrameWnd )));
CRect rc;
pAppFrame->GetClientRect(&rc);
pAppFrame->ClientToScreen(&rc);//Screen Coordinate
CRect NavRect;
GetWindowRect(&NavRect);//Screen Coordinate
CRect DefaultRect;
DefaultRect.left=rc.right-NavRect.Width()-2;
DefaultRect.right=DefaultRect.left+NavRect.Width();
DefaultRect.top=rc.top+(NavWndHeight+50);
DefaultRect.bottom=DefaultRect.top+NavRect.Height();
SetWindowPos(&(this->wndTop),DefaultRect.left,DefaultRect.top,DefaultRect.Width(),DefaultRect.Height(),SWP_NOACTIVATE);
}
void CZoomInDlg::OnHideZoomZInDlg()
{
if( (GetStyle() & WS_VISIBLE) != 0)
{
ShowWindow(SW_HIDE);
}
}
void CZoomInDlg::OnSize(UINT nType, int cx, int cy)
{
CDialog::OnSize(nType, cx, cy);
if(bInit)
bInit = FALSE;
else{
bRedrawControl = TRUE;
m_ZoomCombo.MoveWindow(3,cy-21,55,15,TRUE);
PostMessage(WM_REDRAWZOOMIN);
}
}
void CZoomInDlg::OnLButtonDown(UINT nFlags, CPoint point)
{
if(pView == NULL)
return;
if(rcDestTheory.PtInRect(point))
{
if(NormalStatus == IMAGE_MEASURE)
{
bMoveWithMouse=TRUE;
//选点
CMainFrame* pAppFrame = (CMainFrame*) AfxGetApp()->m_pMainWnd;
double xZoom,yZoom;
xZoom=yZoom=(double)ZoomInZoom;
double lfptDIBOffx,lfptDIBOffy; //鼠标点在当前图象上的位置
lfptDIBOffx = rcDIB.left + (point.x-rcDestTheory.left-ZoomInZoom/2)/xZoom;
if(ZoomInZoom == 1.0f)
lfptDIBOffy = rcDIB.top + (point.y-rcDestTheory.top)/yZoom;
else
lfptDIBOffy = DocSize.cy - rcDIB.bottom + (point.y-rcDestTheory.top-ZoomInZoom/2 )/yZoom;
lfptDIBMousex = lfptDIBOffx;
lfptDIBMousey = lfptDIBOffy;
// if(pAppFrame->PickPointDlg)
// pAppFrame->PickPointDlg->SendMessage(WM_PICK_POINT);
}
}
CDialog::OnLButtonDown(nFlags, point);
}
void CZoomInDlg::OnMouseMove(UINT nFlags, CPoint point)
{
if(pView == NULL)
return;
CString str;
if(rcDestTheory.PtInRect(point))
{
bIndest = TRUE;
RedrawZoomIn();
//画图象显示区域的基准线
CDC * pDC = GetDC();
CRect clientRect;
GetClientRect(&clientRect);
CPen Pen1,*pOldPen;
Pen1.CreatePen(PS_SOLID,1,RGB(255,0,0));
pOldPen = pDC->SelectObject(&Pen1);
pDC->MoveTo(point.x,clientRect.top);
pDC->LineTo(point.x,clientRect.bottom-25);
pDC->MoveTo(clientRect.left+2,point.y);
pDC->LineTo(clientRect.right-2,point.y);
pDC->MoveTo(point.x,point.y);
pDC->SelectStockObject(NULL_BRUSH);
pDC->Ellipse(point.x-7, point.y-7, point.x+7,point.y+7);
/////////////////////////////////
double xZoom,yZoom;
xZoom=yZoom=(double)ZoomInZoom;
double lfptDIBOffx,lfptDIBOffy; //鼠标点在当前图象上的位置
lfptDIBOffx = rcDIB.left + (point.x-rcDestTheory.left-ZoomInZoom/2)/xZoom;
if(ZoomInZoom == 1.0f)
lfptDIBOffy = rcDIB.top + (point.y-rcDestTheory.top)/yZoom;
else
lfptDIBOffy = DocSize.cy - rcDIB.bottom + (point.y-rcDestTheory.top-ZoomInZoom/2 )/yZoom;
str.Format("X=%.2lf Y=%.2lf",lfptDIBOffx,lfptDIBOffy);
}
else{
bIndest = FALSE;
str.Format("像素坐标");
Invalidate(0);
}
GetDlgItem(IDC_POINTPOSITION)->SetWindowText(str);
CDialog::OnMouseMove(nFlags, point);
}
void CZoomInDlg::OnLButtonUp(UINT nFlags, CPoint point)
{
CDialog::OnLButtonUp(nFlags, point);
}
BOOL CZoomInDlg::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
{
if (nHitTest == HTCLIENT && bIndest)
{
::SetCursor(m_ImageMeasure);
return 0;
}
return CDialog::OnSetCursor(pWnd, nHitTest, message);
}
void CZoomInDlg::OnSelchangeZoomCombo()
{
ZoomInZoom=m_ZoomCombo.GetCurSel()+1;
bEditChanged= FALSE;
bpbmpChanged=TRUE;
bRedrawControl=TRUE;
PostMessage(WM_REDRAWZOOMIN);
}
void CZoomInDlg::OnEditchangeZoomCombo()
{
bEditChanged= TRUE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -