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

📄 mutilcdseldlg.cpp

📁 MT6225修改LCDwww.1mp.cn_lcd_select_tool.rar
💻 CPP
字号:
// MutiLCDSelDlg.cpp : implementation file
//

#include "stdafx.h"
#include "MutiLCDSel.h"
#include "MutiLCDSelDlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

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()

/////////////////////////////////////////////////////////////////////////////
// CMutiLCDSelDlg dialog

CMutiLCDSelDlg::CMutiLCDSelDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CMutiLCDSelDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CMutiLCDSelDlg)
	m_StrFilePath = _T("");
	m_strIcInfo = _T("");
	m_strVendor = _T("");
	//}}AFX_DATA_INIT
	m_file_content = NULL;
	m_filelen = NULL;
	m_positon = 0;
	m_count = 0;
	m_currentListindex = 0;
	m_StroutputFilePath =_T("");
	m_strFileExt = _T("");
	memset(m_LCDFlag,0,sizeof(m_LCDFlag));
	memset(m_lcd_info,0x0,sizeof(m_lcd_info));
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CMutiLCDSelDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CMutiLCDSelDlg)
	DDX_Control(pDX, IDC_LCDLIST, m_LcdList);
	DDX_Text(pDX, IDC_FILEPATH, m_StrFilePath);
	DDX_Text(pDX, IDC_ICINFO, m_strIcInfo);
	DDX_Text(pDX, IDC_VENDORINFO, m_strVendor);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CMutiLCDSelDlg, CDialog)
	//{{AFX_MSG_MAP(CMutiLCDSelDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_BUFILESELECT, OnBufileselect)
	ON_BN_CLICKED(IDC_BUSAVEAS, OnBusaveas)
	ON_LBN_SELCHANGE(IDC_LCDLIST, OnSelchangeLcdlist)
	ON_EN_CHANGE(IDC_FILEPATH, OnChangeFilepath)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMutiLCDSelDlg message handlers

BOOL CMutiLCDSelDlg::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
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CMutiLCDSelDlg::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 CMutiLCDSelDlg::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 CMutiLCDSelDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CMutiLCDSelDlg::OnBufileselect() 
{
	// TODO: Add your control notification handler code here
	DWORD dwFlags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
	static char BASED_CODE szFilter[] = "BIN Files (*.BIN)|*.BIN||";

	CFileDialog	dialog(TRUE,NULL,NULL,dwFlags,szFilter,NULL );

	if(dialog.DoModal() == IDOK)
	{
		m_StrFilePath = dialog.GetPathName();
		UpdateData(FALSE);
		ReadBinFile();
		ParseLcdInfo();
		GetLcdInfoStr();
		CreateLcdList();
		DrawLcdInfo();
	}	
}

void CMutiLCDSelDlg::OnBusaveas() 
{
	// TODO: Add your control notification handler code here
	DWORD dwFlags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
	static char BASED_CODE szFilter[] = "BIN Files (*.BIN)|*.BIN||";

	if(m_StrFilePath.IsEmpty())
	{
		MessageBox("请先选择bin文件",NULL,MB_OK);
		if(m_file_content)
		{
			GlobalFree((HGLOBAL)m_file_content);
			m_file_content = NULL;
		}
		return;
	}

	CFileDialog	dialog(FALSE,NULL,m_StrFilePath,dwFlags,szFilter,NULL );

	if(dialog.DoModal() == IDOK)
	{
		m_StroutputFilePath = dialog.GetPathName();
		m_strFileExt = dialog.GetFileExt();
		ConvertBinFile();
		
	}	
}

void CMutiLCDSelDlg::OnSelchangeLcdlist() 
{
	// TODO: Add your control notification handler code here
	char tempfalg[MAX_LCD_FLG_LEN+1] ={0};
	m_currentListindex = m_LcdList.GetCurSel();

	sprintf(tempfalg,"%02X",m_currentListindex);
	memcpy(m_LCDFlag,tempfalg,MAX_LCD_FLG_LEN);
	DrawLcdInfo();
}

void CMutiLCDSelDlg::ReadBinFile()
{
	if(m_StrFilePath.IsEmpty())
	{
		return ;
	}

	if(!m_binfile.Open((LPCTSTR)m_StrFilePath,CFile::typeBinary|CFile::modeReadWrite,NULL))
	{
		MessageBox("文件打开错误",NULL,MB_OK);
		m_binfile.Close();
		return;
	}
	m_count = 0;
	m_LcdList.ResetContent();
	m_filelen = m_binfile.GetLength();
	m_file_content = (BYTE*)GlobalAlloc(0,m_filelen);
	m_binfile.ReadHuge(m_file_content,m_filelen);
	m_binfile.Close();
	return ;
}

void CMutiLCDSelDlg::ParseLcdInfo()
{
	DWORD64 i;
	char buf[50];


	for(i =0;i<m_filelen;i++)
	{
		if(m_file_content[i] == 'L'
			&&m_file_content[i+1] == 'I'
			&&m_file_content[i+2] == 'Q'
			&&m_file_content[i+3] == 'U'
			&&m_file_content[i+4] == 'I'
			&&m_file_content[i+5] == 'D'						
			)
		{
			if(m_file_content[i+6] == '_'
				&&m_file_content[i+7] == 'L'
				&&m_file_content[i+8] == 'C'
				&&m_file_content[i+9] == 'D'
				&&m_file_content[i+10] == '_'
			)
			{
				m_positon = i;
				memcpy(m_LCDFlag,m_file_content+i+11,MAX_LCD_FLG_LEN);

				for(int j = 0; j < 50 ;j++)
				{
					buf[j] = m_file_content[i+j];
				}
			}
			else if(m_file_content[i+6] == 'X'
				&&m_file_content[i+7] == '_'
				&&m_file_content[i+29] == '_'
				&&m_file_content[i+30] == 'L'
				&&m_file_content[i+31] == 'C'
				&&m_file_content[i+32] == 'D'
				&&m_file_content[i+33] == '_'
				)
			{
				for(int j = 0; j < 50 ;j++)
				{
					buf[j] = m_file_content[i+j];
				}

				memcpy(m_lcd_info[m_count].vendor,m_file_content+i+8,MAX_LCD_STR_LEN);
				memcpy(m_lcd_info[m_count].IC,m_file_content+i+19,MAX_LCD_STR_LEN);
				memcpy(m_lcd_info[m_count].flag,m_file_content+i+34,MAX_LCD_FLG_LEN);
				m_count++;
			}
		}
	}
}

