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

📄 eventhandler.cpp

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

#include "stdafx.h"
#include "EventHandler.h"
#include "PasswordDlg.h"
#include <afxctl.h>
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CEventHandler

IMPLEMENT_DYNCREATE(CEventHandler, CCmdTarget)

CEventHandler::CEventHandler()
{
		//Initialize COM  libraries...create MTA...
	CoInitialize(NULL);
	EnableAutomation();
}

CEventHandler::~CEventHandler()
{
}

void CEventHandler::Initialize( LPUNKNOWN pUnk, REFIID iid )
{
	//advise the server that this (mainframe) is the sink for events...

	AfxConnectionAdvise( 
		pUnk,		
		iid,		
		GetIDispatch(FALSE),	
		FALSE,			//donod addref
		&m_dwCookie );	//cookie to break connection later...
}

void CEventHandler::Uninitialize( LPUNKNOWN pUnk, REFIID iid )
{
	//break the connection...donot receive any more events...

	AfxConnectionUnadvise( 
		pUnk, 
		iid , 
		GetIDispatch(FALSE),  
		FALSE, 
		m_dwCookie ) ;
}
BEGIN_MESSAGE_MAP(CEventHandler, CCmdTarget)
	//{{AFX_MSG_MAP(CEventHandler)
		// NOTE - the ClassWizard will add and remove mapping macros here.
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////


//----------------------------------------------------------------------------------
// CEventHandler message handlers
IMPLEMENT_DYNCREATE(CQueryPasswordEvent, CEventHandler)

BEGIN_MESSAGE_MAP(CQueryPasswordEvent, CEventHandler)
END_MESSAGE_MAP()


BEGIN_DISPATCH_MAP(CQueryPasswordEvent, CEventHandler)
	DISP_FUNCTION_ID(CQueryPasswordEvent, "QueryPassword", 1, OnQueryPassword, VT_BSTR, VTS_BSTR)
	DISP_FUNCTION_ID(CQueryPasswordEvent, "PasswordIncorrect", 2, OnPasswordIncorrect, VT_BSTR,, VTS_NONE)
END_DISPATCH_MAP( ) 

BEGIN_INTERFACE_MAP(CQueryPasswordEvent, CEventHandler)
	INTERFACE_PART(CQueryPasswordEvent, DIID__IPDFQueryPasswordEvents, Dispatch)
	INTERFACE_PART(CQueryPasswordEvent, DIID__IPDF2ImageEvents, Dispatch)
END_INTERFACE_MAP()

BSTR CQueryPasswordEvent::OnQueryPassword(BSTR filename)
{
	CPasswordDlg pwdDlg;
	BSTR Password;
	if(pwdDlg.DoModal())
	{
	 if(!pwdDlg.m_openpwd.IsEmpty())
	 {
		Password = pwdDlg.m_openpwd.AllocSysString();
	 }
	}
	return Password ;
}

void CQueryPasswordEvent::OnPasswordIncorrect(BSTR filename)
{
	AfxMessageBox("EndPassword");
}
//------------------------------------------------------------------------------

IMPLEMENT_DYNCREATE(CCombineEvent, CEventHandler)

BEGIN_MESSAGE_MAP(CCombineEvent, CEventHandler)
END_MESSAGE_MAP()


BEGIN_DISPATCH_MAP(CCombineEvent, CEventHandler)
	DISP_FUNCTION_ID(CCombineEvent, "StartJob", 1, OnStartJob, VT_EMPTY, VTS_NONE)
	DISP_FUNCTION_ID(CCombineEvent, "StartDoc", 2, OnStartDoc, VT_EMPTY, VTS_BSTR)
	DISP_FUNCTION_ID(CCombineEvent, "EndDoc",	3, OnEndDoc, VT_EMPTY, VTS_NONE)
	DISP_FUNCTION_ID(CCombineEvent, "EndJob",	4, OnEndJob, VT_EMPTY, VTS_NONE)
	DISP_FUNCTION_ID(CCombineEvent, "Abort",	5, OnAbort, VT_EMPTY, VTS_NONE)
	DISP_FUNCTION_ID(CCombineEvent, "QueryContinue",6, OnQueryContinue, VT_BOOL, VTS_BSTR)
END_DISPATCH_MAP( )

BEGIN_INTERFACE_MAP(CCombineEvent, CEventHandler)
	INTERFACE_PART(CCombineEvent, DIID__IPDFCombineEvents, Dispatch)
END_INTERFACE_MAP()

void CCombineEvent::OnStartJob()
{
	OutputDebugString( "OnStartJob" ) ;
		AfxMessageBox("123");
}

void CCombineEvent::OnStartDoc(char* filename)
{
	char buf[512] = {0} ;
	sprintf( buf, "Start Doc: %s", filename ) ;
	OutputDebugString( buf ) ;
	AfxMessageBox("123");
}

void CCombineEvent::OnEndDoc()
{
	OutputDebugString( "OnEndDoc" ) ;
		AfxMessageBox("123");
}

void CCombineEvent::OnEndJob()
{
	OutputDebugString( "OnEndJob" ) ;
		AfxMessageBox("123");
}
void CCombineEvent::OnAbort()
{
	OutputDebugString( "OnAbort" ) ;
}
VARIANT_BOOL CCombineEvent::OnQueryContinue(BSTR filename)
{

	m_continue = TRUE;
	return m_continue;
}

⌨️ 快捷键说明

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