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

📄 ftptranserview.cpp

📁 大家好,好久没做什么东西了,前些日子偶然看到本论坛的一个FTP多线程断点续传的源代码
💻 CPP
字号:
// FTPTranserView.cpp : CFTPTranserView 类的实现
//

#include "stdafx.h"
#include "FTPTranser.h"

#include "FTPTranserDoc.h"
#include "FTPTranserView.h"
#include ".\ftptranserview.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif


// CFTPTranserView

IMPLEMENT_DYNCREATE(CFTPTranserView, CScrollView)

BEGIN_MESSAGE_MAP(CFTPTranserView, CScrollView)
	ON_WM_SIZE()
	ON_WM_VSCROLL()
END_MESSAGE_MAP()

// CFTPTranserView 构造/析构

CFTPTranserView::CFTPTranserView()
{
	// TODO: 在此处添加构造代码

}

CFTPTranserView::~CFTPTranserView()
{
}

BOOL CFTPTranserView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: 在此处通过修改 CREATESTRUCT cs 来修改窗口类或
	// 样式

	return CView::PreCreateWindow(cs);
}


void CFTPTranserView::OnProcess(int start,int len)
{
	CFTPTranserDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	if (!pDoc)
		return;
}
// CFTPTranserView 绘制

void CFTPTranserView::OnDraw(CDC* pDC)
{
	
	CFTPTranserDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	if (!pDoc)
		return;
	CDC back;
	CBitmap backbit;
	back.CreateCompatibleDC(pDC);
	
	
	CBitmap bitmap,bitmap1;
	bitmap.LoadBitmap(IDB_BITMAP1);
	bitmap1.LoadBitmap(IDB_BITMAP2);
	CDC dc,dc1;
	dc.CreateCompatibleDC(pDC);
	dc1.CreateCompatibleDC(pDC);
	HBITMAP hbit = (HBITMAP)bitmap.GetSafeHandle();
	HBITMAP hbit1 = (HBITMAP)bitmap1.GetSafeHandle();
	if(hbit == NULL || hbit1 == NULL)
	{
		return;
	}
	HANDLE old = SelectObject(dc.GetSafeHdc(),hbit);
	HANDLE old1 = SelectObject(dc1.GetSafeHdc(),hbit1);
	


	RECT clientRect;
	GetClientRect(&clientRect);
	backbit.CreateCompatibleBitmap(pDC,clientRect.right - clientRect.left,clientRect.bottom - clientRect.top);
	HANDLE old2 = SelectObject(back.GetSafeHdc(),backbit);
	back.FloodFill(0,0,RGB(248,248,224));
	int curY = GetScrollPos(SB_VERT);
	int numperline = (clientRect.right - clientRect.left) / 11;
	int numpercol = (clientRect.bottom - clientRect.top) / 11 + 2;
	int lines = curY / 11;
	int index = lines * numperline;
	int count = pDoc->count/NUMBERPERPOINT;

	for(int i = 0; i<numpercol && index < count ; i++)
	{
		for(int j= 0 ; j<numperline && index < count ; j++,index++)
		{
			if(index > pDoc->current / NUMBERPERPOINT)
				BitBlt(back.GetSafeHdc(),j * 11,i * 11,11,11,dc.GetSafeHdc(),0,0,SRCCOPY);
			else
				BitBlt(back.GetSafeHdc(),j * 11,i * 11,11,11,dc1.GetSafeHdc(),0,0,SRCCOPY);
		}
	}

	BitBlt(pDC->GetSafeHdc(),0,curY,clientRect.right-clientRect.left,clientRect.bottom - clientRect.top,back.GetSafeHdc(),0,0,SRCCOPY);

	
	SelectObject(dc.GetSafeHdc(),old);
	SelectObject(dc1.GetSafeHdc(),old1);
	SelectObject(back.GetSafeHdc(),old2);
}


// CFTPTranserView 诊断

#ifdef _DEBUG
void CFTPTranserView::AssertValid() const
{
	CView::AssertValid();
}

void CFTPTranserView::Dump(CDumpContext& dc) const
{
	CView::Dump(dc);
}

CFTPTranserDoc* CFTPTranserView::GetDocument() const // 非调试版本是内联的
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CFTPTranserDoc)));
	return (CFTPTranserDoc*)m_pDocument;
}
#endif //_DEBUG


// CFTPTranserView 消息处理程序

void CFTPTranserView::OnInitialUpdate()
{
	CScrollView::OnInitialUpdate();
	CSize sizeTotal;
	// TODO: 计算此视图的合计大小
	sizeTotal.cx = sizeTotal.cy = 1;
	SetScrollSizes(MM_TEXT, sizeTotal);
}

void CFTPTranserView::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint)
{	
	if(!this->IsWindowVisible())
		return;
	if(lHint != 0)
	{
		CFTPTranserDoc* pDoc = GetDocument();
		RECT clientRect;
		GetClientRect(&clientRect);
		int curY = GetScrollPos(SB_VERT);
		int numperline = (clientRect.right - clientRect.left) / 11;
		int numpercol = (clientRect.bottom - clientRect.top) / 11 + 2;
		int lines = curY / 11;
		int index = lines * numperline;
		if(pDoc->current > index * NUMBERPERPOINT && pDoc->current < (lines+numpercol) * numperline * NUMBERPERPOINT)
		{
			CPoint start,end;
			start.x = (pDoc->last - ((pDoc->last / numperline) * numperline)) * 11;
			start.y = pDoc->last /numperline * 11 - curY;

			index = pDoc->current / NUMBERPERPOINT;
			end.x = (index - ((index /numperline) * numperline)) * 11;
			end.y = (index /numperline + 1) * 11 - curY;

			CRect rect(start,end);
			//在不同行
			if(end.y - start.y > 11)
			{
				rect.SetRect(start.x,start.y,clientRect.right,start.y+11);
				InvalidateRect(&rect);
				rect.SetRect(0,end.y - 11,end.x,end.y);
				InvalidateRect(&rect);
				//如果中间还有整行的
				if(end.y - start.y > 22)
				{
					rect.SetRect(0,start.y+11,clientRect.right,end.y - 11);
					InvalidateRect(&rect);
				}
			}			
			InvalidateRect(&rect);

			pDoc->last = index;
		}

		
	}
	else
		CScrollView::OnUpdate(pSender,lHint,pHint);		
}

void CFTPTranserView::OnSize(UINT nType, int cx, int cy)
{
	CScrollView::OnSize(nType, cx, cy);
	

	CFTPTranserDoc * pDoc = (CFTPTranserDoc *)GetDocument();
	if(pDoc == NULL)
		return;
	SIZE size;
	if(pDoc->count <= 0)
	{
		size.cx = 0;
		size.cy = 0;
	}
	else
	{
		
		RECT clientRect;
		GetClientRect(&clientRect);
		int with = clientRect.right - clientRect.left;
		if(with <= 0)
			with = 100;
		int lines = (pDoc->count / NUMBERPERPOINT)	/ (with / 11)  + 2;
		
		
		size.cx = clientRect.right - clientRect.left;
		size.cy = lines * 11;
	}
	SetScrollSizes(MM_TEXT,size);
}

void CFTPTranserView::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
	// TODO: Add your message handler code here and/or call default

	CScrollView::OnVScroll(nSBCode, nPos, pScrollBar);	
	
	if(nSBCode == SB_ENDSCROLL)
	{
		RECT clientRect;
		GetClientRect(&clientRect);
		InvalidateRect(&clientRect);
	}

}

⌨️ 快捷键说明

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