// SampleView.cpp : implementation file // #include "stdafx.h" #include "Server_MemDC.h" #include "SlimScrollView.h" #include "Global_Define.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CSlimScrollView #define UM_MOUSE_MOVE (WM_USER + 7650) #define UM_MOUSE_LBUTTON_DOWN (WM_USER + 7651) #define UM_MOUSE_RBUTTON_UP (WM_USER + 7652) #define UM_MOUSE_LBUTTON_UP (WM_USER + 7653) IMPLEMENT_DYNCREATE(CSlimScrollView, CScrollView) CSlimScrollView::CSlimScrollView() { //m_Bitmap.LoadBitmap (IDB_BITMAP1); m_hMemDC = NULL; m_hMainDC = NULL; m_pBMI = NULL; m_pParents = NULL; m_pSetupIMG = NULL; m_pScaleIMg = NULL; m_pBrightHWnd = NULL; m_hBitmap = NULL; m_rtDefect.SetRect(0,0,0,0); m_rtRect.SetRect(0,0,0,0); m_bDefect = FALSE; m_bRect = FALSE; m_bZoomMode = FALSE; m_pSetupIMG = new BYTE[SLIM_IMG_MAX_WIDTH*SLIM_IMG_MAX_HEIGHT*sizeof(BYTE)]; //m_pSetupIMG = (BYTE*)::VirtualAlloc(NULL, (SLIM_IMG_MAX_WIDTH*SLIM_IMG_MAX_HEIGHT)*sizeof(BYTE), MEM_COMMIT | MEM_RESERVE | MEM_TOP_DOWN, PAGE_READWRITE); ZeroMemory(m_pSetupIMG,sizeof(BYTE)*SLIM_IMG_MAX_WIDTH*SLIM_IMG_MAX_HEIGHT); m_pDispBuf = m_pSetupIMG; m_zoomScale = 1.0; m_ScaleWidth = m_ScaleHeight = m_ImageWidth = m_ImageHeight = 0; m_bMessage = FALSE; m_width = 0; m_height = 0; m_OriginPos = m_OffsetPos = m_MousePoint = CPoint(0,0); m_pointSplineOffset = CPoint(0,0); DWORD bufsize = sizeof(BITMAPINFOHEADER)+ 256*sizeof(RGBQUAD); m_pBMI = (BITMAPINFO *)new BYTE[bufsize]; // Set Bitmap information m_pBMI->bmiHeader.biSize=sizeof(BITMAPINFOHEADER); m_pBMI->bmiHeader.biPlanes=1; m_pBMI->bmiHeader.biBitCount=8; m_pBMI->bmiHeader.biCompression=0; //BI_RGB; m_pBMI->bmiHeader.biXPelsPerMeter=0; m_pBMI->bmiHeader.biYPelsPerMeter=0; m_pBMI->bmiHeader.biClrUsed=256; m_pBMI->bmiHeader.biClrImportant=0; // Set Palette for(WORD i=0 ; i< 256 ; i++) { m_pBMI->bmiColors[i].rgbRed = (BYTE)i; m_pBMI->bmiColors[i].rgbGreen = (BYTE)i; m_pBMI->bmiColors[i].rgbBlue = (BYTE)i; m_pBMI->bmiColors[i].rgbReserved = 0; } m_nNotchInsListIdx = -1;//20140528 m_bNotchInsPosMod = FALSE;//20140528 } CSlimScrollView::~CSlimScrollView() { if(m_pBMI) { delete[] m_pBMI,m_pBMI = NULL; } ReleaseMemory(); } void CSlimScrollView::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) { int scroll_Pos; if ( nSBCode==SB_ENDSCROLL ) { scroll_Pos = GetScrollPos(SB_HORZ); } ::PostMessage(this->GetParent()->GetSafeHwnd(),MSG_SCANVIEW,NULL,NULL); CScrollView::OnHScroll(nSBCode, nPos, pScrollBar); } void CSlimScrollView::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) { int scroll_Pos; if ( nSBCode==SB_ENDSCROLL ) { scroll_Pos = GetScrollPos(SB_VERT); } CScrollView::OnVScroll(nSBCode, nPos, pScrollBar); } void CSlimScrollView::EnlargeImage(BYTE *pInBuff, LONG wSrcWidth, LONG wSrcHeight, BYTE *pOutBuff, LONG wDestWidth, LONG wDestHeight,double scale) { if (scale <= 1) return; double dFactor = 1 / scale; double dXSrc = 0; CSize sizeSrc; sizeSrc.cx = wSrcWidth; sizeSrc.cy = wSrcHeight; for (int nX = 0; nX < wDestWidth; nX++) { double dYSrc = 0; for (int nY = 0; nY < wDestHeight; nY++) { pOutBuff[nY * wDestWidth + nX] = CalcWeightedColor(pInBuff, sizeSrc, dXSrc, dYSrc); dYSrc += dFactor; // next dest pixel in source coords } dXSrc += dFactor; // next dest pixel in source coords } return; } BYTE CSlimScrollView::CalcWeightedColor(BYTE* pPixels, CSize size, double dX, double dY) { // interpolate between the current pixel and its pixel to the right and down int nX = (int)dX; int nY = (int)dY; if (dX < 0 || dY < 0) return pPixels[max(0, nY) * size.cx + max(0, nX)]; // closest BYTE* pVal = &pPixels[nY * size.cx + nX]; // current double dXFraction = dX - nX; double dX1MinusFraction = 1 - dXFraction; double dYFraction = dY - nY; double dY1MinusFraction = 1 - dYFraction; BYTE* pXP = &pPixels[nY * size.cx + CHKMIN(nX + 1, size.cx - 1)]; // x + 1 BYTE* pYP = &pPixels[CHKMIN(nY + 1, size.cy - 1) * size.cx + nX]; // y + 1 int result = (int)((dX1MinusFraction * *pVal + dXFraction * *pXP + dY1MinusFraction * *pVal + dYFraction * *pYP) / 2); return result; } void CSlimScrollView::ShrinkImage(BYTE *pInBuff, LONG wSrcWidth, LONG wSrcHeight, BYTE *pOutBuff, LONG wDestWidth, LONG wDestHeight,double scale) { ASSERT (scale < 1 && scale > 0); if (scale >= 1 || scale <= 0) return; double dFactor = 1 / scale; double dXEnd = -dFactor / 2; int nXStart, nXEnd = -1; for (int nX = 0; nX < wDestWidth; nX++) { int nYStart, nYEnd = -1; double dYEnd = -dFactor / 2; nXStart = nXEnd + 1; dXEnd += dFactor; nXEnd = CHKMIN(wSrcWidth - 1, (int)dXEnd + 1); if (nXStart > nXEnd) continue; for (int nY = 0; nY < wDestHeight; nY++) { nYStart = nYEnd + 1; dYEnd += dFactor; nYEnd = CHKMIN(wSrcHeight - 1, (int)dYEnd + 1); if (nYStart > nYEnd) continue; int nCount = 0, nVal = 0; // average the pixels over the range for (int nXSub = nXStart; nXSub <= nXEnd; nXSub++) { for (int nYSub = nYStart; nYSub <= nYEnd; nYSub++) { nVal += pInBuff[nYSub * wSrcWidth + nXSub]; nCount++; } } pOutBuff[nY * wDestWidth + nX] = nVal/nCount; } } return; } BOOL CSlimScrollView::DoZoomInOut() { if(m_pSetupIMG == NULL) return FALSE; CSize sizeTotal; if(m_pScaleIMg != NULL) delete[] m_pScaleIMg, m_pScaleIMg=NULL; m_pScaleIMg = new BYTE[m_ScaleWidth*m_ScaleHeight]; if(m_ImageWidth == m_ScaleWidth && m_ImageHeight == m_ScaleHeight) { m_pDispBuf = m_pSetupIMG; } else { EnlargeImage(m_pSetupIMG,m_ImageWidth,m_ImageHeight,m_pScaleIMg,m_ScaleWidth,m_ScaleHeight,m_zoomScale); m_pDispBuf = m_pScaleIMg; } InitGDI(m_ScaleWidth,m_ScaleHeight,TRUE); sizeTotal.cx = m_ScaleWidth; sizeTotal.cy = m_ScaleHeight; SetScrollSizes(MM_TEXT, sizeTotal); SetScrollRange(SB_HORZ,0,sizeTotal.cx,TRUE); SetScrollRange(SB_VERT,0,sizeTotal.cy,TRUE); EnableScrollBar(SB_BOTH,ESB_ENABLE_BOTH); Invalidate(TRUE); return TRUE; } BOOL CSlimScrollView::CalcScaleSize() { if(m_pSetupIMG == NULL) return FALSE; double dCX,dCY; LONG oldWidth,oldHeight; oldWidth = m_ScaleWidth; oldHeight = m_ScaleHeight; dCX = (double)m_ImageWidth*m_zoomScale; dCY = (double)m_ImageHeight*m_zoomScale; if((LONG)dCX == m_ScaleWidth && (LONG)dCY == m_ScaleHeight) return FALSE; m_ScaleWidth = (LONG)dCX; m_ScaleWidth = ((LONG)(m_ScaleWidth + 3) & ~3); m_ScaleHeight = (LONG)dCY; m_ScaleHeight = ((LONG)(m_ScaleHeight + 3) & ~3); m_pRectPoint.x = (m_pRectPoint.x*m_ScaleWidth)/oldWidth; m_pRectPoint.y = (m_pRectPoint.y*m_ScaleHeight)/oldHeight; return TRUE; } BEGIN_MESSAGE_MAP(CSlimScrollView, CScrollView) //{{AFX_MSG_MAP(CSlimScrollView) ON_WM_MOUSEMOVE() ON_WM_SETCURSOR() ON_WM_VSCROLL() ON_WM_HSCROLL() ON_WM_ERASEBKGND() ON_WM_MOUSEACTIVATE() ON_WM_RBUTTONDOWN() ON_WM_RBUTTONUP() ON_WM_LBUTTONDOWN() ON_WM_LBUTTONUP() //}}AFX_MSG_MAP ON_WM_LBUTTONDBLCLK()//20140528 END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CSlimScrollView drawing int CSlimScrollView::OnMouseActivate(CWnd* pDesktopWnd, UINT nHitTest, UINT message) { // return CView::OnMouseActivate(pDesktopWnd, nHitTest, message); return MA_ACTIVATE; } void CSlimScrollView::OnInitialUpdate() { CScrollView::OnInitialUpdate(); CSize sizeTotal; // TODO: calculate the total size of this view sizeTotal.cx = m_ScaleWidth; sizeTotal.cy = m_ScaleHeight; SetScrollSizes(MM_TEXT, sizeTotal); } void CSlimScrollView::OnDraw(CDC* pDC) { CDocument* pDoc = GetDocument(); HDC hDC = pDC->GetSafeHdc(); CRect rt(0,0,m_width,m_height); CControlMemDC memDC(pDC,&rt); m_hMemDC = memDC.GetSafeHdc(); if(m_pDispBuf != NULL) { DrawImage(m_pDispBuf); if(m_bDrawRect == TRUE && m_bMessage == FALSE) { CRect rect = m_rtRect; rect.left = (int)((double)rect.left*m_zoomScale); rect.right = (int)((double)rect.right*m_zoomScale); rect.top = (int)((double)rect.top*m_zoomScale); rect.bottom = (int)((double)rect.bottom*m_zoomScale); DrawRectangle(rect,RGB(255,0,0)); CPoint point[2]; point[0] = CPoint(rect.left,rect.top+rect.Height()/2); point[1] = CPoint(rect.right,rect.top+rect.Height()/2); DrawLine(point[0].x,point[0].y,point[1].x,point[1].y,RGB(255,255,0)); point[0] = CPoint(rect.left+rect.Width()/2,rect.top); point[1] = CPoint(rect.left+rect.Width()/2,rect.bottom); DrawLine(point[0].x,point[0].y,point[1].x,point[1].y,RGB(255,255,0) ); } DrawMark(); DrawPoint(); DrawNotchInsPos();//20140528 if((int)m_pSplinePos.size() > 0) DrawSpline(); } } void CSlimScrollView::DrawSpline() { CPoint point; std::multimap::iterator it; for(it=m_pSplinePos.begin();it!=m_pSplinePos.end();it++) { point = it->second.origin; point.x = (int)((double)point.x*m_zoomScale); point.y = (int)((double)point.y*m_zoomScale); ::SetPixel(m_hMemDC,point.x,point.y,RGB(255,0,0)); } } void CSlimScrollView::DrawMark() { COLORREF colorOrigin = RGB(120,255,255); COLORREF colorOffset = RGB(255,50,50); int nDrawS = 5; if(m_OriginPos.x > 0 && m_OriginPos.y > 0) { DrawLine(m_OriginPos.x-nDrawS,m_OriginPos.y,m_OriginPos.x+nDrawS,m_OriginPos.y,colorOrigin); DrawLine(m_OriginPos.x,m_OriginPos.y-nDrawS,m_OriginPos.x,m_OriginPos.y+nDrawS,colorOrigin); } if(m_OffsetPos.x > 0 && m_OffsetPos.y > 0) { DrawLine(m_OffsetPos.x-nDrawS,m_OffsetPos.y,m_OffsetPos.x+nDrawS,m_OffsetPos.y,colorOffset); DrawLine(m_OffsetPos.x,m_OffsetPos.y-nDrawS,m_OffsetPos.x,m_OffsetPos.y+nDrawS,colorOffset); } } void CSlimScrollView::DrawLine(long sx, long sy, long ex, long ey, COLORREF color,int nStyle) { HPEN pOldPen = (HPEN)::SelectObject(m_hMemDC,::CreatePen(nStyle, 1, color)); ::MoveToEx(m_hMemDC, sx, sy, NULL); ::LineTo(m_hMemDC, ex, ey); ::DeleteObject(::SelectObject(m_hMemDC, (HPEN)pOldPen)); } ///////////////////////////////////////////////////////////////////////////// // CSlimScrollView diagnostics #ifdef _DEBUG void CSlimScrollView::AssertValid() const { CScrollView::AssertValid(); } void CSlimScrollView::Dump(CDumpContext& dc) const { CScrollView::Dump(dc); } #endif //_DEBUG ///////////////////////////////////////////////////////////////////////////// // CSlimScrollView message handlers BOOL CSlimScrollView::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext) { // TODO: Add your specialized code here and/or call the base class m_pParents = pParentWnd; return CWnd::Create(lpszClassName, lpszWindowName, dwStyle, rect, pParentWnd, nID, pContext); } void CSlimScrollView::DisplayError() { LPVOID lpMsgBuf; FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language (LPTSTR) &lpMsgBuf, 0, NULL ); CString msg = (LPCTSTR)lpMsgBuf; AfxMessageBox(msg); LocalFree( lpMsgBuf ); } BOOL CSlimScrollView::InitGDI(int width, int height, bool bColor) { //////////////////////////////////////////////////////////////////////////////////////////////////////// if(m_width != width || m_height != height) { if(m_bZoomMode == FALSE) { if(m_pSetupIMG) { //VirtualFree(m_pSetupIMG, sizeof(BYTE)*(width*height), MEM_DECOMMIT); //VirtualFree(m_pSetupIMG, 0, MEM_RELEASE); delete [] m_pSetupIMG; m_pSetupIMG = NULL; m_pDispBuf = NULL; } if(m_pSetupIMG == NULL) { //m_pSetupIMG = (BYTE*)::VirtualAlloc(NULL, (width*height)*sizeof(BYTE),MEM_COMMIT | MEM_RESERVE | MEM_TOP_DOWN, PAGE_READWRITE); m_pSetupIMG = new BYTE[width * height * sizeof(BYTE) ]; ZeroMemory(m_pSetupIMG,sizeof(BYTE)*width*height); m_pDispBuf = m_pSetupIMG; } if(m_pScaleIMg) { delete [] m_pScaleIMg; m_pScaleIMg = NULL; } m_pBMI->bmiHeader.biWidth=(LONG)width; m_pBMI->bmiHeader.biHeight=-(LONG)height; } else { m_pBMI->bmiHeader.biWidth=(LONG)m_ScaleWidth; m_pBMI->bmiHeader.biHeight=-(LONG)m_ScaleHeight; } } m_width = width; m_height = height; m_pBMI->bmiHeader.biSizeImage= m_pBMI->bmiHeader.biWidth*m_pBMI->bmiHeader.biHeight; SetScrollRange(SB_HORZ,0,m_width,TRUE); SetScrollRange(SB_VERT,0,m_height,TRUE); return TRUE; } void CSlimScrollView::ReleaseMemory() { m_pSplinePos.clear(); m_pNotchInsPos.clear();//20140528 if(m_pScaleIMg != NULL) { delete[] m_pScaleIMg, m_pScaleIMg=NULL; } if(m_pSetupIMG != NULL) { delete[] m_pSetupIMG, m_pSetupIMG=NULL; } m_width = 0; m_height = 0; } void CSlimScrollView::DrawImage(LPBYTE pImg) { ::SetDIBitsToDevice(m_hMemDC, 0, 0, m_width, m_height, 0, 0, 0, m_height, pImg, m_pBMI, DIB_RGB_COLORS); } void CSlimScrollView::DrawRectangle(CRect rect,COLORREF color) { //BYTE nFactor = (BYTE)((double)m_ScaleWidth*0.05)/2; FV_ROI roi; roi.u1 = rect.left; roi.u2 = rect.right; roi.v1 = rect.top; roi.v2 = rect.bottom; // roi.u1 = rect.left -nFactor; // roi.u2 = rect.right+nFactor; // roi.v1 = rect.top -nFactor; // roi.v2 = rect.bottom+nFactor; HPEN pOldPen = (HPEN)::SelectObject(m_hMemDC,::CreatePen(PS_SOLID, 1, color)); ::MoveToEx(m_hMemDC, roi.u1, roi.v1, NULL); ::LineTo(m_hMemDC, roi.u2, roi.v1); ::LineTo(m_hMemDC, roi.u2, roi.v2); ::LineTo(m_hMemDC, roi.u1, roi.v2); ::LineTo(m_hMemDC, roi.u1, roi.v1); ::DeleteObject(::SelectObject(m_hMemDC, (HPEN)pOldPen)); } void CSlimScrollView::DrawRefresh() { Invalidate(FALSE); } BOOL CSlimScrollView::OnEraseBkgnd(CDC* pDC) { // TODO: Add your message handler code here and/or call default return TRUE;//CScrollView::OnEraseBkgnd(pDC); } void CSlimScrollView::DrawPoint() { if(m_pDispBuf == NULL) return; HFONT pFont, pOldFont; pFont = ::CreateFont(14, 0, 0, 0, FW_BOLD, 0, 0, 0, DEFAULT_CHARSET, OUT_CHARACTER_PRECIS, CLIP_CHARACTER_PRECIS, PROOF_QUALITY, DEFAULT_PITCH|FF_DECORATIVE, _T("arial")); pOldFont = (HFONT)::SelectObject(m_hMemDC, (HFONT)pFont); int nOldROP2 = ::SetROP2(m_hMemDC,R2_NOT); int nOldBkMode = ::SetBkMode(m_hMemDC,TRANSPARENT); COLORREF clrText = ::SetTextColor(m_hMemDC,RGB(0, 0, 0)); UINT nOldAlign = ::SetTextAlign(m_hMemDC,TA_CENTER); CString str,strX,strY; CPoint point = m_MousePoint; CRect rect; CBrush brush,rectBrush; int nBright = 0; if(m_pDispBuf != NULL) { CSize szSize = CSize(m_ScaleWidth,m_ScaleHeight); if(point.y >= szSize.cy || point.x >= szSize.cx) { ; } else { nBright = *(m_pDispBuf+point.y*szSize.cx+point.x); } } strX.Format(_T("%d"),point.x); strY.Format(_T("%d"),point.y); strX = GetMoneyRule(strX,1000); strY = GetMoneyRule(strY,1000); str.Format(_T("[%s][%s][%d]"), strX,strY,nBright); brush.CreateSolidBrush(RGB(180,150,190)); rectBrush.CreateSolidBrush(RGB(5,64,128)); rect = CRect(m_MousePoint.x-(int)((double)(str.GetLength())*2.9),m_MousePoint.y+20,m_MousePoint.x+(int)((double)(str.GetLength())*2.9),m_MousePoint.y+20+16); ::FrameRect(m_hMemDC,rect, (HBRUSH)rectBrush); rect.DeflateRect(1,1); ::FillRect(m_hMemDC,&rect,(HBRUSH)brush); ::TextOut(m_hMemDC, m_MousePoint.x, m_MousePoint.y+20, str, str.GetLength()); ::SetTextColor(m_hMemDC,clrText); ::SetBkMode(m_hMemDC,nOldBkMode); ::SetROP2(m_hMemDC,nOldROP2); ::SetTextAlign(m_hMemDC,nOldAlign); ::DeleteObject(::SelectObject(m_hMemDC, (HFONT)pOldFont)); brush.DeleteObject(); rectBrush.DeleteObject(); } CString CSlimScrollView::GetMoneyRule(CString strMoney, int nRuleSpace/*=0*/) { BOOL bMinus = FALSE; if( strMoney.Find(_T("-"),0 ) >= 0 ) bMinus = TRUE; double dMoney = _ttof(strMoney); strMoney.Format(_T("%.0f"), dMoney); CString strResult = _T(""), strTemp1, strTemp2, strTemp3, strTemp4; strTemp4 = strMoney.Right(3); strMoney = strMoney.Left(strMoney.GetLength()-3); strTemp3 = strMoney.Right(3); strMoney = strMoney.Left(strMoney.GetLength()-3); strTemp2 = strMoney.Right(3); strMoney = strMoney.Left(strMoney.GetLength()-3); strTemp1 = strMoney.Right(3); strResult = strTemp1 + ((strTemp1.GetLength() > 0) ? _T(",") : _T("")) + strTemp2 + ((strTemp2.GetLength() > 0) ? _T(",") : _T("")) + strTemp3 + ((strTemp3.GetLength() > 0) ? _T(",") : _T("")) + strTemp4; if( bMinus ) { strResult = _T("-")+strResult; } return strResult; } void CSlimScrollView::OnMouseMove(UINT nFlags, CPoint point) { int cx = this->GetScrollPos(SB_HORZ) + point.x; int cy = this->GetScrollPos(SB_VERT) + point.y; m_MousePoint = CPoint(cx,cy); if(m_bRect) { m_rtRect.bottom =cy; m_rtRect.right = cx; } DrawRefresh(); if(m_bMessage) { GetParent()->PostMessage(MSG_SCANVIEW_MOUSEPOS,cx,cy); } CScrollView::OnMouseMove(nFlags, point); } void CSlimScrollView::PostNcDestroy() { // TODO: Add your specialized code here and/or call the base class CScrollView::PostNcDestroy(); } BOOL CSlimScrollView::DestroyWindow() { // TODO: Add your specialized code here and/or call the base class return CScrollView::DestroyWindow(); } void CSlimScrollView::OnRButtonDown(UINT nFlags, CPoint point) { // TODO: Add your message handler code here and/or call default CScrollView::OnRButtonDown(nFlags, point); } void CSlimScrollView::OnRButtonUp(UINT nFlags, CPoint point) { // TODO: Add your message handler code here and/or call default CScrollView::OnRButtonUp(nFlags, point); } void CSlimScrollView::OnLButtonDown(UINT nFlags, CPoint point) { // TODO: Add your message handler code here and/or call default int cx = this->GetScrollPos(SB_HORZ); int cy = this->GetScrollPos(SB_VERT); if(!m_bRect)//20140528 { m_rtRect.top = point.y + cy; m_rtRect.left = point.x + cx; //m_rtRect.right = 0; //m_rtRect.bottom = 0; m_bRect = TRUE; } if(m_bNotchInsPosMod == TRUE)//20140528 { m_bNotchInsPosMod = FALSE; CPoint pointTemp; pointTemp.y = point.y + cy; pointTemp.x = point.x + cx; // m_pNotchInsPos.insert(std::make_pair(nCount, pointTemp)); GetParent()->PostMessage(MSG_SCANVIEW_POS_MOD, pointTemp.x, pointTemp.y); } CScrollView::OnLButtonDown(nFlags, point); } void CSlimScrollView::OnLButtonUp(UINT nFlags, CPoint point) { // TODO: Add your message handler code here and/or call default int cx = this->GetScrollPos(SB_HORZ); int cy = this->GetScrollPos(SB_VERT); if(m_bRect) { if( m_rtRect.top > m_rtRect.bottom) { int tmp = m_rtRect.top; m_rtRect.top = m_rtRect.bottom; m_rtRect.bottom = tmp; } if( m_rtRect.left > m_rtRect.right) { int tmp = m_rtRect.left; m_rtRect.left = m_rtRect.right; m_rtRect.right = tmp; } // if(m_bMessage) // GetParent()->PostMessage(UM_MOUSE_LBUTTON_UP,MAKELONG(m_rtRect.left/m_zoomScale,m_rtRect.top/m_zoomScale),MAKELONG(m_rtRect.right/m_zoomScale,m_rtRect.bottom/m_zoomScale)); m_bRect = FALSE; } CScrollView::OnLButtonUp(nFlags, point); } void CSlimScrollView::OnLButtonDblClk(UINT nFlags, CPoint point)//20140528 { // int nCount = (int)m_pNotchInsPos.size(); int cx = this->GetScrollPos(SB_HORZ); int cy = this->GetScrollPos(SB_VERT); CPoint pointTemp; pointTemp.y = point.y + cy; pointTemp.x = point.x + cx; // m_pNotchInsPos.insert(std::make_pair(nCount, pointTemp)); GetParent()->PostMessage(MSG_SCANVIEW_POS_ADD, pointTemp.x, pointTemp.y); CScrollView::OnLButtonDblClk(nFlags, point); } void CSlimScrollView::SetMode(SLIM_MODECOMMAND nMode) { m_nCurMode = nMode; m_bZoomMode = TRUE; switch(m_nCurMode) { case SLIM_MODE_ZOOMIN: //m_pCursor = AfxGetApp()->LoadCursor(IDC_ARROW_CURSOR); if(m_zoomScale < SLIM_MAXZOOMIN) { m_zoomScale += SLIM_SCALE_FACTOR; if(m_zoomScale > SLIM_MAXZOOMIN) m_zoomScale = SLIM_MAXZOOMIN; } if(CalcScaleSize() == TRUE) DoZoomInOut(); break; case SLIM_MODE_ZOOMOUT: //m_pCursor = AfxGetApp()->LoadCursor(IDC_ARROW_CURSOR); if(m_zoomScale > SLIM_MAXZOOMOUT) { m_zoomScale -= SLIM_SCALE_FACTOR; if(m_zoomScale < SLIM_MAXZOOMOUT) m_zoomScale = SLIM_MAXZOOMOUT; } if(CalcScaleSize() == TRUE) DoZoomInOut(); break; case SLIM_MODE_NORMAL: DoOrigin(); break; case SLIM_MODE_POINT: //m_pCursor = AfxGetApp()->LoadCursor(IDC_ARROW_CURSOR); break; } m_bZoomMode = FALSE; Invalidate(TRUE); } void CSlimScrollView::DoOrigin() { if(m_nCurMode == SLIM_MODE_NORMAL) { m_ScaleWidth = m_ImageWidth; m_ScaleHeight = m_ImageHeight; m_zoomScale = 1; DoZoomInOut(); } DrawRefresh(); } CRect CSlimScrollView::GetDrawRect() { if(m_rtRect.left < 0) m_rtRect.left = 0; if(m_rtRect.right < 0) m_rtRect.right = 0; if(m_rtRect.left >= m_ScaleWidth) m_rtRect.left = m_ScaleWidth-1; if(m_rtRect.right >= m_ScaleWidth) m_rtRect.right = m_ScaleWidth-1; if(m_rtRect.top < 0) m_rtRect.top = 0; if(m_rtRect.bottom < 0) m_rtRect.bottom = 0; if(m_rtRect.top >= m_ScaleHeight) m_rtRect.top = m_ScaleHeight-1; if(m_rtRect.bottom >= m_ScaleHeight) m_rtRect.bottom = m_ScaleHeight-1; return m_rtRect; } void CSlimScrollView::SetSplinePosition(std::multimap *pPoint,CPoint pointOffset) { if(pPoint == NULL) return; m_pSplinePos.clear(); m_pSplinePos.insert(pPoint->begin(),pPoint->end()); m_pointSplineOffset = pointOffset; } void CSlimScrollView::DrawNotchInsPos()//20140528 { if(m_bDrawNotchInsPos == TRUE) { std::multimap::iterator it; CRect rect; COLORREF color; for(it=m_pNotchInsPos.begin();it!=m_pNotchInsPos.end();it++) { if(it->first == m_nNotchInsListIdx) { color = RGB(255,255,0); if(m_bNotchInsPosMod == TRUE) { rect.left = m_MousePoint.x-2; rect.right = m_MousePoint.x+2;; rect.top = m_MousePoint.y-2; rect.bottom = m_MousePoint.y+2; } else { rect.left = it->second.x-2; rect.right = it->second.x+2;; rect.top = it->second.y-2; rect.bottom = it->second.y+2; } } else { color = RGB(255,0,0); rect.left = it->second.x-2; rect.right = it->second.x+2;; rect.top = it->second.y-2; rect.bottom = it->second.y+2; } DrawRectangle(rect,color); } //DrawLine(m_nNotchCadCenterX,0,m_nNotchCadCenterX,m_ImageHeight,RGB(255,255,0)); DrawLine(0,m_nNotchCadCenterY,m_ImageWidth,m_nNotchCadCenterY,RGB(128,128,0)); } } void CSlimScrollView::SetNotchInsPosition( std::multimap *pPoint ) { if(pPoint == NULL) return; m_pNotchInsPos.clear(); m_pNotchInsPos.insert(pPoint->begin(),pPoint->end()); Invalidate(FALSE); } void CSlimScrollView::SetNotchCadCenterPos( int nPosX, int nPosY ) { m_nNotchCadCenterX = nPosX; m_nNotchCadCenterY = nPosY; }