BOOL CMutiLCDSelDlg::DestroyWindow() 
{
	// TODO: Add your specialized code here and/or call the base class
	if(m_file_content)
	{
		GlobalFree((HGLOBAL)m_file_content);
		m_file_content = NULL;
	}
	return CDialog::DestroyWindow();
}

void CMutiLCDSelDlg::CreateLcdList()
{
	int i;

	for(i = 0;i<m_count;i++)
	{
		CString str(m_lcd_info[i].vendor);

		m_LcdList.InsertString(i,str);
	}
//	sscanf((const char*) m_LCDFlag, "%X",&m_currentListindex);

	m_LCDFlag[0] = m_lcd_info[m_currentListindex].flag[0];
	m_LCDFlag[1] = m_lcd_info[m_currentListindex].flag[1];



	m_LcdList.SetCurSel(m_currentListindex);
}

void CMutiLCDSelDlg::GetLcdInfoStr()
{
	int i,j,k;
	for(i=0;i<m_count;i++)
	{
		for(j=0;j<MAX_LCD_STR_LEN;j++)
		{
			if(m_lcd_info[i].vendor[j] == '#')
			{
				m_lcd_info[i].vendor[j] = '\0';
				break;
			}
		}

		for(k=MAX_LCD_STR_LEN;k>=0;k--)
		{
			if(m_lcd_info[i].IC[k] == '#'
				&&(m_lcd_info[i].IC[k-1] != '#'))
			{
				m_lcd_info[i].IC[k] = '\0';
				break;
			}
		}	
	}
}

void CMutiLCDSelDlg::DrawLcdInfo()
{

	LPTSTR p,q;

	if(strcmp(m_lcd_info[m_currentListindex].vendor,"TRULY")==0)
	{
		m_strVendor = L"信利";
	}
	else if(strcmp(m_lcd_info[m_currentListindex].vendor,"JIUZHENG")==0)
	{
		m_strVendor = L"九正";
	}
	else if(strcmp(m_lcd_info[m_currentListindex].vendor,"YASSY")==0)
	{
		m_strVendor = L"雅视";
	}
	else if(strcmp(m_lcd_info[m_currentListindex].vendor,"LEYI")==0)
	{
		m_strVendor = L"乐易";
	}
	else if(strcmp(m_lcd_info[m_currentListindex].vendor,"BYD")==0)
	{
		m_strVendor = L"比亚迪";
	}
	else if(strcmp(m_lcd_info[m_currentListindex].vendor,"DIJING")==0)
	{
		m_strVendor = L"帝晶";
	}
	else if(strcmp(m_lcd_info[m_currentListindex].vendor,"HANGTIAN")==0)
	{
		m_strVendor = L"航天光电";
	}
	else if(strcmp(m_lcd_info[m_currentListindex].vendor,"JUNHUA")==0)
	{
		m_strVendor = L"军华";
	}
	else
	{
		m_strVendor = m_lcd_info[m_currentListindex].vendor;	
	}
	m_strIcInfo = m_lcd_info[m_currentListindex].IC;


	m_LCDFlag[0] = m_lcd_info[m_currentListindex].flag[0];
	m_LCDFlag[1] = m_lcd_info[m_currentListindex].flag[1];


	UpdateData(FALSE);
	
}

void CMutiLCDSelDlg::ConvertBinFile()
{
	int i;	

	if(m_StroutputFilePath.IsEmpty())
	{
		MessageBox("请填上转化bin文件名字",NULL,MB_OK);
		if(m_file_content)
		{
			GlobalFree((HGLOBAL)m_file_content);
			m_file_content = NULL;
		}
		return;
	}

	if(m_strFileExt.IsEmpty())
	{
		m_StroutputFilePath += ".bin";
	}
	else if((m_strFileExt != "BIN")&&(m_strFileExt != "bin"))
	{
		//m_strFileExt = ".bin";
		m_StroutputFilePath.TrimRight(".");
		m_StroutputFilePath += ".bin";
	}
	else if(m_strFileExt == "BIN")
	{
	  m_StroutputFilePath.Replace(".BIN",".bin");		
	}

	memcpy(m_file_content+m_positon+11,m_LCDFlag,MAX_LCD_FLG_LEN);

	if(!m_oupbinfile.Open((LPCTSTR)m_StroutputFilePath,CFile::typeBinary|CFile::modeCreate | CFile::modeWrite,NULL))
	{
		MessageBox("文件创建失败",NULL,MB_OK);
		m_oupbinfile.Close();
		return;
	}
	m_oupbinfile.WriteHuge(m_file_content,m_filelen);
	m_oupbinfile.Flush();  
	m_oupbinfile.Close();	
	MessageBox("转化完成",NULL,MB_OK);
}

void CMutiLCDSelDlg::OnChangeFilepath() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	
}

⌨️ 快捷键说明

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