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

📄 testznpdflibrariandlldlg.cpp

📁 i am server im imi mim im im
💻 CPP
字号:
// TestZnPDFLibrarianDLLDlg.cpp : implementation file
//

#include "stdafx.h"
#include "TestZnPDFLibrarianDLL.h"
#include "TestZnPDFLibrarianDLLDlg.h"
#include "Eventhandler.h"
#include "SearchStatus.h"
#include "new.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
char szPath[MAX_PATH];
/////////////////////////////////////////////////////////////////////////////
// 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()

/////////////////////////////////////////////////////////////////////////////
// CTestZnPDFLibrarianDLLDlg dialog

CTestZnPDFLibrarianDLLDlg::CTestZnPDFLibrarianDLLDlg(CWnd* pParent /*=NULL*/)
: CDialog(CTestZnPDFLibrarianDLLDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CTestZnPDFLibrarianDLLDlg)
	k = 0;
	m_matchcaseV = FALSE;
	m_wholewordV = FALSE;
	m_QueryBookmarkV = FALSE;
	m_QueryCommentV = FALSE;
	m_phrase = _T("");
	m_IndexFilePath = _T("");
	m_records = 0;
	m_Stemming = FALSE;
	m_QueryTypev = SQT_ExactPhrase ;
	
	m_CriteriaValue = _T("");
	InitKeyCriteria = "Author";
	m_BKeyCriteria = InitKeyCriteria.AllocSysString();
	m_EnumMetaDataOP = OP_Less;
	m_StrMetaDataOP = "Less";
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CTestZnPDFLibrarianDLLDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CTestZnPDFLibrarianDLLDlg)
	DDX_Control(pDX, IDC_EDIT4, m_cRecords);
	DDX_Control(pDX, IDC_COMBO2, m_KeyCriteria);
	DDX_Control(pDX, IDC_COMBO3, m_MetaDataOP);
	DDX_Control(pDX, IDC_LIST3, m_IncludeFile);
	DDX_Control(pDX, IDC_COMBO1, m_QueryType);
	DDX_Control(pDX, IDC_LIST2, m_Criteria);
	DDX_Control(pDX, IDC_LIST1, m_result);
	DDX_Control(pDX, IDC_CHECK1, m_wholewordC);
	DDX_Check(pDX, IDC_CHECK2, m_matchcaseV);
	DDX_Check(pDX, IDC_CHECK1, m_wholewordV);
	DDX_Check(pDX, IDC_CHECK3, m_QueryBookmarkV);
	DDX_Check(pDX, IDC_CHECK4, m_QueryCommentV);
	DDX_Text(pDX, IDC_EDIT1, m_phrase);
	DDX_Text(pDX, IDC_EDIT2, m_IndexFilePath);
	DDX_Text(pDX, IDC_EDIT4, m_records);
	DDX_Check(pDX, IDC_CHECK5, m_Stemming);
	DDX_Text(pDX, IDC_EDIT5, m_CriteriaValue);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CTestZnPDFLibrarianDLLDlg, CDialog)
//{{AFX_MSG_MAP(CTestZnPDFLibrarianDLLDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTON4, OnIndex)
ON_BN_CLICKED(IDC_BUTTON2, OnAddCriteria)
ON_BN_CLICKED(IDC_BUTTON1, OnSearch)
ON_BN_CLICKED(IDC_CHECK1, OnCheck1)
ON_CBN_EDITCHANGE(IDC_COMBO1, OnEditchangeCombo1)
ON_CBN_SELCHANGE(IDC_COMBO1, OnSelchangeCombo1)
ON_CBN_SELCHANGE(IDC_COMBO2, OnSelchangeCombo2)
ON_CBN_SELCHANGE(IDC_COMBO3, OnSelchangeCombo3)
ON_WM_TIMER()
ON_BN_CLICKED(IDC_BUTTON3, OnBeep)
ON_BN_CLICKED(IDC_BUTTON5, OnKillTimer)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CTestZnPDFLibrarianDLLDlg message handlers

