⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 readervcview.cpp

📁 Foxit Reader DLL开发的示例软件。可以很方便地实现自己的pdf viewer.
💻 CPP
📖 第 1 页 / 共 2 页
字号:
void CReaderVCView::OnLButtonUp(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	LoadMyCursor();

	if (m_bSnap)
	{
		CDC *pDC  = GetDC();
		CPen *pOldPen;
		CPen pen;
		CBrush *pOldBr;
		CRect rect;
		pen.CreatePen(PS_DASH, 2, RGB(255,0,0));
		pOldPen = pDC->SelectObject(&pen);
		pOldBr = (CBrush*) (pDC->SelectStockObject(NULL_BRUSH));
		int nOldRop = pDC->SetROP2(R2_XORPEN);
		pDC->Rectangle(m_rtOld);
		pDC->SetROP2(nOldRop);
		m_rtOld.left = m_rtOld.top = m_rtOld.right = m_rtOld.bottom = 0;
		ReleaseDC(pDC);
	}
	
	if (m_bSnap)
	{	
		BOOL open = OpenClipboard();
		if (open)
		{
			::EmptyClipboard();
			int bmpWidth = abs(point.x - m_ptLBDown.x);
			int bmpHeight = abs(point.y - m_ptLBDown.y);
			if (bmpHeight == 0 || bmpWidth == 0)return;
			CRect bmpRect(m_ptLBDown, point);
			CClientDC dc(this);
			CBitmap *pBitmap = new CBitmap();
			pBitmap->CreateCompatibleBitmap(&dc,bmpWidth,bmpHeight);
			CDC memDC;
			memDC.CreateCompatibleDC(&dc);
			memDC.SelectObject(pBitmap);
			CBrush whiteBrush(RGB(255,255,255));
			memDC.FillRect(bmpRect,&whiteBrush);
			memDC.BitBlt(0, 0, bmpRect.Width(), bmpRect.Height(),&dc, bmpRect.left, bmpRect.top,SRCCOPY);
			HBITMAP hBitmap = (HBITMAP) *pBitmap;
			:: SetClipboardData(CF_BITMAP, hBitmap);
			::CloseClipboard();
			MessageBox("The selected area has been copied to clipboard!");
			delete pBitmap;
		}
	}

	CView::OnLButtonUp(nFlags, point);
}

void CReaderVCView::OnMouseMove(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	if (nFlags == MK_LBUTTON)
	{
		LoadMyCursor(1);
	}else{LoadMyCursor();}
	
	CDC *pDC = GetDC();
	if (m_bHand && nFlags == MK_LBUTTON)
	{
		int curPos, prevPos;
		int dy = m_ptLBDown.y - point.y;
		prevPos = m_nPosV;
		curPos = prevPos + dy;
		prevPos = SetScrollPos(SB_VERT, curPos, TRUE);
		curPos = GetScrollPos(SB_VERT);
		int distance;
		distance = prevPos - curPos;
		m_nStartY += distance;
		ScrollWindow(0, distance);
	
		dy = m_ptLBDown.x - point.x;
		prevPos = m_nPosH;
		curPos = prevPos + dy;
		prevPos = SetScrollPos(SB_HORZ, curPos, TRUE);
		curPos = GetScrollPos(SB_HORZ);
		distance = prevPos - curPos;
		m_nStartX += distance;
		ScrollWindow(distance, 0);

	}
	if (m_bSnap && nFlags == MK_LBUTTON)
	{
		CPen *pOldPen;
		CPen pen;
		CBrush *pOldBr;
		CRect rect(m_ptLBDown, point);
		pen.CreatePen(PS_DASH, 2, RGB(255,0,0));
		pOldPen = pDC->SelectObject(&pen);
		pOldBr = (CBrush*) (pDC->SelectStockObject(NULL_BRUSH));
		int nOldRop = pDC->SetROP2(R2_XORPEN);
		int nModle = pDC->Rectangle(m_rtOld);
		
		pDC->Rectangle(rect);
		pDC->SelectObject(pOldBr);
		pDC->SelectObject(pOldPen);
		pDC->SetROP2(nModle);
		m_rtOld = rect;
		
	}
	ReleaseDC(pDC);	
	CView::OnMouseMove(nFlags, point);
}

void CReaderVCView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) 
{
	// TODO: Add your message handler code here and/or call default
	switch(nChar)
	{
	case 35:
		OnDocLastpage();	
		break;
	case 36:
		OnDocFirstpage();
		break;
	case 37:
		this->OnDocPrepage();
		break;
	case 39:
		this->OnDocNextpage();
		break;
	case 38:
		
		break;
	case 40:
		
		break;
	default:
		break;
	}
	CView::OnKeyDown(nChar, nRepCnt, nFlags);
}

void CReaderVCView::OnToolSnapshot() 
{
	m_bSnap = TRUE;
	m_bHand = FALSE;

}



void CReaderVCView::OnToolHand() 
{
	m_bSnap = FALSE;
	m_bHand = TRUE;
}

