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

📄 testpdfocxdlg.cpp

📁 pdf文件编辑工具控件
💻 CPP
📖 第 1 页 / 共 2 页
字号:
//	m_ctrlPDFOcx.MainToolbarDeleteButton(25); //Delete Text Selection button
//	m_ctrlPDFOcx.MainToolbarDeleteButton(24); //Separator
//	m_ctrlPDFOcx.MainToolbarDeleteButton(23); //Delete Content->Polygon
//	m_ctrlPDFOcx.MainToolbarDeleteButton(22); //Delete Content->Ellipse
//	m_ctrlPDFOcx.MainToolbarDeleteButton(21); //Delete Content->Rectangle
//	m_ctrlPDFOcx.MainToolbarDeleteButton(20); //Delete Content->Line
//	m_ctrlPDFOcx.MainToolbarDeleteButton(19); //Delete Content->Text Box
//	m_ctrlPDFOcx.MainToolbarDeleteButton(18); //Separator
//	m_ctrlPDFOcx.MainToolbarDeleteButton(17); //Delete Comment->Ellipse
//	m_ctrlPDFOcx.MainToolbarDeleteButton(16); //Delete Comment->Rectangle
//	m_ctrlPDFOcx.MainToolbarDeleteButton(15); //Delete Comment->Line
//	m_ctrlPDFOcx.MainToolbarDeleteButton(14); //Delete Comment->Pen Drawing
//	m_ctrlPDFOcx.MainToolbarDeleteButton(13); //Delete Comment->Image Stamper
//	m_ctrlPDFOcx.MainToolbarDeleteButton(12); //Delete Comment->Note
//	m_ctrlPDFOcx.MainToolbarDeleteButton(11); //Delete Comment->Text Box
//	m_ctrlPDFOcx.MainToolbarDeleteButton(10); //Separator
//	m_ctrlPDFOcx.MainToolbarDeleteButton(9);  //Delete "Link Editor" button
//	m_ctrlPDFOcx.MainToolbarDeleteButton(8);  //Delete "Form Filling" button
//	m_ctrlPDFOcx.MainToolbarDeleteButton(7);  //Delete "Edit Content" button
//	m_ctrlPDFOcx.MainToolbarDeleteButton(6);  //Delete "Edit Comment" button
//	m_ctrlPDFOcx.MainToolbarDeleteButton(5);  //Delete "View Mode" button
//	m_ctrlPDFOcx.MainToolbarDeleteButton(4);  //Separator
//	m_ctrlPDFOcx.MainToolbarDeleteButton(3);  //Delete "Email" button
//	m_ctrlPDFOcx.MainToolbarDeleteButton(2);  //Delete "Print" button
//	m_ctrlPDFOcx.MainToolbarDeleteButton(1);  //Delete "Save" button
//	m_ctrlPDFOcx.MainToolbarDeleteButton(0);  //Delete "Open" button

//	if(0)
//	{//View Mode
//		//Hide the form filling button
//		m_ctrlPDFOcx.MainToolbarHideButton(32877,TRUE);
//		//Use Embed Fonts to render the comments and annotations
//		m_ctrlPDFOcx.InvokeMethod(210,1,0);
//	}
//	else
//	{//View + Form Filling Mode
//		//Show the form filling button
//		m_ctrlPDFOcx.MainToolbarHideButton(32877,FALSE);
//		//Use System Fonts to render the comments and annotations
//		m_ctrlPDFOcx.InvokeMethod(210,0,0);
//	}
	//m_ctrlPDFOcx.SetMessageCallback((long)m_hWnd,WM_MESSAGECALLBACK,(long)this);
	m_ctrlPDFOcx.SetMessageCallbackFunc((long*)&GlobalMessageCallback, (long)this);
	return TRUE;  // return TRUE  unless you set the focus to a control
}

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

void CTestpdfocxDlg::OnSize(UINT nType, int cx, int cy) 
{
	CDialog::OnSize(nType, cx, cy);

	if(IsWindow(m_ctrlPDFOcx.GetSafeHwnd()))
	{
		CRect m_rectClient;
		GetClientRect(&m_rectClient);
		m_rectClient.top += TOP_MARGIN;
		m_ctrlPDFOcx.MoveWindow(m_rectClient);
	}
}

BOOL CTestpdfocxDlg::PreCreateWindow(CREATESTRUCT& cs) 
{
	cs.lpszClass = AfxRegisterWndClass(CS_HREDRAW|CS_VREDRAW,
		0,(HBRUSH)::GetStockObject(WHITE_BRUSH),0);	
	return CDialog::PreCreateWindow(cs);
}
void CTestpdfocxDlg::ShowPopupMenu()
{
#define MENU_ID  1000
	CMenu menuPopup;
	menuPopup.CreatePopupMenu();
	menuPopup.AppendMenu(MF_STRING,MENU_ID+0,"Menu Item0");
	menuPopup.AppendMenu(MF_STRING,MENU_ID+1,"Menu Item1");
	menuPopup.AppendMenu(MF_STRING,MENU_ID+2,"Menu Item2");
	menuPopup.AppendMenu(MF_STRING,MENU_ID+3,"Menu Item3");
	menuPopup.AppendMenu(MF_STRING,MENU_ID+4,"Menu Item4");
	menuPopup.AppendMenu(MF_STRING,MENU_ID+5,"Menu Item5");
	POINT point;
	GetCursorPos(&point);
	UINT nIndex = menuPopup.TrackPopupMenu(TPM_RETURNCMD|TPM_LEFTALIGN|TPM_LEFTBUTTON,point.x+1,point.y+1,this);
	switch(nIndex)
	{
	case MENU_ID+0:
		break;
	case MENU_ID+1:
		break;
	case MENU_ID+2:
		break;
	case MENU_ID+3:
		break;
	case MENU_ID+4:
		break;
	case MENU_ID+5:
		break;
	default:
		TRACE("Select nothing...\n");
		return;
	}
	char szBuffer[1024];
	sprintf(szBuffer,"Selected 'Menu Item%d'",nIndex-MENU_ID);
	MessageBox(szBuffer);
}
void CTestpdfocxDlg::ShowCommentInfo()
{
	int iCommentCount = m_ctrlPDFOcx.InvokeMethod(220,0,0);
	int iSelectedCommentCount = m_ctrlPDFOcx.InvokeMethod(221,0,0);
	int iSelectedComment = m_ctrlPDFOcx.InvokeMethod(222,0,0);
	
	CRect rectSelectedComment(0,0,0,0);
	m_ctrlPDFOcx.InvokeMethod(223,iSelectedComment,(long*)&rectSelectedComment);
	int iSelectedCommentType = m_ctrlPDFOcx.InvokeMethod(224,iSelectedComment,0);
	long iSelectedCommentUserData = m_ctrlPDFOcx.InvokeMethod(225,iSelectedComment,0);
	BOOL bOK = m_ctrlPDFOcx.InvokeMethod(226,iSelectedComment,(long*)this);

	TRACE("CommentCount=%d,SelectedCommentCount=%d,SelectedComment=%d,rectSelectedComment(%d,%d,%d,%d)\n",
		iCommentCount,iSelectedCommentCount,iSelectedComment,
		rectSelectedComment.left,rectSelectedComment.top,rectSelectedComment.right,rectSelectedComment.bottom);
	TRACE("SelectedCommentType=%d,SelectedCommentUserData=0x%x\n",iSelectedCommentType,iSelectedCommentUserData);
}
typedef struct TEXTINFOtag{
	RECT rect;
	char text[10];
}TEXTINFO,*LPTEXTINFO;
void CTestpdfocxDlg::OnButtonGettext() 
{
	// TODO: Add your control notification handler code here
	int iCount = m_ctrlPDFOcx.GetPageCount();
	long nTextContent = 0;
	int iCharCount = m_ctrlPDFOcx.GetTextContent(1,&nTextContent);
	LPTEXTINFO lpText = (LPTEXTINFO)nTextContent;
	for(int i = 0; i < iCharCount; i++,lpText++)
	{
		TRACE("Rect(%d,%d,%d,%d), %s\n",lpText->rect.left,lpText->rect.top,
			lpText->rect.right,lpText->rect.bottom,lpText->text);
	}
}
LRESULT CTestpdfocxDlg::OnMessageCallback(WPARAM wCallbackMessage, LPARAM lUserData)
{
	MSG *lpMsg = (MSG*)wCallbackMessage;
	return GlobalMessageCallback(lpMsg->hwnd,lpMsg->message,lpMsg->wParam,lpMsg->lParam,lUserData);
}

void CTestpdfocxDlg::OnButtonHidebuttons() 
{
	// TODO: Add your control notification handler code here
	m_ctrlPDFOcx.MainToolbarHideButton(ID_TOOLBAR_SAVE,TRUE);
	m_ctrlPDFOcx.MainToolbarHideButton(ID_TOOLBAR_EMAIL,TRUE);
	m_ctrlPDFOcx.MainToolbarHideButton(ID_TOOLBAR_CONTENT,TRUE);
	m_ctrlPDFOcx.MainToolbarHideButton(ID_TOOLBAR_CONTENT_TEXT,TRUE);
	m_ctrlPDFOcx.MainToolbarHideButton(ID_TOOLBAR_CONTENT_LINE,TRUE);
	m_ctrlPDFOcx.MainToolbarHideButton(ID_TOOLBAR_CONTENT_RECTANGLE,TRUE);
	m_ctrlPDFOcx.MainToolbarHideButton(ID_TOOLBAR_CONTENT_ELLIPSE,TRUE);
	m_ctrlPDFOcx.MainToolbarHideButton(ID_TOOLBAR_CONTENT_POLYLINE,TRUE);
}

void CTestpdfocxDlg::OnButtonShowbuttons() 
{
	// TODO: Add your control notification handler code here
	m_ctrlPDFOcx.MainToolbarHideButton(ID_TOOLBAR_SAVE,FALSE);
	m_ctrlPDFOcx.MainToolbarHideButton(ID_TOOLBAR_EMAIL,FALSE);
	m_ctrlPDFOcx.MainToolbarHideButton(ID_TOOLBAR_CONTENT,FALSE);
	m_ctrlPDFOcx.MainToolbarHideButton(ID_TOOLBAR_CONTENT_TEXT,FALSE);
	m_ctrlPDFOcx.MainToolbarHideButton(ID_TOOLBAR_CONTENT_LINE,FALSE);
	m_ctrlPDFOcx.MainToolbarHideButton(ID_TOOLBAR_CONTENT_RECTANGLE,FALSE);
	m_ctrlPDFOcx.MainToolbarHideButton(ID_TOOLBAR_CONTENT_ELLIPSE,FALSE);
	m_ctrlPDFOcx.MainToolbarHideButton(ID_TOOLBAR_CONTENT_POLYLINE,FALSE);	
}

void CTestpdfocxDlg::OnDestroy() 
{
	CDialog::OnDestroy();
	
	// TODO: Add your message handler code here
	
}

void CTestpdfocxDlg::OnClose() 
{
	long nModify = 0;
	m_ctrlPDFOcx.InvokeMethod(71,0,&nModify);
	if(nModify == 1)
	{
		MessageBox("Your PDF file has been modified.","PDF OCX",MB_ICONINFORMATION);
	}	
	CDialog::OnClose();
}

void CTestpdfocxDlg::OnButtonPdf2image() 
{
	static char BASED_CODE szFilter[] 
		="PDF File(*.pdf)|*.pdf||";
	CFileDialog  fOpenDlg(TRUE,"","",
		OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
		szFilter,NULL);
	if(fOpenDlg.DoModal() != IDOK)
		return;
	CString strPDFFileName = fOpenDlg.GetPathName();

	char sImageFilter[] = 
		"EMF File (*.emf)|*.emf|"
		"BMP file (*.bmp)|*.bmp|"
		"WMF File (*.wmf)|*.wmf|"
		"JPG File (*.jpg;*.jpeg)|*.jpg;*.jpeg|"
		"GIF File (*.gif)|*.gif|"
		"TIF File (*.tif;*.tiff)|*.tif;*.tiff|"
		"PNG File (*.png)|*.png|"
		"TGA File (*.tga)|*.tga|"
		"PCX File (*.pcx)|*.pcx|"
		"All File (*.*)|*.*||";
	CFileDialog  fSaveDlg(TRUE,".jpg","",
		OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
		sImageFilter,NULL);
	if(fSaveDlg.DoModal() != IDOK)
		return;
	CString strImgFileName = fSaveDlg.GetPathName();

	int iRet = m_ctrlPDFOcx.ConvertPDFToImage(strPDFFileName, strImgFileName,72,72,
		COMPRESSION_CCITTFAX4, 0, -1, -1, 24, 0);
	ShellExecuteA(m_hWnd,"open",strImgFileName,NULL,NULL,SW_SHOW);
}

void CTestpdfocxDlg::OnButtonSelectIcon() 
{
	static iSelect = 1;
	if(iSelect == 0)
		m_ctrlPDFOcx.InvokeMethod(41, 1, 0);//Hand
	else if(iSelect == 1)
		m_ctrlPDFOcx.InvokeMethod(21, 0, 0);//Text Copy
	else if(iSelect == 2)
		m_ctrlPDFOcx.InvokeMethod(22, 0, 0);//Picture Copy
	iSelect++;
	if(iSelect >= 3)
		iSelect = 0;
	//m_ctrlPDFOcx.InvokeMethod(227, 0, 0);//Disable main popup menu
}

⌨️ 快捷键说明

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