📄 eventhandler.cpp
字号:
// EventHandler.cpp : implementation file
//
#include "stdafx.h"
#include "EventHandler.h"
#include "resource.h"
#include "TextznPDFPrintDLLDlg.h"
#include "PassWordDlg.h"
#include <afxctl.h> //define AfxConnectionAdvise、AfxConnectionUnadvise
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
CString password;
/////////////////////////////////////////////////////////////////////////////
// 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,
&m_dwCookie );
}
void CEventHandler::Uninitialize( LPUNKNOWN pUnk, REFIID iid )
{
//break the connection...donot receive any more events...
AfxConnectionUnadvise(
pUnk,
iid ,
GetIDispatch(FALSE),
FALSE,
m_dwCookie ) ;
}
/////////////////////////////////////////////////////////////////////////////
// CPDFPrintEvent
IMPLEMENT_DYNCREATE(CPDFPrintEvent, CCmdTarget)
BEGIN_MESSAGE_MAP(CPDFPrintEvent, CEventHandler)
END_MESSAGE_MAP()
BEGIN_DISPATCH_MAP(CPDFPrintEvent, CEventHandler)
DISP_FUNCTION_ID(CPDFPrintEvent, "QueryPassword", 1, OnQueryPassword, VT_BSTR, VTS_BSTR)
DISP_FUNCTION_ID(CPDFPrintEvent, "PasswordIncorrect", 2, OnPasswordIncorrect, VT_EMPTY, VTS_BSTR)
DISP_FUNCTION_ID(CPDFPrintEvent, "StartDoc", 3, OnStartDoc, VT_EMPTY, VTS_BSTR)
DISP_FUNCTION_ID(CPDFPrintEvent, "StartPage", 4, OnStartPage, VT_EMPTY, VTS_I4)
DISP_FUNCTION_ID(CPDFPrintEvent, "EndPage", 5, OnEndPage, VT_EMPTY, VTS_I4)
DISP_FUNCTION_ID(CPDFPrintEvent, "EndDoc", 6, OnEndDoc, VT_EMPTY, VTS_BSTR)
END_DISPATCH_MAP( )
BEGIN_INTERFACE_MAP(CPDFPrintEvent, CEventHandler)
INTERFACE_PART(CPDFPrintEvent, DIID__IPDFPrintEvents, Dispatch)
END_INTERFACE_MAP()
/////////////////////////////////////////////////////////////////////////////
BSTR CPDFPrintEvent::OnQueryPassword(char* filename)
{
CPasswordDlg PasswordDlg;
if(PasswordDlg.DoModal() == IDOK)
{
password = PasswordDlg.m_DocPassword ;
}
return password.AllocSysString() ;
}
void CPDFPrintEvent::OnPasswordIncorrect(char* filename)
{
}
void CPDFPrintEvent::OnStartDoc(char* filename)
{
char buf[512] = {0} ;
sprintf( buf, "Start Print Doc: %s", filename ) ;
OutputDebugString( buf ) ;
}
void CPDFPrintEvent::OnStartPage(long pageno)
{
char buf[512] = {0} ;
sprintf( buf, "Start Print Page: %d", pageno ) ;
OutputDebugString( buf ) ;
}
void CPDFPrintEvent::OnEndPage(long pageno)
{
char buf[512] = {0} ;
sprintf( buf, "End page: %d", pageno ) ;
OutputDebugString( buf ) ;
}
void CPDFPrintEvent::OnEndDoc(char* filename)
{
char buf[512] = {0} ;
sprintf( buf, "End Doc: %s", filename ) ;
OutputDebugString( buf ) ;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -