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

📄 printeditor.shtml

📁 mfc资源大全包含MFC编程各个方面的源码
💻 SHTML
📖 第 1 页 / 共 2 页
字号:
<FONT COLOR="#990000"><PRE>
#include "SinglePagePrintJob.h"

class CTestPrintFormDoc;

class CTestPrintFormView : public CFormView
{
public:
	CSinglePagePrintJob	cSingleJob;
...
}
</FONT></PRE>
Then, we can modify our view print functions like that:<br>
<FONT COLOR="#990000"><PRE>

BOOL CTestPrintFormView::OnPreparePrinting(CPrintInfo* pInfo)
{
	UpdateData();

	cSingleJob.Clear();
	cSingleJob.AddPage("testform1.prx", "testpage", 1);

	if (pInfo->m_bPreview) return DoPreparePrinting(pInfo);

	return cSingleJob.OnPreparePrinting(pInfo);
}

void CTestPrintFormView::OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo)
{
	cSingleJob.OnBeginPrinting(pDC, pInfo);
}

void CTestPrintFormView::OnEndPrinting(CDC* pDC, CPrintInfo* pInfo)
{
	cSingleJob.OnEndPrinting(pDC, pInfo);
}

void CTestPrintFormView::OnPrint(CDC* pDC, CPrintInfo* pInfo)
{
	cSingleJob.OnPrint(pDC, pInfo);
}
</FONT></PRE>

Now we'll see how to implement a script able to handling the items of a list control.

<A NAME="POINT5">
<H4>5. A sample script for multi items form</H4>
</A>

<FONT COLOR="#000099"><PRE>
[Form Page Header]
NumPages=2
Page 0=testpage
Page 1=testsubform

[testpage]
Rect=100,100,2000,2800
Static=0,0,1900,150,Test Form Demo with subform,,,bold,italic,,Times New Roman,26,-1,ffffff,000000,000000,0,0,1,37
Static=0,300,300,400,Field 1:,,,bold,,,Arial,8,-1,ffffff,000000,000000,0,0,1,2
Edit=350,300,900,400,m_Field1,,,,,,Arial,8,-1,ffffff,000000,000000,0,0,1,0
Static=0,400,300,500,Field 2:,,,bold,,,Arial,8,-1,ffffff,000000,000000,0,0,1,2
Edit=350,400,900,500,m_Field2,,,,,,Arial,8,-1,ffffff,000000,000000,0,0,1,0
Static=900,300,1200,400,Field 3:,,,bold,,,Arial,8,-1,ffffff,000000,000000,0,0,1,2
Edit=1250,300,1900,400,m_Field3,,,,,,Arial,8,-1,ffffff,000000,000000,0,0,1,0
Static=900,400,1200,500,Field 4:,,,bold,,,Arial,8,-1,ffffff,000000,000000,0,0,1,2
Edit=1250,400,1900,500,m_Field4,,,,,,Arial,8,-1,ffffff,000000,000000,0,0,1,0
HLine=0,150,1900,200,,,,,,,Arial,8,-1,ffffff,000000,000000,0,0,1,0
Image=1600,0,1900,150,m_Image1,,,,,,Arial,8,-1,ffffff,000000,000000,0,0,1,0
Subform=94,694,1790,2500,testsubform,,,,,,Arial,8,-1,ffffff,000000,000000,0,0,1,0
Static=88,644,398,688,Column 1,,,,,,Arial,8,0,c0c0c0,000000,000000,0,0,1,0
Static=396,644,1792,688,Column 2,,,,,,Arial,8,0,c0c0c0,000000,000000,0,0,1,0
HLine=10,2602,1882,2630,,,,,,,Arial,8,-1,ffffff,000000,000000,0,0,1,0
Rect=88,644,1792,688,,,,,,,Arial,8,-1,ffffff,000000,000000,0,0,1,0
Rect=88,692,1792,2498,testsubform,,,,,,Arial,8,-1,ffffff,000000,000000,0,0,1,0

[testsubform]
Rect=0,0,1800,53
Edit=0,0,298,46,m_subfield1,,,,,,Arial,8,-1,ffffff,000000,000000,0,0,1,0
Edit=303,0,1888,46,m_subfield2,,,,,,Arial,8,-1,ffffff,000000,000000,0,0,1,0
HLine=0,52,1700,53,,,,,,,Arial,8,-1,ffffff,000000,000000,0,0,1,0
VLine=299,0,301,53,,,,,,,Arial,8,-1,ffffff,000000,000000,0,0,1,0
</FONT></PRE>
<I>(this is the "testform2.prx" provided in the demo)</I><br>
<br>
The main differences between this and the other script is that here we have 2 pages defined, "testpage"
and "testsubform". In the testpage form we have a Subform item with "testsubform" as field value.<br>
The size of the testsubform page is little, having an height of 0.5 cm. The Subform item in the "testpage"
page has an height of ~18 cm. That means that we have about 36 items in a page (a bit less since testsubform
height is 53 and not 50).<br>
When using multiitem pages, you have to use the AddPage function in another way:<br>
	
<FONT COLOR="#990000"><PRE>
	cMultiJob.AddPage("testform2.prx", "testpage", 1, wndList.GetItemCount());
</PRE></FONT>
Here we pass another parameter after the page Id - it's the number of subitems we have for the Subform item.
<br>
The class will call another virtual function just before getting info for a subitem:<br>
<FONT COLOR="#990000"><PRE>
	virtual void SelectSubItem(const long lPageId, const long lSubItemIndex);
</PRE></FONT>
If for example we have 200 items in the list control, the class will call:<br>
<FONT COLOR="#990000"><PRE>
Selectpage(1);
SelectSubItem(1,0);
SelectSubItem(1,1);
SelectSubItem(1,2);
SelectSubItem(1,3);
...
SelectSubItem(1,35);
<FONT COLOR="#009900">// Here we'll have a page change</FONT>
SelectSubItem(1,36);
..and so on
</PRE></FONT>

In the demo, since we are not using database or the like, I simply store the lSubItemIndex every
time the SelectSubItem function is called, and my derived functions looks like that:<br>

<FONT COLOR="#990000"><PRE>
void CMultiPagePrintJob::ParseScript(const char * cTag, CString &csValue)
{
	ASSERT(pView);

	if (!(lstrcmpi(cTag, "m_Field1"))) csValue = pView->csVal1;
	else if (!(lstrcmpi(cTag, "m_Field2"))) csValue = pView->csVal2;
	else if (!(lstrcmpi(cTag, "m_Field3"))) csValue = pView->csVal3;
	else if (!(lstrcmpi(cTag, "m_Field4"))) csValue = pView->csVal4;
	else if (!(lstrcmpi(cTag, "m_subfield1"))) csValue = pView->wndList.GetItemText(lSubItem, 0);
	else if (!(lstrcmpi(cTag, "m_subfield2"))) csValue = pView->wndList.GetItemText(lSubItem, 1);
}

void CMultiPagePrintJob::SelectSubItem(const long lPageId, const long lSubItemIndex)
{
	lSubItem = lSubItemIndex;
}
</PRE></FONT>


<br><br>
This is how the script above appear in print preview:<br>
<img src="preview2.gif" width="640" height="309" alt="preview2.gif (7K)"><br>
<br>
This is how "testpage" appear in the PrintFormEditor:<br>
<img src="printeditor2.gif" width="640" height="254" alt="printeditor2.gif (14K)"><br>
<br>
And this is how "testsubform" appear in the PrintFormEditor:<br>
<img src="printeditor2b.gif" width="640" height="61" alt="printeditor2b.gif (2K)"><br>
<br>

<A NAME="POINT1">
<H4>6. Putting it all in a view (2)</H4>
</A>

After we derived the CMultiPagePrintJob, we'll put an instance of it in the view header:<br>

<FONT COLOR="#990000"><PRE>
#include "MultiPagePrintJob.h"

class CTestPrintFormDoc;

class CTestPrintFormView : public CFormView
{
public:
	CMultiPagePrintJob	cSingleJob;
...
}
</FONT></PRE>

Then, we can modify our view print functions like that:<br>
<FONT COLOR="#990000"><PRE>

BOOL CTestPrintFormView::OnPreparePrinting(CPrintInfo* pInfo)
{
	UpdateData();

	cMultiJob.Clear();
	cMultiJob.AddPage("testform2.prx", "testpage", 1, wndList.GetItemCount());

	if (pInfo->m_bPreview) return DoPreparePrinting(pInfo);

	return cMultiJob.OnPreparePrinting(pInfo);
}

void CTestPrintFormView::OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo)
{
	cMultiJob.OnBeginPrinting(pDC, pInfo);
}

void CTestPrintFormView::OnEndPrinting(CDC* pDC, CPrintInfo* pInfo)
{
	cMultiJob.OnEndPrinting(pDC, pInfo);
}

void CTestPrintFormView::OnPrint(CDC* pDC, CPrintInfo* pInfo)
{
	cMultiJob.OnPrint(pDC, pInfo);
}
</FONT></PRE>


<br><br>

<A NAME="POINT7">
<H4>7. Printing from a dialog</H4>
</A>

These classes have been written based on my generic print classes here at codeguru. That means
that printing from dialogs or from any other place is supported, <I>except</I> for print preview.<br>
In the demo there is a menu command to launch a dialog which prints from it, printing exactly the
same as from the view; in that way you can see the difference.<br>
Basically, all you need to launch the print from somewhere else (you can do it from the view too,
but you will have no preview) is this:<br>

<FONT COLOR="#990000"><PRE>
	UpdateData();

	cMultiJob.Clear();
	<FONT COLOR="#009900">// This is the print job name as it will appear in the system print status</FONT>
	cMultiJob.strTitle = "Test dialog multiitem pages";
	cMultiJob.AddPage("testform2.prx", "testpage", 1, wndList.GetItemCount());
	cMultiJob.OnFilePrint();
</FONT></PRE>

<A NAME="POINT8">
<H4>8. The PrintFormEditor</H4>
</A>

As I stated above, I give no support for this app. Use it at your own risk. You are encouraged,
if you find that app has something good in it, to improve or rewrite it. If you do, send me your
code and I will post it here.<br>
Here there are the basic for working with it (and remember that the app can crash in every moment,
but - I hope - shouldn't format your HD, at least not at the first time it crashes ..).<br>
It has 2 windows, the view and a dockable bar. In the dockable bar are shown the pages of the document.<br>
You can add a page using the menu Pages->Add a page; you can remove a page selecting it in the paper bar
and using the menu Pages->Remove page.<br>
With the menu pages->Page size and and margins you can define the page size, margin and name. The
name can also be defined editing the icons in the paper bar and asking for the property dialog,
pushing the "pin" button and then clicking on an icon in the paperbar.<br>
Using the "Strumenti" toolbar you can add the items to the page; the "Align" toolbar permits standard
alignment function; you are warned that the Align toolbar commands doesn't work very well - they use
as "base" item the upper/left of the selected items, not the first or the last selected one.<br>
You can handle an item properties selecting it and using the context menu->Property. Be carefully
in having more than one item selected when doing this, since the change may be not as you can imagine.<br>
When you made changes to the properties, if they are not immediatly reflected on the selected item, 
hit the enter key.<br>
Some of the features in the property dialog are not currently implemented in the parse classes, as
the "double border style"; and it doesn't gray out the unused fields (eg. you can select "bold" and
font's facename even for lines - but it will be ignored).<br>
The help button in property dialog in here only show how it can be implemented, actually it shows
an unuseful little help page (in italian!).<br>
Remember, if you try the print preview command, to close the property dialog before. Exiting the print
preview is something which sometimes crash the app on my pc - save before!<br>
<br>
A last thing; I finded useful to use this app to make drafts of pages, and then manually modify the scripts.<br>
Don't damn me too much using this thing; remember that is free (an applause for the word "free" ..), that
I do other thing to live beside this (or I will be starving at this time ..) and I promise that if I will
won at the lottery I will write a better one.<br>


<A NAME="POINT9">
<H4>9. What do I need to use it ?</H4>
</A>

You'll need to import (with the standard add component way) the classes:<br>
<ul>
<li>CFormJob</li>
<li>CFormPrinterJob</li>
<li>CPrintStatus</li>
</ul>
Importing the CPrintStatus, which is a dialog, will import the dialog template resource too (IDD_PRINT_STATUS).<br>
It needs an avi file to be displayed during printing process (I took a sample from Microsoft) named
IDR_PRINT "AVI" resource (look at demo resource).<br>

<A NAME="POINT10">
<H4>10. Note about static MFC linking</H4>
</A>
Someone has reported me of troubles in compiling the previous printer classes with static MFC library;
the troubles where in loading the string resource named AFX_.. present in the CFormPrinterJob class.<br>
I've succesfully compiled and run the classes with static MFC (under VC5 + SP3, NT40 + SP3) .. so I'm sorry, guys, but it's a
problem of your Os/compiler/dll/lib .. don't damn me!<br>
<br>


That's all. Hope this little thing will make less basic printing questions appear in the discussion
board! Enjoy ..
<br>
<br>
<i>And if you permits .. I would like to dedicate this work, especially the buggy PrintFormEditor (little vengeange, 
there's a bug for every tears), to my *sigh* ex-girlfriend Enrica.. I'm soo lonely and sad now .. *sigh*</i>

<br>
<p>Last updated: 1 July 1998 </p>

<P>
<HR>
<TABLE BORDER=0 WIDTH="100%" >
<TR>
<TD WIDTH="33%"><FONT SIZE=-1><A HREF="http://www.codeguru.com">Goto HomePage</A></FONT></TD>

<TD WIDTH="33%">
<CENTER><FONT SIZE=-2>&copy; 1998 Zafir Anjum</FONT>&nbsp;</CENTER>
</TD>

<TD WIDTH="34%">
<DIV ALIGN=right><FONT SIZE=-1>Contact me: <A HREF="mailto:zafir@home.com">zafir@home.com</A>&nbsp;</FONT></DIV>
</TD>
</TR>
</TABLE>

</BODY>
</HTML>

⌨️ 快捷键说明

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