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

📄 wcenotpaddlg.cpp

📁 一个windows ce上的notepad
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// WCENotpadDlg.cpp : implementation file
//

#include "stdafx.h"
//#include "WCENotpad.h"
#include "WCENotpadDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

#define EXIT_READ 0
#define NEXT_PAGE 1
#define PRE_PAGE  2


/////////////////////////////////////////////////////////////////////////////
// CWCENotpadDlg dialog

const DWORD FILE_UNIT_SIZE = 10*1024;
CWCENotpadDlg::CWCENotpadDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CWCENotpadDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CWCENotpadDlg)
	m_strEdit = _T("");
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CWCENotpadDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CWCENotpadDlg)
	DDX_Control(pDX, IDC_SHOW_DATA, m_EditCtrl);
	DDX_Text(pDX, IDC_SHOW_DATA, m_strEdit);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CWCENotpadDlg, CDialog)
	//{{AFX_MSG_MAP(CWCENotpadDlg)
	ON_WM_LBUTTONDOWN()
	ON_WM_PAINT()
	ON_WM_CTLCOLOR()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CWCENotpadDlg message handlers

BOOL CWCENotpadDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	
//	CenterWindow(GetDesktopWindow());	// center to the hpc screen

	// TODO: Add extra initialization here

//	m_EditCtrlRect = CRect(6,10,164,64);
//	m_EditCtrl.GetClientRect(&m_EditCtrlRect);
	m_EditCtrl.SetLimitText(FILE_UNIT_SIZE);//每次读取的数据为预设的文件块大小
	m_EditCtrl.SetMargins(8,6);
	m_nCurPage = 0;
	m_nPageCount = 0;
	m_nFilePartCount = -1;
	m_nCurFilePart = -1;
	m_bPartCountFinished = false;
	m_dwFileSize = 0;
	m_nBtnCount = 0;
	m_bFirstDraw = false;
	m_nPreBtnIndex = -2;
	//往窗口上添加图片按钮
	this->AddBmpButton(EXIT_READ,CRect(0,211,106,240),IDB_EXIT_READ_UP,IDB_EXIT_READ_DOWN);//退出
	this->AddBmpButton(PRE_PAGE,CRect(107,211,213,240),IDB_PRE_PAGE_UP,IDB_PRE_PAGE_DOWN);//上一页
	this->AddBmpButton(NEXT_PAGE,CRect(214,211,320,240),IDB_NEXT_PAGE_UP,IDB_NEXT_PAGE_DOWN);//下一页

	this->GetNextBlock();//获取第一块数据

	return TRUE;  // return TRUE  unless you set the focus to a control
}



void CWCENotpadDlg::NextPage()
{
	int nLines = m_EditCtrl.GetLineCount();
	if(nLines <= 0)
		return ;
	if(m_nCurPage < m_BlockNode.GetAt(m_nCurFilePart).nPageCount )
	{
		m_nCurPage++;
		m_EditCtrl.LineScroll(12,0);
		
	}
	else //看有没有下一块数据
	{
	//	AfxMessageBox(_T("获取下一块数据。"));
		if(GetNextBlock() != NULL) //文件中还有下一块数据
		{
			//UpdateData(false);
			m_nCurPage = 0;
		}
	}
/*	CString ss;
	ss.Format(_T("当前块%d 当前总页数%d 当前页%d"),m_nCurFilePart,
		m_BlockNode.GetAt(m_nCurFilePart).nPageCount, m_nCurPage);
	this->m_staPageInfo.SetWindowText(ss);
	UpdateData(false);
	if(nLines>m_nCurPage*8)
	{
		m_EditCtrl.LineScroll(8,0);
	}
	else
		m_EditCtrl.LineScroll(nLines-m_nCurPage*8,0);
		
	m_nCurPage++;
	CString str;
	str.Format(_T("总页数 %d   当前第 %d 页"),m_nPageCount,m_nCurPage+1);
	this->m_staPageInfo.SetWindowText(str);
	int nFirstVisible = m_EditCtrl.GetFirstVisibleLine();
	CString s;
	s.Format(_T("first visible line:%d"),nFirstVisible);
	AfxMessageBox(s);
	if (nFirstVisible > 0)
	{
	  m_EditCtrl.LineScroll(-nFirstVisible, 0);
	}
	*/
}

void CWCENotpadDlg::PrePage() //只涉及到对当前页变量的操作,而不对当前数据块进行操作
{
	if(m_nCurPage > 0 )
	{
		m_EditCtrl.LineScroll(-12,0);
		m_nCurPage--;
	}
	else
	{
		if(GetPreBlock() != NULL)
		{
			int LinesScroll;
			m_nCurPage=(m_BlockNode.GetAt(m_nCurFilePart)).nPageCount;
			LinesScroll = m_nCurPage*12;
			UpdateData(false);
			m_EditCtrl.LineScroll(LinesScroll,0);
		}
	}
}

//DEL void CWCENotpadDlg::OnClose() 
//DEL {
//DEL 	EndDialog(0);	
//DEL }

//DEL void CWCENotpadDlg::OnOpenFile() 
//DEL {
//DEL 	DWORD   dwBytesWritten = 0, dwFileSize;
//DEL     TCHAR *  pszUnicodeBuff;
//DEL     char *   pszFileBuff = 0;
//DEL     HANDLE  hAsciiFile;
//DEL 
//DEL 	TCHAR szFilters[] =  _T("Text File(*.txt)|*.txt");
//DEL 	CFileDialog dlg(TRUE, _T("Text File"), NULL,
//DEL         OFN_HIDEREADONLY|OFN_FILEMUSTEXIST|OFN_READONLY, szFilters, this);
//DEL 	//OPENFILENAME ofn;
//DEL 	//dlg.m_ofn.lpstrInitialDir=_T("\\Storage Card\\");
//DEL 	dlg.m_ofn.lpstrInitialDir=_T("\\Temp");
//DEL 	if(dlg.DoModal()!=IDOK )
//DEL 		return;
//DEL 	CString FilePath = dlg.GetPathName();
//DEL 	m_sFilePathName = FilePath;
//DEL 	this->GetNextBlock();
//DEL /*	CString *pstr = ReadTextFile(FilePath,0,FILE_UNIT_SIZE,);
//DEL 	if(pstr != NULL)
//DEL 	{
//DEL 		m_strEdit =*pstr;
//DEL 		UpdateData(false);
//DEL 	}
//DEL 	BLOCK_INFO bi;
//DEL 	bi = this->CurBlockInfo(0);
//DEL 	m_BlockNode.Add(bi);
//DEL 	m_nCurFilePart = 0;
//DEL 	m_nCurPage = 0;
//DEL   LPOPENFILENAME lpof = NULL;
//DEL 	hAsciiFile = CreateFile( FilePath,
//DEL 							 GENERIC_READ ,
//DEL 							 FILE_SHARE_READ,
//DEL 							 NULL, 
//DEL 							 OPEN_EXISTING, 
//DEL 							 FILE_ATTRIBUTE_NORMAL,
//DEL 							 NULL);
//DEL 	dwFileSize = GetFileSize( hAsciiFile, NULL );
//DEL 	pszFileBuff = (char*)LocalAlloc( LPTR, dwFileSize );
//DEL 	if( !pszFileBuff )
//DEL 	{    
//DEL 		::MessageBox( NULL, TEXT( "Couldn't Allocate Memory."), 
//DEL 			TEXT( "Open File Failed" ), MB_ICONERROR);
//DEL 		return ;
//DEL 	}
//DEL 
//DEL 	ReadFile( hAsciiFile,(LPVOID)pszFileBuff, dwFileSize, &dwBytesWritten, NULL);
//DEL 
//DEL //	AfxMessageBox(pszFileBuff);
//DEL 	pszUnicodeBuff = (TCHAR *)LocalAlloc( LPTR, sizeof(TCHAR) * ( dwFileSize + 1 ));
//DEL 	mbstowcs( pszUnicodeBuff, (char *)pszFileBuff, (size_t)strlen(pszFileBuff) );
//DEL 	CString sFileData;
//DEL 	sFileData.Format(_T("%s"),pszUnicodeBuff);	
//DEL //	SetDlgItemText(IDC_SHOW_DATA,sFileData);
//DEL 	m_EditCtrl.SetWindowText(sFileData);
//DEL 	int LineCount = this->m_EditCtrl.GetLineCount();
//DEL 	if(LineCount%8 != 0)
//DEL 		m_nPageCount = LineCount/8 +1;
//DEL 	else
//DEL 		m_nPageCount = LineCount/8;
//DEL 
//DEL 	CString str;
//DEL 	str.Format(_T("总页数 %d   当前第 %d 页"),m_nPageCount,m_nCurPage+1);
//DEL 	this->m_staPageInfo.SetWindowText(str);
//DEL 
//DEL 	BLOCK_INFO	BlockInfo;
//DEL 	BlockInfo.lStartPos = 0;
//DEL 	BlockInfo.nPageCount = -1;
//DEL 	BlockInfo.lSize = FILE_UNIT_SIZE;	
//DEL 	
//DEL 
//DEL 	LocalFree(pszUnicodeBuff);
//DEL 	LocalFree(pszFileBuff);
//DEL 	CloseHandle(hAsciiFile);*/	
//DEL 
//DEL }

//DEL void CWCENotpadDlg::OnNextPage() 
//DEL {
//DEL 	NextPage();
//DEL }

//DEL void CWCENotpadDlg::OnPrepage() 
//DEL {
//DEL 	PrePage();	
//DEL }


BOOL CWCENotpadDlg::OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo) 
{
	return CDialog::OnCmdMsg(nID, nCode, pExtra, pHandlerInfo);
}

BOOL CWCENotpadDlg::OnCommand(WPARAM wParam, LPARAM lParam) 
{
	int wmId, wmEvent;
	wmId   = LOWORD(wParam); 
	wmEvent = HIWORD(wParam); 
	switch (wmId)
	{
		case IDC_SHOW_DATA:
		   this->SetFocus();
		   break;
	}
	
	return CDialog::OnCommand(wParam, lParam);
}


LRESULT CWCENotpadDlg::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) 
{
/*	int wmId;
	wmId    = LOWORD(wParam); 
	switch (wmId)
	{
		case IDC_SHOW_DATA:
			AfxMessageBox(_T("Window proc!"));
			 return 0;
			 break;
	}
*/	
	return CDialog::WindowProc(message, wParam, lParam);
}

CString *CWCENotpadDlg::ReadTextFile(CString sFilePathName,DWORD nStartPos, DWORD size,DWORD &dwReadSize)
{
    DWORD   dwBytesWritten = 0, dwFileSize;
    TCHAR*  pszUnicodeBuff;
    CHAR*   pszFileBuff = 0;
    HANDLE  hAsciiFile;


    LPOPENFILENAME lpof = NULL;
	hAsciiFile = CreateFile( sFilePathName,
							 GENERIC_READ ,
							 FILE_SHARE_READ,
							 NULL, 
							 OPEN_EXISTING, 

⌨️ 快捷键说明

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