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

📄 sqlbig5bugtooldlg.cpp

📁 SQLBig5BugTool 宽字符操作问题
💻 CPP
字号:
// SQLBig5BugToolDlg.cpp : implementation file
//

#include "stdafx.h"
#include "SQLBig5BugTool.h"
#include "SQLBig5BugToolDlg.h"

#include "MyIniFile.h"
#include <io.h>

#define COL_NAME_FILE_PATH "文件路径"

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

/////////////////////////////////////////////////////////////////////////////
// CSQLBig5BugToolDlg dialog

CSQLBig5BugToolDlg::CSQLBig5BugToolDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CSQLBig5BugToolDlg::IDD, pParent)
{
	m_strDictFilePath = AfxGetApp()->GetProfileString("SQLBig5BugTool","DictFilePath");

	if(m_strDictFilePath.IsEmpty())
	{
		m_strDictFilePath=GetFullPathEx("WrongWord.txt",GetExeDir()).c_str();
	}
	//{{AFX_DATA_INIT(CSQLBig5BugToolDlg)
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

CSQLBig5BugToolDlg::~CSQLBig5BugToolDlg()
{
}

void CSQLBig5BugToolDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CSQLBig5BugToolDlg)
	DDX_Control(pDX, IDC_MSG_LIST, m_listMsg);
	DDX_Control(pDX, IDC_SQL_FILE_LIST, m_listSQLFile);
	DDX_Text(pDX, IDC_EDIT_DICT, m_strDictFilePath);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CSQLBig5BugToolDlg, CDialog)
	//{{AFX_MSG_MAP(CSQLBig5BugToolDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_BUTTON_ADD_FILE, OnButtonAddFile)
	ON_BN_CLICKED(IDC_BUTTON_DELETE_FILE, OnButtonDeleteFile)
	ON_BN_CLICKED(IDC_BUTTON_CONVERT, OnButtonConvert)
	ON_WM_DESTROY()
	ON_NOTIFY(LVN_ITEMCHANGED, IDC_SQL_FILE_LIST, OnItemchangedSqlFileList)
	ON_WM_CLOSE()
	ON_BN_CLICKED(IDC_BUTTON_FEEDBACK, OnButtonFeedback)
	ON_NOTIFY(NM_DBLCLK, IDC_MSG_LIST, OnDblclkMsgList)
	//}}AFX_MSG_MAP
		ON_WM_DROPFILES()
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CSQLBig5BugToolDlg message handlers

BOOL CSQLBig5BugToolDlg::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
	
	m_imageList.Create(16,16,TRUE,2,2);
	m_imageList.Add(AfxGetApp()->LoadIcon(IDI_MY_LIST));//IDI_MY_LIST));
	
	m_listSQLFile.Init(IDI_MY_LIST);
	
	m_listMsg.Init(IDI_MY_LIST);
	
	UpdateUIStatus();

	LoadListSQLFile();
	
	HBITMAP hBitmap;
	BITMAP bitmap;
	HWND  hButton;
	hBitmap = ::LoadBitmap(AfxGetResourceHandle(),MAKEINTRESOURCE(IDB_FEEDBACK));
	hButton = ::GetDlgItem(GetSafeHwnd(),IDC_BUTTON_FEEDBACK);
	::GetObject(hBitmap,sizeof(BITMAP),&bitmap); //获取位图大小
	//设置按钮大小使之与位图大小合适
	::SetWindowPos(hButton,HWND_TOP,0,0,bitmap.bmWidth+2,bitmap.bmHeight+2,SWP_NOMOVE); 
	::SendMessage(hButton,BM_SETIMAGE,IMAGE_BITMAP,(LPARAM)hBitmap);   //设置位图
	
	
	FILE_VERSION_INFO	FileVersionInfo;
	
	GetVersionInfo(
		CMyLog::GetExeFilePath(),
		FileVersionInfo
		);
	
	CString strTitle;
	GetWindowText(strTitle);
	
	strTitle+=(" 版本: "+FileVersionInfo.strFileVersion+"").c_str();
	
	SetWindowText(strTitle);

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

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

void CSQLBig5BugToolDlg::OnButtonAddFile() 
{
	// TODO: Add your control notification handler code here
	UpdateData();
	
	char   szFilter[]   =   "SQL 文件 (*.sql)|*.sql||";  
	
	CFileDialog dlg(TRUE,"sql","*.sql",
		OFN_NOCHANGEDIR|OFN_FILEMUSTEXIST
		|OFN_NONETWORKBUTTON|OFN_READONLY|OFN_ALLOWMULTISELECT,
		szFilter
		);
	
	dlg.m_ofn.lpstrInitialDir=GetExeDir();
	dlg.m_ofn.lpstrTitle="选择需要转换的SQL文件";
	
	char szFileNames[64*1024]={0,};

	dlg.m_ofn.lpstrFile=szFileNames;
	dlg.m_ofn.nMaxFile=sizeof(szFileNames);
	
	
	if(dlg.DoModal()==IDOK)
	{ 
		POSITION   pos   =   dlg.GetStartPosition();   
		while   (pos   !=   NULL)   
		{   
			CString strFilePath=dlg.GetNextPathName(pos); 

			long lRow=m_listSQLFile.AddRow();

			m_listSQLFile.SetItemTextByName(lRow,COL_NAME_FILE_PATH,strFilePath);
		}   
		
		m_listSQLFile.AutoExpandAllColumn();
		
		UpdateUIStatus();
	}
}