void CReaderVCView::LoadMyCursor(int nflag)
{
	HCURSOR hCur;
	if (nflag == 1)
	{
		
	 if (m_bSnap)
		{
			hCur = AfxGetApp()->LoadStandardCursor(IDC_CROSS);
		}
		else
		{
			hCur = AfxGetApp()->LoadCursor(IDC_CURSOR1);
		}
	}
	if (m_bHand)
	{
		hCur = AfxGetApp()->LoadCursor(IDC_CURSOR2);
	}
	else if (m_bSnap)
	{
		hCur = AfxGetApp()->LoadStandardCursor(IDC_CROSS);
	}else 
	{
		hCur = AfxGetApp()->LoadStandardCursor(IDC_ARROW);
	}
	
	
	::SetCursor(hCur);
}





void CReaderVCView::SyncScroll()
{
	CRect rect;                                                               
	GetClientRect(rect);                                                      
	
	int nSizeX = 0; 
	int nSizeY = 0;
	//int temp = 0;

	if (1 == m_nRotateFlag || 3 == m_nRotateFlag)
	{
		nSizeX = m_nActualSizeY;
		nSizeY = m_nActualSizeX;
	}
	else
	{
		nSizeX = m_nActualSizeX;
		nSizeY = m_nActualSizeY;
	}

	
	SCROLLINFO scrinfo;                                                       
	scrinfo.cbSize = sizeof(SCROLLINFO);                                      
	GetScrollInfo(SB_HORZ, &scrinfo);                                         
	scrinfo.nMin =0;                                                          
	scrinfo.nMax = nSizeX * m_dbScaleFactor + m_nStartX;                                                 
	scrinfo.nPage = __min(nSizeX * m_dbScaleFactor, rect.Width());                              
	if (nSizeX <= rect.Height())
	{
		//si.fMask |= SIF_DISABLENOSCROLL;
		this->EnableScrollBar(SB_HORZ, ESB_DISABLE_RTDN);
	}
	else{
		//si.fMask &= ~SIF_DISABLENOSCROLL;
		this->EnableScrollBar(SB_HORZ, ESB_ENABLE_BOTH);
		
	} 
	SetScrollInfo(SB_HORZ, &scrinfo);                                         
	SetScrollPos(SB_HORZ, 0);                                           
	//m_nPosH = nPosH;                                                          
	
	GetScrollInfo(SB_VERT, &scrinfo);                                         
	scrinfo.nMin = 0;                                                         
	scrinfo.nMax = nSizeY * m_dbScaleFactor + 2*m_nStartY;                                             
	scrinfo.nPage = __min(nSizeY * m_dbScaleFactor, rect.Height());                             
	if (nSizeY <= rect.Height())
	{
		//si.fMask |= SIF_DISABLENOSCROLL;
		this->EnableScrollBar(SB_VERT, ESB_DISABLE_RTDN);
	}
	else{
		//si.fMask &= ~SIF_DISABLENOSCROLL;
		this->EnableScrollBar(SB_VERT, ESB_ENABLE_BOTH);
		
	}       
	SetScrollInfo(SB_VERT, &scrinfo);                                         
	SetScrollPos(SB_VERT, 0);                                             
	                                                     
}

void CReaderVCView::OnSize(UINT nType, int cx, int cy) 
{
	CView::OnSize(nType, cx, cy);
	m_nStartX = m_nStartY = 10;
	SyncScroll();
	// TODO: Add your message handler code here	
}

void CReaderVCView::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) 
{
	// TODO: Add your message handler code here and/or call default
	int prevPos = GetScrollPos(SB_HORZ);                               
	int curPos = prevPos;                                              
	int nMin, nMax, nPage;                                             
	GetScrollRange(SB_HORZ, &nMin, &nMax);                             
	SCROLLINFO si;                                                     
	GetScrollInfo(SB_HORZ, &si);                                       
	nPage = si.nPage;                                                  
	
	switch(nSBCode)                                                    
	{                                                                  
	case SB_TOP:                                                       
		curPos = nMin;                                                   
		break;                                                           
	case SB_BOTTOM:                                                    
		curPos = nMax;                                                   
		break;                                                           
	case SB_LINEUP:                                                    
		curPos --;                                                       
		break;                                                         
	case SB_LINEDOWN:                                                  
		curPos ++;                                                       
		break;                                                         
	case SB_ENDSCROLL:                                                 
		return;                                                          
	case SB_PAGEDOWN:                                                  
		curPos += nPage;                                                 
		break;                                                           
	case SB_PAGEUP:                                                    
		curPos -= nPage;                                                 
		break;                                                         
	case SB_THUMBPOSITION:                                             
		curPos = si.nTrackPos;                                           
		break;                                                         
	case SB_THUMBTRACK:                                                
		curPos = si.nTrackPos;                                           
		break;                                                         
	}                                                                  
	
	if (curPos < nMin) { curPos = nMin;}                               
	if(curPos > nMax){ curPos = nMax;}                                 
	SetScrollPos(SB_HORZ, curPos);                                     

	int distance;                                                      
	distance = prevPos - curPos;                                                                     
	m_nStartX += distance;                                                                                
	ScrollWindow(distance, 0);                                  
	CRect rect;
	GetClientRect(rect);
	CRect rtnew(rect.left, rect.top, rect.left+distance, rect.bottom);
	InvalidateRect(&rtnew);
	CView::OnHScroll(nSBCode, nPos, pScrollBar);
}

void CReaderVCView::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) 
{
	// TODO: Add your message handler code here and/or call default                                   
	int prevPos = GetScrollPos(SB_VERT);                                        
	int curPos = prevPos;                                                       
	int nMin, nMax, nPage;                                                      
	GetScrollRange(SB_VERT, &nMin, &nMax);                                      
	SCROLLINFO si;                                                              
	GetScrollInfo(SB_VERT, &si);                                                
	nPage = si.nPage;                                                           
                                                                            
	switch(nSBCode)                                                             
	{                                                                           
	case SB_TOP:                                                                
		curPos = nMin;                                                            
		break;                                                                    
	case SB_BOTTOM:                                                             
		curPos = nMax;                                                            
		break;                                                                    
	case SB_LINEUP:                                                             
		curPos --;                                                                
		break;                                                                  
	case SB_LINEDOWN:                                                           
		curPos ++;                                                                
		break;                                                                  
	case SB_ENDSCROLL:                                                          
		return;                                                                   
	case SB_PAGEDOWN:                                                           
		curPos += nPage;                                                          
		break;                                                                    
	case SB_PAGEUP:                                                             
		curPos -= nPage;                                                          
		break;                                                                  
	case SB_THUMBPOSITION:                                                      
		curPos = si.nTrackPos;                                                    
		break;                                                                  
	case SB_THUMBTRACK:                                                         
		curPos = si.nTrackPos;                                                    
		break;                                                                  
	}                                                                           
                                                                            
	if (curPos < nMin) { curPos = nMin;}                                        
	if(curPos > nMax){ curPos = nMax;}                                          
	SetScrollPos(SB_VERT, curPos);                                                                                                      
                                                                            
	int distance;                                                                                                        
	distance = prevPos - curPos;                                                
	m_nStartY += distance;                                                                                                  
	ScrollWindow(0, distance);                                           

	CRect rect;
	GetClientRect(rect);
	CRect rtnew(rect.left, rect.bottom + distance, rect.right, rect.bottom);
	CRect rtnew2(rect.left, rect.top, rect.right, rect.top + distance);
	InvalidateRect(&rtnew);
	InvalidateRect(&rtnew2);

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



void CReaderVCView::OnInitialUpdate() 
{
	CView::OnInitialUpdate();
	
	// TODO: Add your specialized code here and/or call the base class
}

void CReaderVCView::OnDestroy() 
{
	CView::OnDestroy();
	// TODO: Add your message handler code here
}

void CReaderVCView::OnUpdateDocFirstpage(CCmdUI* pCmdUI) 
{
	if (0 == m_nPageIndex)
	{
		pCmdUI->Enable(FALSE);
	} 
	else
	{
		pCmdUI->Enable(TRUE);
	}
	
}

void CReaderVCView::OnUpdateDocLastpage(CCmdUI* pCmdUI) 
{
	if (m_nPageIndex == m_nTotalPage - 1)
	{
		pCmdUI->Enable(FALSE);
	} 
	else
	{
		pCmdUI->Enable(TRUE);
	}
	
}

void CReaderVCView::OnUpdateDocNextpage(CCmdUI* pCmdUI) 
{
	if (m_nPageIndex == m_nTotalPage - 1)
	{
		pCmdUI->Enable(FALSE);
	} 
	else
	{
		pCmdUI->Enable(TRUE);
	}
	
}

void CReaderVCView::OnUpdateDocPrepage(CCmdUI* pCmdUI) 
{
	if (0 == m_nPageIndex)
	{
		pCmdUI->Enable(FALSE);
	} 
	else
	{
		pCmdUI->Enable(TRUE);
	}
	
}

void CReaderVCView::OnUpdateToolHand(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	if (m_bHand)
	{
		pCmdUI->SetCheck(1);
	} 
	else
	{
		pCmdUI->SetCheck(0);
	}
	
	
}

void CReaderVCView::OnUpdateToolSnapshot(CCmdUI* pCmdUI) 
{
	if (m_bSnap)
	{
		pCmdUI->SetCheck(1);
	} 
	else
	{
		pCmdUI->SetCheck(0);
	}
	
}


void CReaderVCView::OnViewBookmark() 
{
	// TODO: Add your command handler code here
	CChildFrame* pParent = (CChildFrame*)GetParentFrame();
	if(pParent == NULL) return;
	if (m_bBookmark) {
		pParent->m_wndSplitter.ShowColumn();
		
	}else{
		pParent->m_wndSplitter.HideColumn(0);
	}
	m_bBookmark = !m_bBookmark;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -