📄 makelibdlg.cpp
字号:
// MakeLibDlg.cpp : implementation file
//
#include "stdafx.h"
#include "MakeLib.h"
#include "MakeLibDlg.h"
#include <direct.h> // chdor()
#include "afxtempl.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
WORD TranCode(WORD);
void GetGB2312Count(CStringArray * pArray);
CString StringFiltter(CString);
char * StringFiltter(char *);
UINT WordThreadProcess( LPVOID lpVoid);
/////////////////////////////////////////////////////////////////////////////
// CMakeLibDlg dialog
CMakeLibDlg::CMakeLibDlg(CWnd* pParent /*=NULL*/)
: CDialog(CMakeLibDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CMakeLibDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CMakeLibDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CMakeLibDlg)
DDX_Control(pDX, IDC_STATIC_HINT, m_Hint);
DDX_Control(pDX, IDC_PROGRESS1, m_Prog);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CMakeLibDlg, CDialog)
//{{AFX_MSG_MAP(CMakeLibDlg)
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTON_BROWSE, OnButtonBrowse)
ON_BN_CLICKED(IDC_BUTTON_BWBROWS_FILE, OnButtonBwbrowsFile)
ON_BN_CLICKED(IDC_BUTTON_RESTORE, OnButtonRestore)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMakeLibDlg message handlers
BOOL CMakeLibDlg::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
// TODO: Add extra initialization here
memset((void*) &ti, 0, sizeof(THRAD_INFOR));
lpti = &ti;
return TRUE; // return TRUE unless you set the focus to a control
}
// 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 CMakeLibDlg::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 CMakeLibDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CMakeLibDlg::OnButtonBrowse()
{
BROWSEINFO bi;
TCHAR szDisplayName[MAX_PATH] = {'\0'};
LPITEMIDLIST pidl;
LPMALLOC pMalloc = NULL;
ZeroMemory(&bi, sizeof(BROWSEINFO));
bi.hwndOwner = GetSafeHwnd();
bi.pszDisplayName = szDisplayName;
bi.lpszTitle = TEXT("选择文件夹!");
bi.ulFlags = BIF_RETURNONLYFSDIRS;
pidl = SHBrowseForFolder(&bi);
if(pidl)
{
SHGetPathFromIDList(pidl, szDisplayName);
SetDlgItemText(IDC_EDIT_FOLDER, szDisplayName);
}
if (SHGetMalloc(&pMalloc) == NOERROR)
pMalloc->Free((void *)pidl);
}
void CMakeLibDlg::OnOK()
{
GetDlgItemText(IDC_EDIT_FOLDER, strFolder);
GetDlgItemText(IDC_EDIT_OUT, strStdFile);
if( strFolder.IsEmpty() ) return ;
if( strStdFile.IsEmpty() ) return ;
lpti->lpFolderPath = (LPCTSTR) strFolder;
lpti->lpStdFileName = (LPCTSTR) strStdFile;
lpti->pParent = this;
lpti->pProg = &m_Prog;
AfxBeginThread(WordThreadProcess, lpti);
}
UINT WordThreadProcess( LPVOID lpVoid)
{
LPTHRAD_INFOR lpti = ( LPTHRAD_INFOR ) lpVoid;
CStringArray array;
FindWordFile( CString( lpti->lpFolderPath), &array);
CStringArray arrWord;
GetGB2312Count( & arrWord);
int i=0,k=0,j=0, size = arrWord.GetSize();
LPINDEX_ONE pOne = new INDEX_ONE [ size ];
ZeroMemory( pOne, sizeof( INDEX_ONE ) * size);
for( i=0;i<size;i++)
{
CString str = arrWord.GetAt(i);
BYTE h = str.GetAt(0);
BYTE l = str.GetAt(1);
WORD w = MAKEWORD(l, h);
(*(pOne+i)).w = w;
}
BYTE b1=0,b2=0 ;
CString strLine;
int FileCount = array.GetSize();
int WordCount = arrWord.GetSize();
CStdioFile file;
HEAD_INFOR head;
memset((void*) &head, 0, sizeof(HEAD_INFOR));
memcpy((void*)head.Flag, (const BYTE *) "WWWW", 4);
head.Unit[0] = 0xC055;
head.Unit[0] = 0xC055;
head.Unit[0] = 0xC055;
head.Unit[0] = 0xC055;
head.size = size;
CFile fout;
fout.Open(lpti->lpStdFileName, CFile::modeCreate|CFile::modeWrite|CFile::typeBinary);
fout.Write((void*) &head, sizeof(HEAD_INFOR));
fout.Seek( sizeof(HEAD_INFOR) + sizeof(INDEX_ONE) * WordCount, CFile::begin);
lpti->pProg->SetRange32(0, WordCount);
lpti->pProg->SetStep(1);
lpti->pProg->SetPos(0);
for(i=0;i< WordCount;i++)
{
for(k=0; k<FileCount; k++)
{
CString str = array.GetAt(k);
file.Open((LPCTSTR) str, CFile::modeRead);
UINT len =0;
file.ReadString(strLine);
file.ReadString(strLine);
strLine.TrimLeft();
strLine.TrimRight();
len = strLine.GetLength();
switch(len)
{
case 4:
(*(pOne+i)).FirstOffset2 = fout.GetPosition();
break;
case 6:
(*(pOne+i)).FirstOffset3 = fout.GetPosition();
break;
case 8:
(*(pOne+i)).FirstOffset4 = fout.GetPosition();
break;
}
file.SeekToBegin();
while( file.ReadString(strLine) )
{
b1 = (BYTE) strLine.GetAt(0);
b2 = (BYTE) strLine.GetAt(1);
WORD w2 = MAKEWORD(b2, b1);
if (w2 == (*(pOne+i)).w )
{
strLine = strLine;
fout.Write((void*) (LPCTSTR) strLine, strLine.GetLength() );
if(len == 4) (*(pOne+i)).Num2 ++;
if(len == 6) (*(pOne+i)).Num3 ++;
if(len == 8) (*(pOne+i)).Num4 ++;
}
strLine.Empty();
}
file.Close();
}
lpti->pProg->SetPos(i);
}
fout.Seek( sizeof(HEAD_INFOR), CFile::begin);
for(i=0;i< WordCount;i++)
{
fout.Write((void*) (pOne+i), sizeof(INDEX_ONE) );
}
if (pOne) delete[] pOne;
fout.Close();
lpti->pProg->SetPos(0);
AfxMessageBox("OK");
return 1;
}
void CMakeLibDlg::OnButtonBwbrowsFile()
{
// TODO: Add your control notification handler code here
CFileDialog dlg(FALSE);
if( dlg.DoModal() == IDCANCEL ) return ;
SetDlgItemText(IDC_EDIT_OUT, (LPCTSTR)dlg.GetPathName() );
}
WORD TranCode( WORD w)
{
BYTE h = HIBYTE(w);
BYTE l = LOBYTE(w);
return (WORD) MAKEWORD(h, l);
}
void GetGB2312Count(CStringArray * pArray)
{
TCHAR szW[3] = {'\0'};
BYTE i = 0x00, k=0x00;
BOOL Flag = FALSE;
for( i = 0xb0; i<0xff; i++)
{
for(k=0xa1; k<0xff; k++)
{
szW[0] = i;
szW[1] = k;
szW[2] ='\0';
pArray->Add (CString (szW));
WORD w = MAKEWORD(k, i);
if( w == 0xf7fe)
{
Flag = TRUE;
}
}
if(Flag == TRUE) break;
}
}
void CMakeLibDlg::OnButtonRestore()
{
CArray <INDEX_ONE, INDEX_ONE &> arr;
CFile fw;
CFile fr;
fr.Open("d:\\out.dat", CFile::modeRead|CFile::typeBinary);
fw.Open("d:\\out.txt", CFile::modeCreate|CFile::modeWrite);
UINT i=0, x=0, y=0, z=0;
HEAD_INFOR head;
INDEX_ONE one;
memset((void*) &head, 0, sizeof(HEAD_INFOR));
fr.Read((void*) &head, sizeof(HEAD_INFOR));
for(i=0;i< head.size ; i++)
{
memset((void*) &one, 0, sizeof(INDEX_ONE));
fr.Read((void*) &one, sizeof(INDEX_ONE));
arr.Add(one);
}
fr.SeekToBegin();
BYTE b4 [4] = {0};
BYTE b6 [6] = {0};
BYTE b8 [8] = {0};
BYTE kg = 0x20;
WORD hh= 0x0a0d;
for( i=0; i< head.size ; i++)
{
memset((void*) &one, 0, sizeof(INDEX_ONE));
one = arr.GetAt(i);
fr.Seek(one.FirstOffset2, CFile::begin) ;
for(x=0;x<one.Num2 ;x++)
{
fr.Read((void*) b4, sizeof(BYTE)*4);
fw.Write((void*) b4, sizeof(BYTE)*4);
fw.Write((void*) &kg, sizeof(BYTE));
}
fr.Seek(one.FirstOffset3, CFile::begin) ;
for(y=0;y<one.Num3 ;y++)
{
fr.Read((void*) b6, sizeof(BYTE)*6);
fw.Write((void*) b6, sizeof(BYTE)*6);
fw.Write((void*) &kg, sizeof(BYTE));
}
fr.Seek(one.FirstOffset4, CFile::begin) ;
for(z=0;z<one.Num4 ;z++)
{
fr.Read((void*) b8, sizeof(BYTE)*8);
fw.Write((void*) b8, sizeof(BYTE)*8);
fw.Write((void*) &kg, sizeof(BYTE));
}
fw.Write((void*) &hh, sizeof(WORD));
}
fw.Close();
fr.Close();
AfxMessageBox("OK");
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -