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

📄 testpdfocxdlg.cpp

📁 pdf文件编辑工具控件
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// testpdfocxDlg.cpp : implementation file
//

#include "stdafx.h"
#include "testpdfocx.h"
#include "testpdfocxDlg.h"
#include "ocxdefine.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

#define TOP_MARGIN	50

/////////////////////////////////////////////////////////////////////////////
// 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()

/////////////////////////////////////////////////////////////////////////////
// CTestpdfocxDlg dialog

CTestpdfocxDlg::CTestpdfocxDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CTestpdfocxDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CTestpdfocxDlg)
		// 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 CTestpdfocxDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CTestpdfocxDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CTestpdfocxDlg, CDialog)
	//{{AFX_MSG_MAP(CTestpdfocxDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_WM_SIZE()
	ON_MESSAGE(WM_MESSAGECALLBACK, OnMessageCallback)
	ON_BN_CLICKED(IDC_BUTTON_GETTEXT, OnButtonGettext)
	ON_BN_CLICKED(IDC_BUTTON_HIDEBUTTONS, OnButtonHidebuttons)
	ON_BN_CLICKED(IDC_BUTTON_SHOWBUTTONS, OnButtonShowbuttons)
	ON_WM_DESTROY()
	ON_WM_CLOSE()
	ON_BN_CLICKED(IDC_BUTTON_PDF2IMAGE, OnButtonPdf2image)
	ON_BN_CLICKED(IDC_BUTTON_SELECT_ICON, OnButtonSelectIcon)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CTestpdfocxDlg message handlers
void DrawLines(CDC *pDC,CRect m_nSelectedCellRect,BOOL bErase)
{
	int Width = 5;
	COLORREF m_ForeColor = RGB(0,0,255);
	if(bErase)
		m_ForeColor = RGB(255,255,255);
	CPen  pen(PS_SOLID,Width,m_ForeColor);
	CPen* OldPen = (CPen*)pDC->SelectObject(&pen);
	pDC->MoveTo(m_nSelectedCellRect.left,m_nSelectedCellRect.top);
	pDC->LineTo(m_nSelectedCellRect.right,m_nSelectedCellRect.top);
	pDC->LineTo(m_nSelectedCellRect.right,m_nSelectedCellRect.bottom);
	pDC->LineTo(m_nSelectedCellRect.left,m_nSelectedCellRect.bottom);
	pDC->LineTo(m_nSelectedCellRect.left,m_nSelectedCellRect.top);
	pDC->SelectObject(OldPen);
}
void ShowClickedButton(int iButtonID)
{
	CString strMessage;
	switch(iButtonID)
	{
	case ID_TOOLBAR_OPEN:
		strMessage = "ID_TOOLBAR_OPEN button clicked.";
		break;
	case ID_TOOLBAR_SAVE:
		strMessage = "ID_TOOLBAR_SAVE button clicked.";
		break;
	case ID_TOOLBAR_PRINT:
		strMessage = "ID_TOOLBAR_PRINT button clicked.";
		break;
	case ID_TOOLBAR_EMAIL:
		strMessage = "ID_TOOLBAR_EMAIL button clicked.";
		break;
	case ID_TOOLBAR_HAND:
		strMessage = "ID_TOOLBAR_HAND button clicked.";
		break;
	case ID_TOOLBAR_COMMENT:
		strMessage = "ID_TOOLBAR_COMMENT button clicked.";
		break;
	case ID_TOOLBAR_CONTENT:
		strMessage = "ID_TOOLBAR_CONTENT button clicked.";
		break;
	case ID_TOOLBAR_FORM:
		strMessage = "ID_TOOLBAR_FORM button clicked.";
		break;
	case ID_TOOLBAR_LINKTOOL:
		strMessage = "ID_TOOLBAR_LINKTOOL button clicked.";
		break;
	case ID_TOOLBAR_COMMENT_TEXT:
		strMessage = "ID_TOOLBAR_COMMENT_TEXT button clicked.";
		break;
	case ID_TOOLBAR_COMMENT_NOTE:
		strMessage = "ID_TOOLBAR_COMMENT_NOTE button clicked.";
		break;
	case ID_TOOLBAR_COMMENT_STAMP:
		strMessage = "ID_TOOLBAR_COMMENT_STAMP button clicked.";
		break;
	case ID_TOOLBAR_COMMENT_PENCIL:
		strMessage = "ID_TOOLBAR_COMMENT_PENCIL button clicked.";
		break;
	case ID_TOOLBAR_COMMENT_LINE:
		strMessage = "ID_TOOLBAR_COMMENT_LINE button clicked.";
		break;
	case ID_TOOLBAR_COMMENT_RECTANGLE:
		strMessage = "ID_TOOLBAR_COMMENT_RECTANGLE button clicked.";
		break;
	case ID_TOOLBAR_COMMENT_ELLIPSE:
		strMessage = "ID_TOOLBAR_COMMENT_ELLIPSE button clicked.";
		break;
	case ID_TOOLBAR_CONTENT_TEXT:
		strMessage = "ID_TOOLBAR_CONTENT_TEXT button clicked.";
		break;
	case ID_TOOLBAR_CONTENT_LINE:
		strMessage = "ID_TOOLBAR_CONTENT_LINE button clicked.";
		break;
	case ID_TOOLBAR_CONTENT_RECTANGLE:
		strMessage = "ID_TOOLBAR_CONTENT_RECTANGLE button clicked.";
		break;
	case ID_TOOLBAR_CONTENT_ELLIPSE:
		strMessage = "ID_TOOLBAR_CONTENT_ELLIPSE button clicked.";
		break;
	case ID_TOOLBAR_CONTENT_POLYLINE:
		strMessage = "ID_TOOLBAR_CONTENT_POLYLINE button clicked.";
		break;
	case ID_TOOLBAR_SELECT_TEXT:
		strMessage = "ID_TOOLBAR_SELECT_TEXT button clicked.";
		break;
	case ID_TOOLBAR_SELECT_IMAGE:
		strMessage = "ID_TOOLBAR_SELECT_IMAGE button clicked.";
		break;
	}
	AfxMessageBox(strMessage);
}
LRESULT GlobalMessageCallback(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam, long lUserData)
{
	CTestpdfocxDlg *pOCXDlg = (CTestpdfocxDlg*)lUserData;
	switch(message)
	{
	case WM_RBUTTONDOWN:
	case WM_RBUTTONUP:
	case WM_LBUTTONDOWN:
	case WM_LBUTTONUP:
	case WM_MOUSEMOVE:
		break;
	case WM_ADD_COMMENT_FINISHED:
		pOCXDlg->ShowPopupMenu();
		break;
	case WM_SELECT_A_COMMENT:
		pOCXDlg->ShowCommentInfo();
		break;
	case WM_SELECT_A_TEXTAREA:
		{
			LPSSELECTEDTEXTCONTENT lpSelectedText = (LPSSELECTEDTEXTCONTENT)lParam;
			pOCXDlg->ShowPopupMenu();
			CString strMessage;
			strMessage.Format("Selected Rectangle=%d,%d,%d,%d\n",lpSelectedText->rect.left,lpSelectedText->rect.top,
				lpSelectedText->rect.right,lpSelectedText->rect.bottom);
			strMessage += lpSelectedText->text;
			AfxMessageBox(strMessage);
			return TRUE;
		}
	case WM_ADD_COMMENT_GET_PREDEFINED_TEXT:
		{
			pOCXDlg->strTempText = "This is a prefilled text annotation, you may predefine it easily.";
			LPSTEXTDATA lpTextData = (LPSTEXTDATA)lParam;
			if(lpTextData)
			{
				lpTextData->len = pOCXDlg->strTempText.GetLength();
				lpTextData->text = LPCTSTR(pOCXDlg->strTempText);
			}
			break;
		}
	case WM_ADD_COMMENT_CLICK:
		{
			ShowClickedButton(wParam);
			break;
		}
	}
	return FALSE; //Return FALSE if you wish call original process
}

BOOL CTestpdfocxDlg::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
	CenterWindow();
	CRect clientRect;
	GetClientRect(&clientRect);
	clientRect.top = TOP_MARGIN;
	if(!m_ctrlPDFOcx.Create(NULL,WS_CHILD|WS_VISIBLE,clientRect,this,ID_PDFOCXWND))
	{
		AfxMessageBox("Please register pdfocx.ocx file first.");
		return -1;
	}
	//m_ctrlPDFOcx.AboutBox();
	//Remove "Trial PDF View OCX" watermark by your Order ID
	m_ctrlPDFOcx.SetOrderID("XXXXXXXXXX",NULL,NULL);

	//Delete buttons from toolbar, please refer to "toolbars.pdf" document
	//to get Index ID for each button
//	m_ctrlPDFOcx.MainToolbarDeleteButton(26); //Delete Capture Screen button

⌨️ 快捷键说明

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