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

📄 数据分析器dlg.cpp

📁 数据结构分析工具
💻 CPP
📖 第 1 页 / 共 3 页
字号:
// 数据分析器Dlg.cpp : implementation file
//

#include "stdafx.h"
#include "数据分析器.h"
#include "数据分析器Dlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
void init_crc32_table();
unsigned long GenerateCRC32(unsigned char * DataBuf,unsigned long len);
void MakeCrc(byte buf[], int len);
unsigned int mycalccrc32(unsigned char * data,int len);
unsigned int m_crcValue = 0;
class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
		// No message handlers
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMyDlg dialog

CMyDlg::CMyDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CMyDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CMyDlg)
	m_path = _T("");
	m_data = _T("");
	m_datafile = _T("");
	m_len = 100;
	m_crc = _T("");
	m_charnum = 0;
	m_start = 0;
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);

	m_file = NULL;
	m_k = 0;

	init_crc32_table();
}

void CMyDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CMyDlg)
	DDX_Control(pDX, IDC_DATA, m_datactr);
	DDX_Text(pDX, IDC_PATH, m_path);
	DDX_Text(pDX, IDC_DATA, m_data);
	DDX_Text(pDX, IDC_datafile, m_datafile);
	DDX_Text(pDX, IDC_len, m_len);
	DDX_Text(pDX, IDC_CRC, m_crc);
	DDX_Text(pDX, IDC_charnum, m_charnum);
	DDX_GridControl(pDX, IDC_GRID, m_Grid);
	DDX_Text(pDX, IDC_START, m_start);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CMyDlg, CDialog)
	//{{AFX_MSG_MAP(CMyDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_brower, Onbrower)
	ON_BN_CLICKED(IDC_OPEN, OnOpen)
	ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
	ON_BN_CLICKED(IDC_Analyse, OnAnalyse)
	ON_BN_CLICKED(IDC_BUTTON4, OnButton4)
	ON_BN_CLICKED(IDC_BUTTON5, OnLoad)
	ON_BN_CLICKED(IDC_brower2, Onbrower2)
	ON_BN_CLICKED(IDC_OPEN2, OnOpen2)
	ON_BN_CLICKED(IDC_SAVE, OnSave)
	ON_BN_CLICKED(IDC_ADDLINE, OnAddline)
	ON_BN_CLICKED(IDC_DELETELINE, OnDeleteline)
	ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
	ON_BN_CLICKED(IDC_CRC32, OnCrc32)
	ON_BN_CLICKED(IDC_TONGJI, OnTongji)
	ON_BN_CLICKED(IDC_CLEAR, OnClear)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMyDlg message handlers

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

	// Add "About..." menu item to system menu.

	// IDM_ABOUTBOX must be in the system command range.
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	// 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
	
	// TODO: Add extra initialization here
	InitGrid();
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CMyDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CMyDlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CMyDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CMyDlg::Onbrower() 
{
	// TODO: Add your control notification handler code here
	//CFileDialog dlg(true,NULL,NULL,OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,CODESTREAMFILEEX);
	CFileDialog dlg(true);
	if(dlg.DoModal()==IDOK)
	{
	//	m_filename = dlg.GetFileName();	
		m_path = dlg.GetPathName();
	//	m_pathname.Replace(m_filename,"");
	//	m_filename = dlg.GetPathName();	
		this->UpdateData(false);
	//	BrowseFile(0,m_pathname);
	//	this->GetDlgItem(IDC_Play)->EnableWindow(true);
	}
}

