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

📄 wcenotpaddlg.cpp

📁 一个windows ce上的notepad
💻 CPP
📖 第 1 页 / 共 2 页
字号:
							 FILE_ATTRIBUTE_NORMAL,
							 NULL);
	dwFileSize = GetFileSize( hAsciiFile, NULL );

	//不在本这里设置当前读取的数据为第几部分
	pszFileBuff = (char*)LocalAlloc( LPTR, dwFileSize );
	if( !pszFileBuff )
		return	NULL;
	if(m_nCurFilePart == -1)
		m_dwFileSize = dwFileSize;

	DWORD TempReadSize;
	if(dwFileSize - nStartPos < size)
		TempReadSize = dwFileSize - nStartPos;
	else
		TempReadSize = size;
	SetFilePointer(hAsciiFile, nStartPos,NULL, FILE_BEGIN);
	ReadFile( hAsciiFile,(LPVOID)pszFileBuff, TempReadSize, &dwBytesWritten, NULL);
	if(dwBytesWritten <= 0)
		return NULL;
	dwReadSize = dwBytesWritten;
	pszUnicodeBuff = (TCHAR*)LocalAlloc( LPTR, sizeof(TCHAR) * ( dwFileSize + 1 ));
	mbstowcs( pszUnicodeBuff, (const char *)pszFileBuff, (size_t)strlen(pszFileBuff) );
	CString *strFileData = new CString();
	strFileData->Format(_T("%s"),pszUnicodeBuff);

	LocalFree(pszUnicodeBuff);
	LocalFree(pszFileBuff);
	CloseHandle(hAsciiFile);
	return strFileData;
}

bool CWCENotpadDlg::HasNextBlock()
{
	return m_bHasNextBlock;
}

//计算下一个文件结点的分块信息、
BLOCK_INFO CWCENotpadDlg::CurBlockInfo(bool bLastBlock)
{
	BLOCK_INFO pbi;
	long len = m_strEdit.GetLength();
	int CharSize,nPageCnt;
	int LineCount = this->m_EditCtrl.GetLineCount();
	nPageCnt = LineCount/12;
	if(LineCount%12 != 0) //行数不是为12的整数倍
	{
		pbi.nPageCount = nPageCnt - 1;
		CharSize = m_EditCtrl.LineIndex(nPageCnt*12);
		if(bLastBlock) //在最后一页添加回车符
		{
			int AddLinesCount = 12 - LineCount%12;//必须添加的回车符个数
			for(int i=0;i<AddLinesCount;i++)
				m_strEdit += _T("\r\n");
		}
	}
	else
	{
		pbi.nPageCount =  nPageCnt - 2;
		CharSize = len;
	}
	if(bLastBlock)
		pbi.nPageCount += 1;
	UpdateData(false);
	
/*	//////////
	CString st;
	st.Format(_T("index=%d"),index);
	AfxMessageBox(st);
	//////////
	*/
	if(m_nCurFilePart == 0) 
	{
		pbi.lStartPos = 0;
	}
	else
	{
		pbi.lStartPos = m_BlockNode.GetAt(m_nCurFilePart-1).lStartPos
			+m_BlockNode.GetAt(m_nCurFilePart-1).lSize + 1;
	}

	if(bLastBlock) 
	{
		pbi.lSize = len;
	}
	else
	{
		pbi.lSize = CharSize;
	}
	return pbi;

//	CString ss;
//	ss.Format(_T("StartPos=%lu"),pbi.lStartPos);
//	AfxMessageBox(ss);
	
}

//获取下一个显示数据块
CString * CWCENotpadDlg::GetNextBlock()
{
//	long StartPos = (m_BlockNode.GetAt(m_nCurFilePart)).lStartPos;
	CString *ptr;
	DWORD dwFileSize;
	DWORD dwReadSize;
	if(m_bPartCountFinished && m_nCurFilePart == m_nFilePartCount)
		return NULL;
	else
	{
		DWORD StartPos;
		if(m_nCurFilePart == -1)
			StartPos = 0;
		else
			StartPos = (m_BlockNode.GetAt(m_nCurFilePart)).lStartPos
					+(m_BlockNode.GetAt(m_nCurFilePart)).lSize+1;
		ptr = ReadTextFile(m_sFilePathName,StartPos,FILE_UNIT_SIZE,dwReadSize);
	//	DWORD dwLeftSize = m_dwFileSize - StartPos; //未读部分文件大小
		if(ptr != NULL && dwReadSize > 0 )
		{
			m_nCurFilePart++;
			m_strEdit = *ptr;
			UpdateData(false);
			if(!m_bPartCountFinished && m_nFilePartCount+1 == m_nCurFilePart) //本块读取的为一个新块,要增加一个新的数据块信息结点
			{
				m_nFilePartCount++;
				BLOCK_INFO b_i;
				if( dwReadSize+StartPos >= m_dwFileSize )
				{
					m_bPartCountFinished = true;
					b_i = CurBlockInfo(true);
				}
				else
					b_i = CurBlockInfo(false);
				m_BlockNode.Add(b_i);
			}
		}
	}
}