void CSQLBig5BugToolDlg::OnButtonDeleteFile() 
{
	// TODO: Add your control notification handler code here
	UpdateData();
	
	m_listSQLFile.DeleteAllSelectedItems();

	UpdateUIStatus();
}

void CSQLBig5BugToolDlg::OnDropFiles(HDROP hDropInfo)
{
	// 初始化时 DragAcceptFiles();	
	CString str;
	const int nBufLen = 1024;
	LPTSTR pszBuf = str.GetBuffer(nBufLen);
	
	UINT unFileCount = ::DragQueryFile(hDropInfo, 0xFFFFFFFF, NULL, 0);
	
	for (UINT k = 0; k < unFileCount; ++k)
	{
		UINT unPathLen = ::DragQueryFile(hDropInfo, k, pszBuf, nBufLen << 1);
		
		str.MakeLower();
		if(str.Find(".sql")>0)
		{
			long lRow=m_listSQLFile.AddRow();
			
			m_listSQLFile.SetItemTextByName(lRow,COL_NAME_FILE_PATH,str);
		}
	}
	
	::DragFinish(hDropInfo);
	
	str.ReleaseBuffer();
	
	m_listSQLFile.AutoExpandAllColumn();
	
	CDialog::OnDropFiles(hDropInfo);
}


void CSQLBig5BugToolDlg::OnButtonConvert() 
{
	// TODO: Add your control notification handler code here
	UpdateData();
	AfxGetApp()->WriteProfileString("SQLBig5BugTool","DictFilePath",m_strDictFilePath);	
	
	m_listMsg.DeleteAllItems();
	
	if( (_access( m_strDictFilePath, 0 )) == -1 )
	{
		AfxMessageBox("字典文件不存在");
		return ;
	}
	
	STRING_LIST FilePathList;
	
	for(long l=0;l<m_listSQLFile.GetItemCount();l++)
	{
		CString strFile;
		m_listSQLFile.GetItemTextByName(l,COL_NAME_FILE_PATH,strFile);
		
		FilePathList.push_back((const char*)strFile);
	}

	CStdioFile fDict;
	if(!fDict.Open(m_strDictFilePath,CFile::modeRead|CFile::typeText|CFile::shareExclusive))
	{
		AfxMessageBox("字典文件无法打开");
		return;
	}

	STRING_LIST DictList;

	CString strTxt;
	while(fDict.ReadString(strTxt))
	{
		strTxt.TrimLeft();
		strTxt.TrimRight();
		if(strTxt.IsEmpty())
		{
			continue;
		}
		for(long l=0;l<strTxt.GetLength();l+=2)
		{
			CString strWord=strTxt.Mid(l,2);
			strWord.TrimLeft();
			strWord.TrimRight();
			if(strWord.IsEmpty())
			{
				continue;
			}

			DictList.push_back((const char*)strWord);
		}
	}
	fDict.Close();

	if(DictList.size()<1)
	{
		AfxMessageBox("字典文件为空");
		return;
	}
	
	for(l=0;l<FilePathList.size();l++)
	{
		ReplaceSQLFileWithDict(FilePathList[l].c_str(),DictList);
	}

	AfxMessageBox("替换结束");
}

void CSQLBig5BugToolDlg::ReplaceSQLFileWithDict(
												CString			strSQLFilePath,
												STRING_LIST&	DictList
												)
{
	CStdioFile fSQL;
	if(!fSQL.Open(strSQLFilePath,CFile::modeRead|CFile::typeText|CFile::shareExclusive))
	{
		AfxMessageBox("SQL文件无法打开:"+strSQLFilePath);
		return;
	}
	CStringArray saSQL;

	CString strSQL;
	while(fSQL.ReadString(strSQL))
	{		
		if(!strSQL.IsEmpty())
		{
			for(long l=0;l<DictList.size();l++)
			{
				strSQL.Replace(DictList[l].c_str(),(DictList[l]+"\\").c_str());
			}
		}

		saSQL.Add(strSQL);
	}
	fSQL.Close();

	//
	CString strSQLFilePathNew=strSQLFilePath;
	strSQLFilePathNew.Replace(".sql","_ForBig5.sql");
	
	if(!fSQL.Open(strSQLFilePathNew,CFile::modeCreate|CFile::modeWrite|CFile::typeText|CFile::shareExclusive))
	{
		AfxMessageBox("SQL文件无法写:"+strSQLFilePathNew);
		return;
	}

	for(long l=0;l<saSQL.GetSize();l++)
	{
		CString strSQLNew=saSQL[l];

		fSQL.WriteString(strSQLNew);

		if(strSQLNew.Find("\\'")>0)
		{
			long lRow=m_listMsg.AddRow();

			m_listMsg.SetItemTextByName(lRow,"新SQL文件",strSQLFilePathNew);
			m_listMsg.SetItemTextByName(lRow,"行号",FormatString("%d",l+1).c_str());
			m_listMsg.SetItemTextByName(lRow,"警告",FormatString("转换后发现\\'",l).c_str());
		}		

		fSQL.WriteString("\n");
	}
	fSQL.Close();
}

void CSQLBig5BugToolDlg::UpdateUIStatus()
{
	BOOL bDictFileOK= TRUE;//(_access( m_strDictFilePath, 0 )) ==0 ;

	GetDlgItem(IDC_BUTTON_CONVERT)->EnableWindow((m_listSQLFile.GetItemCount()>0)&&bDictFileOK);
}

void CSQLBig5BugToolDlg::OnDestroy() 
{
	CDialog::OnDestroy();
	
	// TODO: Add your message handler code here	
	AfxGetApp()->WriteProfileString("SQLBig5BugTool","DictFilePath",m_strDictFilePath);	
}

void CSQLBig5BugToolDlg::OnItemchangedSqlFileList(NMHDR* pNMHDR, LRESULT* pResult) 
{
	NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
	// TODO: Add your control notification handler code here
	
	UpdateUIStatus();
	
	*pResult = 0;
}

void CSQLBig5BugToolDlg::LoadListSQLFile()
{
	CString strIni;

	strIni.Format("%s\\SQLBig5BugTool.ini",GetExeDir());
	
	STRING_LIST FilePathList;

	DWORD dwCount=GetPrivateProfileInt("ListSQLFile","Count",0,strIni);
	for(long l=0;l<dwCount;l++)
	{
		char szTxt[1024]={0,};

		GetPrivateProfileString("ListSQLFile",FormatString("File%d",l).c_str(),"",szTxt,sizeof(szTxt),strIni);	

		FilePathList.push_back(szTxt);
	}

	m_listSQLFile.AddColumnText(COL_NAME_FILE_PATH,FilePathList,TRUE);


	m_listSQLFile.AutoExpandAllColumn();
}

void CSQLBig5BugToolDlg::SaveListSQLFile()
{
	CString strIni;
	strIni.Format("%s\\SQLBig5BugTool.ini",GetExeDir());

	DeleteFile(strIni);

	STRING_LIST FilePathList;
	m_listSQLFile.GetColumnText(COL_NAME_FILE_PATH,FilePathList);

	if(FilePathList.size()>0)
	{
		WritePrivateProfileString("ListSQLFile","Count",FormatString("%d",FilePathList.size()).c_str(),strIni);

		for(long l=0;l<FilePathList.size();l++)
		{
			WritePrivateProfileString("ListSQLFile",FormatString("File%d",l).c_str(),FilePathList[l].c_str(),strIni);			
		}
	}
}

void CSQLBig5BugToolDlg::OnClose() 
{
	// TODO: Add your message handler code here and/or call default
	UpdateData();

	SaveListSQLFile();
	
	AfxGetApp()->WriteProfileString("SQLBig5BugTool","DictFilePath",m_strDictFilePath);	
	
	CDialog::OnClose();
}

void CSQLBig5BugToolDlg::OnButtonFeedback() 
{
	// TODO: Add your control notification handler code here
	
	//
	char szTxt[1024]={0,};
	
	szTxt[0]=0;
	GetPrivateProfileString(
		"Setting",
		"LinkURL",
		"http://192.168.2.171/newthread.php?...ad&forumid=4673",
		szTxt,
		sizeof(szTxt),
		"SQLBig5BugTool.ini"
		);
	
	//
	int   iRet   =   (int)ShellExecute(   NULL,   _T("open"),   szTxt,   NULL,   NULL,   SW_SHOW   );   
	if(   iRet   <=   HINSTANCE_ERROR   )   
	{
		AfxMessageBox("无法打开链接:"+(CString)szTxt);
	}	
}

void CSQLBig5BugToolDlg::OnDblclkMsgList(NMHDR* pNMHDR, LRESULT* pResult) 
{
	// TODO: Add your control notification handler code here
	
	POSITION pos=m_listMsg.GetFirstSelectedItemPosition();
	if(pos)
	{
		int nItem=m_listMsg.GetNextSelectedItem(pos);

		CString strLineNumber;
		CString strNewSQLFile;		
		
		m_listMsg.GetItemTextByName(nItem,"新SQL文件",strNewSQLFile);
		
		m_listMsg.GetItemTextByName(nItem,"行号",strLineNumber);
		
		if(!strLineNumber.IsEmpty())
		{
			OpenFileAndAutoLocate(strNewSQLFile,atol(strLineNumber),0,GetSafeHwnd());
		}
	}

	//

	*pResult = 0;
}

⌨️ 快捷键说明

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