void CMyDlg::OnOpen() 
{
	// TODO: Add your control notification handler code here
	
	/*打开文件*/
	FILE *fp;
	int linenum = SHOWLINE_NUM;
	char data[16];
	long filelong;
	int readline;
	CString strtemp;
	int i;

	this->UpdateData(true);

	if(m_path.IsEmpty())
	{
		return;
	}

	fp = fopen(m_path,"rb");

	if(fp == NULL)
	{
		return;
	}

	/*读文件,一行读16个字节,*/
	m_data.Empty();

	fseek(fp,0,SEEK_SET);

	filelong = ftell(fp);
	fseek(fp,0,SEEK_END);
	filelong = ftell(fp) - filelong;

	fseek(fp,0,SEEK_SET);
	if(m_len > 0)
	{
		if(filelong>m_len+m_start)
		{
			filelong =  m_len;
		}
	}



	this->BeginWaitCursor();

	fseek(fp,m_start,SEEK_SET);
	while(filelong > 0)
	{
		
		if(filelong > linenum)
		{
			readline = linenum;
		}
		else
		{
			readline = filelong;
		}

		fread(data,readline,1,fp);

		for(i=0;i<readline;i++)
		{
			strtemp.Empty();
			strtemp.Format("%02X ",(unsigned char)data[i]);
			m_data+=strtemp;
		}
	
		/*
		for(i=readline;i<linenum;i++)
		{
			m_data+="   ";
		}
		

		m_data+="===";
		for(i=0;i<readline;i++)
		{
			strtemp.Empty();
			strtemp.Format("%c",data[i]);
			m_data+=strtemp;
		}
		*/

		m_data+=0x0d;
		m_data+=0x0A;

		filelong -= readline;

	}
	
	fclose(fp);

	this->UpdateData(false);

	this->EndWaitCursor();
}

void CMyDlg::OnButton2() 
{
	// TODO: Add your control notification handler code here
	CPoint p;
	CString str;
	int x,y;
	p = m_datactr.GetCaretPos();

	str.Format("%d,%d",p.x/6,p.y/12);

//	AfxMessageBox(str);

	m_datactr.GetSel(x,y);

//	x = m_Grid.GetRowCount();
	str.Format("%d,%d",x,y);
	AfxMessageBox(str);


}
BOOL CMyDlg::PreTranslateMessage(MSG* pMsg) 
{
	// TODO: Add your specialized code here and/or call the base class
	if( pMsg->message == WM_KEYDOWN )
    {
        if(pMsg->wParam == VK_RETURN
            || pMsg->wParam == VK_ESCAPE )
        {
            ::TranslateMessage(pMsg);
            ::DispatchMessage(pMsg);
            return TRUE;                    // DO NOT process further
        }
    }
	return CDialog::PreTranslateMessage(pMsg);
}
void CMyDlg::InitGrid()
{
	m_Grid.DeleteAllItems();
  //  m_Grid.AutoFill();
	m_Grid.SetRowCount(20);
	m_Grid.SetColumnCount(8);
	m_Grid.SetFixedRowCount(1);
	m_Grid.SetFixedColumnCount(1);
	m_Grid.SetColumnWidth(0,40);



	for(int i=1;i<20;i++)
	{
		CString text;
		text.Format("%d",i);
		m_Grid.SetItemText(i,0,text);
	}
	
	/*条码,操作,原因,责任人,去向,时间,记录人*/
	m_Grid.SetItemText(0,0,"序号");
	m_Grid.SetItemText(0,1,"名称");
	m_Grid.SetItemText(0,2,"类型");
	m_Grid.SetItemText(0,3,"位数");
	m_Grid.SetItemText(0,4,"字符显示");
	m_Grid.SetItemText(0,5,"十进制");
	m_Grid.SetItemText(0,6,"十六进制");
	m_Grid.SetItemText(0,7,"二进制");

	m_Grid.Invalidate();
}
/*把字符C中的低k位移到字符串data中,data中最后k位被移走*/
void CMyDlg::charmove(unsigned char c, int k, unsigned char *data, int len)
{
	int i;
	for(i=len-1;i>0;i--)
	{
		data[i] = (data[i]>>k) | (data[i-1] << (8-k));
	}

	data[0] = (data[0]>>k) | (c << (8-k));
	data[len] = data[len-1] << (8 -k);

}

void CMyDlg::GetData(unsigned char *data, int k)
{
	int charnum;
	int prebitnum;
	int rebitnum;
	int readbitnum;
	unsigned char reservertemp;

	prebitnum = m_k;
	readbitnum = k - prebitnum;

	if(readbitnum<=0)
	{
		data[0] = GetBit(m_c,m_k - k,m_k-1);
		m_k= m_k -k;
		return;
	}
	rebitnum = readbitnum%8;
	charnum = readbitnum/8;

	if(rebitnum)
	{
		charnum+=1;
		rebitnum = 8 - rebitnum;
	}

	m_k=rebitnum;


	fread(data,charnum,1,m_file);

	if(rebitnum>0)
	{
		reservertemp = data[charnum-1];
	}

	if(prebitnum > 0)
	{

⌨️ 快捷键说明

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