CString * CWCENotpadDlg::GetPreBlock()
{
	if(m_nCurFilePart-1 < 0)
		return NULL;
	CString *pstr;
	long lPos = m_BlockNode.GetAt(m_nCurFilePart-1).lStartPos;
	long lSize = m_BlockNode.GetAt(m_nCurFilePart-1).lSize;
	DWORD dwReadSize;
	pstr = ReadTextFile(m_sFilePathName,lPos,lSize,dwReadSize);
	if(pstr != NULL)
	{
		m_strEdit = *pstr;
		m_nCurFilePart--;
		return pstr;
	}
	else
		return NULL;
}

void CWCENotpadDlg::SetFilePath(CString sFilePathName)
{
	this->m_sFilePathName = sFilePathName;
}

void CWCENotpadDlg::OnLButtonDown(UINT nFlags, CPoint point) 
{
	int idCurIndex = GetCurPressBtnID(point);
	WIDGET_NODE wn;
	if(idCurIndex != -1 ) //有按钮按下
	{
		if(m_nPreBtnIndex != -2 && idCurIndex != m_nPreBtnIndex)
		{
			wn = m_WidgetNode.GetAt(m_nPreBtnIndex);
			if(wn.nCurState == 0)
			{
				wn.nCurState = 1;
				m_WidgetNode.SetAt(m_nPreBtnIndex,wn);
				DrawBmpButton(m_nPreBtnIndex);
			}
		}
		wn = m_WidgetNode.GetAt(idCurIndex);
		if(wn.nCurState == 1)
		{
			wn.nCurState = 0;
			m_WidgetNode.SetAt(idCurIndex,wn);
			DrawBmpButton(idCurIndex);
		}
		m_nPreBtnIndex = idCurIndex;
		switch(m_WidgetNode.GetAt(idCurIndex).nBtnID)
		{
			case EXIT_READ:
				 EndDialog(0);
				 break;
			case NEXT_PAGE:
				 NextPage();
				 break;
			case PRE_PAGE:
				 PrePage();
				 break;
			default:
				break;
		}
	}
	else
	{
		if(m_nPreBtnIndex != -2 )
		{
			wn = m_WidgetNode.GetAt(m_nPreBtnIndex);
			wn.nCurState = 1;
			m_WidgetNode.SetAt(m_nPreBtnIndex,wn);
			DrawBmpButton(m_nPreBtnIndex);
		}
	}

	CDialog::OnLButtonDown(nFlags, point);
}

void CWCENotpadDlg::DrawBmpButton(int BtnIndex)
{
	CRect rc = m_WidgetNode.GetAt(BtnIndex).rect;
	int State = m_WidgetNode.GetAt(BtnIndex).nCurState;
	int SrcBmpID;
	if(State == 0)
		SrcBmpID = m_WidgetNode.GetAt(BtnIndex).nDownBitmapID;
	else
		SrcBmpID = m_WidgetNode.GetAt(BtnIndex).nUpBitmapId;
	CDC *pDC = GetDC();
	CDC ImageDc;
	CBitmap image,*pOldImg;
	image.LoadBitmap(SrcBmpID);
	ImageDc.CreateCompatibleDC(pDC);
	pOldImg=ImageDc.SelectObject(&image); 
	pDC->BitBlt(rc.left,rc.top,rc.Width(),rc.Height(),&ImageDc,0, 0,SRCCOPY);
	ImageDc.SelectObject(pOldImg); 	
	ImageDc.DeleteDC();
	ReleaseDC(pDC);

}

int CWCENotpadDlg::GetCurPressBtnID(CPoint pt)
{
	int IDindex=-1;
	for(int i=0;i<m_nBtnCount;i++)
	{
		if(m_WidgetNode.GetAt(i).rect.PtInRect(pt))
		{
		//	btnID = m_WidgetNode.GetAt(i).nBtnID;
			IDindex = i;
			break;
		}
	}
	return IDindex;
}

void CWCENotpadDlg::OnPaint() 
{
	CPaintDC dc(this); // device context for painting
	
	if(!m_bFirstDraw)
	{
		CRect EdgeRect(0,0,320,12);
		CBrush brush;
		brush.CreateSolidBrush(RGB(255,255,255));
		dc.FillRect( &EdgeRect, &brush);
		for(int i=0; i<m_nBtnCount; i++)
			this->DrawBmpButton(i);
		m_bFirstDraw = true;
	}
	
	// Do not call CDialog::OnPaint() for painting messages
}

void CWCENotpadDlg::AddBmpButton(int BtnID, CRect rc, int UpBmpID, int DownBmpID)
{
	WIDGET_NODE wn;
	wn.rect = rc;
	wn.nBtnID = BtnID;
	wn.nCurState = 1;
	wn.nDownBitmapID = DownBmpID;
	wn.nUpBitmapId = UpBmpID;
	m_WidgetNode.Add(wn);
	m_nBtnCount++;
}

HBRUSH CWCENotpadDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) 
{
	HBRUSH hbr;
	hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
	if(pWnd->GetDlgCtrlID() == IDC_SHOW_DATA)
	{
		//pDC->SetBkMode(TRANSPARENT);
		pDC->SetBkColor(RGB(255,255,255));
		pDC->SetTextColor(RGB(255,0,0));
		hbr = (HBRUSH)::GetStockObject(WHITE_BRUSH);
	}
//	HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
	
	
	// TODO: Return a different brush if the default is not desired
	return hbr;
}

⌨️ 快捷键说明

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