BOOL CTestZnPDFLibrarianDLLDlg::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
	CoInitialize(NULL);
	try
	{
		
		m_pPDFLibrarian.CreateInstance(CLSID_PDFLibrarian);
		m_pPDFLibrarian->Initialize(_bstr_t(""),0);
	}
	catch (_com_error e)
	{
		AfxMessageBox( e.Description() );
	}
	try
	{
		
		m_pPDFLibrarian->CreateSearchInterface((IDispatch **)&m_pPDFSearch);//->CreateSearchInterface((IDispatch **)m_pPDFSearch);
		m_pPDFLibrarian->CreateIndexInterface((IDispatch **)&m_pPDFIndex);//CreateIndexInterface((IDispatch **)m_pPDFIndex);	
		
		
	}
	catch(_com_error e)
	{
		AfxMessageBox(e.Description());
	}
	m_result.SetExtendedStyle( m_result.GetExtendedStyle() | LVS_EX_FULLROWSELECT ) ;
	m_result.InsertColumn( 0, _T("File path."), LVCFMT_LEFT, 130) ;
	m_result.InsertColumn( 1, _T("Page_No"), LVCFMT_LEFT, 72 ) ;
	m_result.InsertColumn( 2, _T("Word_No"), LVCFMT_LEFT, 72) ;
	m_result.InsertColumn( 3, _T("Word_Num"), LVCFMT_LEFT, 85 ) ;
	m_result.InsertColumn( 4, _T("ArPos"), LVCFMT_LEFT, 72 ) ;
	m_result.InsertColumn( 5, _T("Annot_No"), LVCFMT_LEFT, 85 ) ;
	
	
	HFONT font = CreateFont( -14, 0, 0, 0, 400, 0, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 0, _T("Microsoft Sans Serif") ) ;
	m_result.SetFont( CFont::FromHandle(font) ) ;
	
	m_Criteria.SetExtendedStyle( m_Criteria.GetExtendedStyle() | LVS_EX_FULLROWSELECT ) ;
	m_Criteria.InsertColumn( 0, _T("Criteria"), LVCFMT_LEFT, 120 ) ;
	m_Criteria.InsertColumn( 1, _T("MetaData"), LVCFMT_LEFT, 120 ) ;
	m_Criteria.InsertColumn( 2, _T("value"), LVCFMT_LEFT, 120 ) ;
	

	m_Criteria.SetFont( CFont::FromHandle(font) ) ;
	
	m_QueryType.SetCurSel(0);
	m_KeyCriteria.SetCurSel(0);
	m_MetaDataOP.SetCurSel(0);
	UpdateData(true);
	
	
	//	time
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

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

void CTestZnPDFLibrarianDLLDlg::OnButton3() 
{
	// TODO: Add your control notification handler code here
	
}

void CTestZnPDFLibrarianDLLDlg::OnIndex() 
{
	// TODO: Add your control notification handler code here
	//TRACE0 (format string (only) be used for simple text message which are dumped to AfxDump)
	TRACE0("1235456566");
	CNew indexdlg( this );
	indexdlg.DoModal() ;
}

void CTestZnPDFLibrarianDLLDlg::OnAddCriteria() 
{
	// TODO: Add your control notification handler code here
	UpdateData(true);
	if(!m_CriteriaValue.IsEmpty())
	{
		
		m_pPDFSearch->AddCriteria(m_BKeyCriteria ,m_EnumMetaDataOP ,m_CriteriaValue.AllocSysString() );
		m_Criteria.InsertItem(k,_com_util::ConvertBSTRToString(m_BKeyCriteria));
		m_Criteria.SetItemText( k , 1 , m_StrMetaDataOP );
		m_Criteria.SetItemText(k,2,m_CriteriaValue);
		UpdateData(false);
		k++;	
	}
}

void CTestZnPDFLibrarianDLLDlg::OnSearch() 
{
	// TODO: Add your control notification handler code here
	
	
	UpdateData(TRUE);
	DWORD dTimeOut = 10;
	UpdateData(false);
	
	if( m_phrase.IsEmpty() )
	{
		AfxMessageBox("Phrase is empty,please fill in  phrase! otherwise you will be death!!!!");
		
	}
	else
	{
		m_result.DeleteAllItems();
		m_IncludeFile.DeleteAllItems();
		m_Criteria.DeleteAllItems();
		m_pPDFSearch->SetOption(m_QueryTypev,m_wholewordV,m_matchcaseV,m_Stemming,m_QueryBookmarkV,m_QueryCommentV);
		
		CFileDialog filedlg( TRUE, _T("ZPI"), NULL, OFN_FILEMUSTEXIST|OFN_OVERWRITEPROMPT, _T("ZPI Files (*.zpi)|*.zpi||") ) ;
		
		if( filedlg.DoModal() == IDOK )
		{
			m_indexfilepath	= filedlg.GetPathName().AllocSysString();
			
			m_result.DeleteAllItems();
			m_records = 0 ;
			HANDLE hSearch = CreateThread( NULL, 0,(LPTHREAD_START_ROUTINE)ThreadProc,(LPVOID )this,0,0);
			
			WaitForSingleObject( hSearch , 10 );
			int n = m_records;
	
		}
		
	
		
	}
	
	
}

void CTestZnPDFLibrarianDLLDlg::OnCheck1() 
{
	// TODO: Add your control notification handler code here
	_bWholeWord = m_wholewordV;
}

void CTestZnPDFLibrarianDLLDlg::RecordCount(int record)
{
	 m_records = record;
	//	 UpdateData(false);
}

void CTestZnPDFLibrarianDLLDlg::OnEditchangeCombo1() 
{
	// TODO: Add your control notification handler code here
	
}

void CTestZnPDFLibrarianDLLDlg::OnSelchangeCombo1() 
{
	// TODO: Add your control notification handler code here
	int cursel;
	cursel = m_QueryType.GetCurSel();
	
	switch( cursel ) 
	{
	case 0:
		m_QueryTypev = SQT_ExactPhrase ;
		break;
	case 1:
		m_QueryTypev = SQT_AnyWords; 
		break;
	case 2:
		m_QueryTypev = SQT_AllWords ;
		break;
	case 3:
		m_QueryTypev = SQT_Boolean ;
		break;
		
	}
}

void CTestZnPDFLibrarianDLLDlg::OnSelchangeCombo2() 
{
	// TODO: Add your control notification handler code here
	CString  
		Author("Author"),
		Title("Title"),
		SubjectKeywords("SubjectKeywords"),
		Creator("Creator"),
		Producer("Producer"),
		CreationDate("CreationDate");
	int cursel = m_KeyCriteria.GetCurSel();
	switch (cursel) 
	{
		
	case 0:
		m_BKeyCriteria = Author.AllocSysString();
		break;
	case 1:
		m_BKeyCriteria = Title.AllocSysString();
		break;
	case 2:
		m_BKeyCriteria = SubjectKeywords.AllocSysString();
		break;
	case 3:
		m_BKeyCriteria = Creator.AllocSysString();
		break;
	case 4:
		m_BKeyCriteria = Producer.AllocSysString();
		break;
	case 5:
		m_BKeyCriteria = CreationDate.AllocSysString();
		break;

		
	}
	
}

void CTestZnPDFLibrarianDLLDlg::OnSelchangeCombo3() 
{
	// TODO: Add your control notification handler code here
	
	int cursel = m_MetaDataOP.GetCurSel();
	switch ( cursel ) 
	{
		
	case 0:
		m_EnumMetaDataOP = OP_Less ;
		m_StrMetaDataOP = "Less";
		break;
	case 1:
		m_EnumMetaDataOP = OP_Equal ;
		m_StrMetaDataOP = "Equal";
		break;
	case 2:
		m_EnumMetaDataOP = OP_Include ;
		m_StrMetaDataOP = "Include";
		break;
	case 3:
		m_EnumMetaDataOP = OP_Unequal ;
		m_StrMetaDataOP = "Unequal";
		break;
	case 4:
		m_EnumMetaDataOP = OP_Exclude ;
		m_StrMetaDataOP = "Exclude";
		break;
	case 5:
		m_EnumMetaDataOP = OP_More ;
		m_StrMetaDataOP = "More";
		break;
	}
}

void CTestZnPDFLibrarianDLLDlg::OnTimer(UINT nIDEvent) 
{
	// TODO: Add your message handler code here and/or call default
	//	MessageBeep(0xFFFFFFFF);   
	//	BSTR PDFpath;
	VARIANT filepath,pageno,pagecount;

	CString strstatus;
	CSearchStatus dlg;
	if(dlg.DoModal())
	{
		m_pPDFIndex->GetCatalogStatus(&filepath,&pagecount,&pageno/*,status*/);
		strstatus.Format("Filepath :%s/n/r",filepath.pcVal );	
	}
	CDialog::OnTimer(nIDEvent);
}

void CTestZnPDFLibrarianDLLDlg::OnBeep() 
{
	// TODO: Add your control notification handler code here
	int n  = m_result.GetItemCount();
	char *a;
	a = new char;

	itoa(n,a,10);
	AfxMessageBox(a);

	//	time = SetTimer(1,200,0);
}

void CTestZnPDFLibrarianDLLDlg::OnKillTimer() 
{
	// TODO: Add your control notification handler code here
	SelDir(	szPath);
//	KillTimer(1);
}

DWORD CTestZnPDFLibrarianDLLDlg::ThreadProc(LPVOID lpParameter)
{
	
	CTestZnPDFLibrarianDLLDlg *pDlg  = (CTestZnPDFLibrarianDLLDlg *)lpParameter;
	
	CoInitialize(NULL) ;
	
	CPDFSearchEvents searchevent(pDlg) ;
	
	searchevent.Initialize( pDlg->m_pPDFLibrarian,DIID__IPDFSearchEvents );
	pDlg->m_pPDFSearch->SearchIndex(/*m_IndexPath*/pDlg->m_indexfilepath.AllocSysString() /*indexfilepath*/ , pDlg->m_phrase.AllocSysString());
	searchevent.Uninitialize(pDlg->m_pPDFLibrarian,DIID__IPDFSearchEvents);
	
	return 0;
}

BOOL CTestZnPDFLibrarianDLLDlg::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_phrase = szPath;
	pMalloc->Free( lpList ) ;
	UpdateData(false);
	return TRUE;
}

⌨️ 快捷键说明

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