📄 new.cpp
字号:
// New.cpp : implementation file
//
#include "stdafx.h"
#include "TestZnPDFLibrarianDLL.h"
#include "New.h"
#include "SearchStatus.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
CString m_IndexPath;//索引路径
/////////////////////////////////////////////////////////////////////////////
// CNew dialog
CNew::CNew(CWnd* pParent /*=NULL*/)
: CDialog(CNew::IDD, pParent)
{
//{{AFX_DATA_INIT(CNew)
m_indexTitle = _T("");
m_ExcludeFile = _T("");
m_IncludeFile = _T("");
m_CustomField = _T("");
m_StopWord = _T("");
m_WordFinderVersion = 0;
m_indexDescription = _T("");
m_EnumCustomFieldType = CFT_CustomStringField;
//}}AFX_DATA_INIT
m_pMainDlg = ( CTestZnPDFLibrarianDLLDlg* )pParent ;
}
void CNew::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CNew)
DDX_Control(pDX, IDC_LIST2, m_listCustomField);
DDX_Control(pDX, IDC_LIST1, m_ListStopWord);
DDX_Control(pDX, IDC_COMBO1, m_CustomFieldType);
DDX_Text(pDX, IDC_EDIT1, m_indexTitle);
DDX_Text(pDX, IDC_EDIT6, m_ExcludeFile);
DDX_Text(pDX, IDC_EDIT4, m_IncludeFile);
DDX_Text(pDX, IDC_EDIT7, m_CustomField);
DDX_Text(pDX, IDC_EDIT8, m_StopWord);
DDX_Text(pDX, IDC_EDIT2, m_WordFinderVersion);
DDX_Text(pDX, IDC_EDIT3, m_indexDescription);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CNew, CDialog)
//{{AFX_MSG_MAP(CNew)
ON_BN_CLICKED(IDC_BUTTON3, OnBuild)
ON_BN_CLICKED(IDC_BUTTON8, OnRebuild)
ON_BN_CLICKED(IDC_BUTTON10, OnPurge)
ON_BN_CLICKED(IDC_BUTTON2, OnIncludeFile)
ON_BN_CLICKED(IDC_BUTTON5, OnExcludeFile)
ON_BN_CLICKED(IDC_BUTTON6, OnCustomField)
ON_BN_CLICKED(IDC_BUTTON7, OnAddStopWord)
ON_BN_CLICKED(IDC_BUTTON9, OnAdd)
ON_CBN_SELCHANGE(IDC_COMBO1, OnSelchangeCombo1)
ON_WM_TIMER()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CNew message handlers
void CNew::OnBuild()
{
// TODO: Add your control notification handler code here
CFileDialog Indexfile( FALSE, _T("ZPI"), NULL, OFN_FILEMUSTEXIST|OFN_OVERWRITEPROMPT, _T("ZPI Files (*.zpi)|*.zpi||") ) ;
if( Indexfile.DoModal() == IDOK )
{
m_IndexPath = Indexfile.GetPathName();
//m_pPDFIndex->BuildIndex(_bstr_t("M:\\PDF\\a.zpi"));
//return;
CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)ThreadProc,(LPVOID)this,0,0);
//m_pPDFIndex->BuildIndex( Indexfile.GetPathName().AllocSysString() );
CSearchStatus dlg(this);
// m_time = SetTimer(1,200,0);
dlg.DoModal();
// KillTimer(1);
}
}
void CNew::OnRebuild()
{
// TODO: Add your control notification handler code here
if(m_IndexPath.IsEmpty())
{
m_pPDFIndex->RebuildIndex( m_IndexPath.AllocSysString() );
}
}
void CNew::OnPurge()
{
// TODO: Add your control notification handler code here
//Abort index Build.
VARIANT_BOOL bBuild;
m_pPDFIndex->IsBuilding( &bBuild );
if( bBuild )
m_pPDFIndex->AbortBuilding();
if(!m_IndexPath.IsEmpty())
{
m_pPDFIndex->PurgeIndex( m_IndexPath.AllocSysString() );
}
}
void CNew::OnIncludeFile()
{
// TODO: Add your control notification handler code here
// CFileDialog pdffile( TRUE, _T("PDF"), NULL, OFN_FILEMUSTEXIST|OFN_OVERWRITEPROMPT, _T("PDF Files (*.pdf)|*.pdf||") ) ;//,Indexfile(false,);//,Indexfile(false,);
_bstr_t indname;
char szPath[MAX_PATH];
// if(pdffile.DoModal() == IDOK)
// {
if(!SelDir(szPath))
return;
m_ZIncludeFile = szPath;
// m_ZIncludeFile = "M:\\SearchSource";
m_pPDFIndex->AddIncludeFile(m_ZIncludeFile.AllocSysString(),VARIANT_TRUE);
VARIANT vr ;
m_pPDFIndex->GetIncludeFileArray(VARIANT_TRUE,&vr);
ASSERT( V_VT(&vr) == (VT_ARRAY|VT_VARIANT) ) ;
SAFEARRAY *pArray = V_ARRAY(&vr);
long lBound, uBound ;
SafeArrayGetLBound( pArray, 1, &lBound ) ;
SafeArrayGetUBound( pArray, 1, &uBound ) ;
m_pMainDlg->m_IncludeFile.InsertItem(3,"IncludeFile");
for (long i=lBound; i<=uBound; ++i)
{
VARIANT vrr ;
SafeArrayGetElement( pArray, &i, &vrr ) ;
ASSERT( V_VT(&vrr) == VT_BSTR ) ;
indname = vrr ;
m_pMainDlg->m_IncludeFile.InsertItem((i+4),_com_util::ConvertBSTRToString(indname));
}
UpdateData(false);
// }
}
void CNew::OnExcludeFile()
{
// TODO: Add your control notification handler code here
// CFileDialog Indexfile( FALSE, _T("ZPI"), NULL, OFN_FILEMUSTEXIST|OFN_OVERWRITEPROMPT, _T("ZPI Files (*.zpi)|*.zpi||") ) ;
CFileDialog pdffile( TRUE, _T("PDF"), NULL, OFN_FILEMUSTEXIST|OFN_OVERWRITEPROMPT, _T("PDF Files (*.pdf)|*.pdf||") ) ;//,Indexfile(false,);
_bstr_t indname;
if(pdffile.DoModal() == IDOK)
{
m_ZExcludeFile = m_ExcludeFile = pdffile.GetPathName();
m_pPDFIndex->AddExcludeFile(m_ZExcludeFile.AllocSysString(),VARIANT_TRUE);
VARIANT vr ,includevr;
m_pPDFIndex->GetExcludeFileArray(VARIANT_TRUE,&includevr);
ASSERT( V_VT(&includevr) == (VT_ARRAY|VT_VARIANT) ) ;
SAFEARRAY *pincludeArray = V_ARRAY(&includevr);
long lincludeBound, uincludeBound ;
SafeArrayGetLBound( pincludeArray, 1, &lincludeBound ) ;
SafeArrayGetUBound( pincludeArray, 1, &uincludeBound ) ;
m_pPDFIndex->GetExcludeFileArray(VARIANT_TRUE,&vr);
ASSERT( V_VT(&vr) == (VT_ARRAY|VT_VARIANT) ) ;
SAFEARRAY *pArray = V_ARRAY(&vr);
long lBound, uBound ;
SafeArrayGetLBound( pArray, 1, &lBound ) ;
SafeArrayGetUBound( pArray, 1, &uBound ) ;
m_pMainDlg->m_IncludeFile.InsertItem((4 +uBound) ,"ExCludeFile");
for (long i=lBound; i<=uBound; ++i)
{
VARIANT vrr ;
SafeArrayGetElement( pArray, &i, &vrr ) ;
ASSERT( V_VT(&vrr) == VT_BSTR ) ;
indname = vrr ;
m_pMainDlg->m_IncludeFile.InsertItem((i+(5 +uBound)),_com_util::ConvertBSTRToString(indname));
}
UpdateData(false);
}
}
void CNew::OnCustomField()
{
// TODO: Add your control notification handler code here
UpdateData(true);
// ZPL_CustomFieldType TempCustomFieldType;
//
// switch() {
// case :
// break;
// case :
// break;
// default:
// }
// TempCustomFieldType = CFT_CustomStringField ;
if( !m_CustomField.IsEmpty() )
{
// m_ZStopWord = m_CustomField;
VARIANT vr;
VariantInit(&vr);
_bstr_t CustomField;
m_listCustomField.DeleteAllItems();
m_pPDFIndex->AddCustomField(m_EnumCustomFieldType,m_CustomField.AllocSysString());
m_pPDFIndex->GetCustomFieldArray(m_EnumCustomFieldType,&vr );
_ASSERT(V_VT(&vr) == ( VT_ARRAY|VT_VARIANT ));
SAFEARRAY *pArray = V_ARRAY(&vr);
long lBound, uBound ;
SafeArrayGetLBound( pArray, 1, &lBound ) ;
SafeArrayGetUBound( pArray, 1, &uBound ) ;
// m_pMainDlg->m_IncludeFile.InsertItem(3,"IncludeFile");
for (long i=lBound; i<=uBound; ++i)
{
VARIANT vrr ;
SafeArrayGetElement( pArray, &i, &vrr ) ;
ASSERT( V_VT(&vrr) == VT_BSTR ) ;
CustomField = vrr ;
m_listCustomField.InsertItem(i,_com_util::ConvertBSTRToString(CustomField));
}
UpdateData( false );
}
}
void CNew::OnAddStopWord()
{
// TODO: Add your control notification handler code here
UpdateData(true);
if( !m_StopWord.IsEmpty() )
{
m_ZStopWord = m_StopWord;
VARIANT vr;
_bstr_t stopword;
m_ListStopWord.DeleteAllItems();
m_pPDFIndex->AddStopWord( m_StopWord.AllocSysString() );
m_pPDFIndex->GetStopWordsArray(&vr );
_ASSERT(V_VT(&vr) == ( VT_ARRAY|VT_VARIANT ));
SAFEARRAY *pArray = V_ARRAY(&vr);
long lBound, uBound ;
SafeArrayGetLBound( pArray, 1, &lBound ) ;
SafeArrayGetUBound( pArray, 1, &uBound ) ;
// m_pMainDlg->m_IncludeFile.InsertItem(3,"IncludeFile");
for (long i=lBound; i<=uBound; ++i)
{
VARIANT vrr ;
SafeArrayGetElement( pArray, &i, &vrr ) ;
ASSERT( V_VT(&vrr) == VT_BSTR ) ;
stopword = vrr ;
m_ListStopWord.InsertItem(i,_com_util::ConvertBSTRToString(stopword));
}
UpdateData( false );
}
}
void CNew::OnAdd()
{
// TODO: Add your control notification handler code here
BSTR indexTitle,indexDescription;
long WordFinderVersion;
int itemp;
char * temp;
CString StrindexTitle("IndexTitle:"),StrindexDescription("IndexDescription:"),StrWordFinderVersion("WordFinderVersion:");
temp = new char(100);
UpdateData(true);
m_pPDFIndex->put_indexTitle( m_indexTitle.AllocSysString() );
m_pPDFIndex->put_indexDescription( m_indexDescription.AllocSysString());
m_pPDFIndex->put_wordFinderVersion( m_WordFinderVersion );
m_pPDFIndex->get_indexTitle(&indexTitle);
m_pPDFIndex->get_indexDescription(&indexDescription);
m_pPDFIndex->get_wordFinderVersion(&WordFinderVersion);
itemp = WordFinderVersion;
itoa(itemp,temp,10);
StrindexTitle +=_com_util::ConvertBSTRToString(indexTitle);
StrindexDescription += _com_util::ConvertBSTRToString(indexDescription);
StrWordFinderVersion += temp;
m_pMainDlg->m_IncludeFile.InsertItem(0, StrindexTitle);
m_pMainDlg->m_IncludeFile.InsertItem(1, StrindexDescription);
m_pMainDlg->m_IncludeFile.InsertItem(2, StrWordFinderVersion);
}
BOOL CNew::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
CoInitialize(NULL);
try
{
m_pPDFLibrarian.CreateInstance(CLSID_PDFLibrarian);
}
catch (_com_error e)
{
AfxMessageBox( e.Description() );
}
m_pPDFLibrarian->Initialize(_bstr_t(""),0);
try
{
m_pPDFLibrarian->CreateSearchInterface((IDispatch **)&m_pPDFSearch);//->CreateSearchInterface((IDispatch **)m_pPDFSearch);
m_pPDFLibrarian->CreateIndexInterface((IDispatch **)&m_pPDFIndex);//CreateIndexInterface((IDispatch **)m_pPDFIndex);
// m_pPDFLibrarian->QueryInterface(DIID__IPDFSearchEvents,(void**)&m_pPDFSearchEvents);
}
catch(_com_error e)
{
AfxMessageBox(e.Description());
}
m_CustomFieldType.SetCurSel(0);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CNew::OnSelchangeCombo1()
{
// TODO: Add your control notification handler code here
int cursel = m_CustomFieldType.GetCurSel();
switch( cursel )
{
case 0:
m_EnumCustomFieldType = CFT_CustomStringField ;
break;
case 1:
m_EnumCustomFieldType = CFT_CustomIntField ;
break;
case 2:
m_EnumCustomFieldType = CFT_CustomDateField ;
break;
}
}
void CNew::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
//UpdateData(false);
CDialog::OnTimer(nIDEvent);
}
DWORD CNew::ThreadProc(LPVOID lpParameter)
{
CoInitialize(NULL) ;
CNew *pNewDlg = (CNew*)lpParameter ;//pNewDlg
pNewDlg->m_pPDFIndex->BuildIndex( m_IndexPath.AllocSysString());/*_bstr_t("M:\\PDF\\a.zpi"));*/
return 0;
}
BOOL CNew::SelDir(char szPath[])
{
UpdateData(true);
LPMALLOC pMalloc ;
if (!SUCCEEDED(SHGetMalloc(&pMalloc)))
return FALSE ;
BROWSEINFO info = {0} ;
info.hwndOwner = m_hWnd ;
info.ulFlags = BIF_RETURNONLYFSDIRS ;
LPITEMIDLIST lpList = SHBrowseForFolder( &info ) ;
SHGetPathFromIDList( lpList, szPath ) ;
m_IncludeFile = szPath;
pMalloc->Free( lpList ) ;
UpdateData(false);
return TRUE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -