📄 reference.htm
字号:
<p>This function will change the printer orientation of the printer. <b><font color="#000099">IT
CANNOT BE CALLED AFTER THE CONSTRUCTOR</font></b> for Cpage is called and
as such is a static member function. It must be called by a function in
the function chain somewhere before the OnPrint() or OnDraw() function
is called and after access to the CDC for the print job is available. The
recommended place to call the static member function is your CView::OnPrepareDC()
override. The CDC passed to this function will be changed by this function
call. The mode parameter must be either DMORIENT_PORTRAIT ( default ) or
DMORIENT_LANDSCAPE.
<p><b>Example</b>
<p><tt>void CMainView::OnPrepareDC(CDC* pDC, CPrintInfo* pInfo)</tt>
<br><tt>{</tt>
<br><tt> CView::OnPrepareDC(pDC, pInfo); // always call
base class first</tt>
<br><tt> switch(pInfo->m_nCurPage) // switch modes based
on page number</tt>
<br><tt> {</tt>
<br><tt> case 1:CPage::SetPrinterMode(pDC);break;</tt>
<br><tt> case 2:CPage::SetPrinterMode(pDC,DMORIENT_LANDSCAPE);break;</tt>
<br><tt> }</tt>
<br><tt>}</tt>
<center>
<p><b><font color="#000099"><font size=-2>DO NOT CALL THIS FUNCTION ONCE
THE CONSTRUCTOR FOR CPAGE HAS EXECUTED.</font></font></b></center>
<p><font color="#000099"><font size=-1>For users not familiar with static
member functions. The above code creates a CPage object on the stack and
executes the member function. The function does not depend on or alter
any data in the class so it needs no virtual table entry or a this pointer.
( as a matter of fact in CANNOT read or write and class data at all) There
will be one and only one copy of the function created no matter how many
CPage objects that there are. This is a poor explanation of static member
functions; please consult the MS documentation for details. HA!</font></font>
<center><a href="#toc">Back</a></center>
<p>
<hr WIDTH="100%">
<br><a NAME="GetPrinterName"></a><b><font size=-1>static LPCSTR GetPrinterName(CDC*
pDC);</font></b>
<p><font size=-1>This function will return the name of the selected printer
driver in use for this CDC. The driver cannot be changed but can be used
to switch between options. This function and the above function also demonstrates
the method of get data from and changing data in a DEVMODE structure. This
method can be used to change paper size DPI etc for all supported printers,</font>
<center>
<p><a href="#toc">Back</a></center>
<hr WIDTH="100%">
<br><a NAME="CpageConstruct"></a><b><font size=-1>CPage(RECT rectDraw,
CDC* p_Dc, int MapMode=MM_ANISOTROPIC)</font></b>
<p><font size=-1>This is the class constructor. There is no private constructor
override. This class is designed to be used in conjunction with MFC and
makes use of the Cview class printing architecture. The parameters are:</font>
<p><font size=-1>RECT rectDraw The drawing rectangle to be used by this
output device. ( see example )</font>
<br><font size=-1>CDC* The display context object passed by MFC to the
print function</font>
<br><font size=-1>Int mapMode The supported mapping modes are MM_TEXT and
MM_ANISOTROPIC</font>
<p><font size=-1>Example of use:</font>
<p><tt>void CMainView::OnPrint(CDC* pDC, CPrintInfo* pInfo)</tt>
<br><tt>{</tt>
<br><tt> double Row,Col;</tt>
<br><tt> CPage* ps= new CPage(pInfo->m_rectDraw,pDC,MM_TEXT);</tt>
<br><tt> Row=ps->Print(6.5,4.0,TEXT_NORMAL,10,"This is
a test");</tt>
<br><tt> delete ps;</tt>
<br><tt>}</tt>
<center><a href="#toc">Back</a></center>
<hr WIDTH="100%">
<p><a NAME="Print"></a><font size=-1><b>int Print(int row,int col,char*
fmt,...); // </b>use cpage default parameteres for flags pt size etc..</font>
<br><b><font size=-1>int Print(int row,int col,UINT TextFlags,int PointSize,char*
fmt,...);</font></b>
<p><font size=-1>The workhorse. This function has many different <a href="#note1">overloads</a>*.
All class functions are designed to use several different units of measurement.
In MM_TEXT map mode the native unit is pixels, which can vary from output
device to output device. In MM_ANISOTROPIC the units are user defined in
both axis. The default for this class is 1000 by 1000. The library can
also function in terms of inches. The passed parameters are converted to
native units before being passed to lower level functions. Inches present
the problem of being fractional in value and not integral. To facilitate
the ease of use the library makes the following assumptions to all calls
to the Print functions (With one exception noted below). <font color="#000099">If
the value is a double it is treated as a inch measurement. If one of the
location variables (Row and Col) is a double the other must be a double
also</font>. The parameters are:</font>
<p><font size=-1>Int row the vertical displacement for the print line.
Displacement is relative to the top of the page.</font>
<br><font size=-1>Int col the horizontal displacement for the print line.
Displacement is relative to the left side</font>
<br><font size=-1>( both of these parameters can be doubles and if so are
treated as inches )</font>
<br><font size=-1>UINT Textflags Modify the appearance of the output string.
See CPrinter.h</font>
<br><font size=-1>Int PointSize The number of points to use for the font.</font>
<br><font size=-1>Char* fmt a printf type format string.</font>
<br><font size=-1>Example of use:</font>
<p><tt>Void PrintStuff (CPage* ps)</tt>
<br><tt>{</tt>
<br><tt> Row=ps->Print(6.5,4.0,TEXT_NORMAL,10,"This is
a test");</tt>
<br><tt> Row=ps->Print(Row,4.0,TEXT_NORMAL,10,"This is
a test Also");</tt>
<br><tt> Row=ps->Print(Row,4.0,TEXT_NORMAL,10,"This is
a test Also as is this");</tt>
<br><tt> Col=1.0;</tt>
<br><tt> ps->Print(Row,&Col,TEXT_NORMAL,10,"This
is a test Also as is this");</tt>
<br><tt> ps->Print(Row,&Col,TEXT_BOLD|TEXT_ITALIC,10,"This
");</tt>
<br><tt> ps->Print(Row,&Col,TEXT_BOLD,10,"is Italic
");</tt>
<br><tt>}</tt>
<p><a NAME="note1"></a><font color="#000099"><font size=-1>*note</font></font>
<br><font color="#000099">Consult CPage.h for details on all the various
overloads. There are many.</font>
<p><font color="#000099"><font size=-1>int Print(int row,int *col,UINT
TextFlags,int PointSize,char* fmt,...) is a special override that takes
a pointer to the column variable. (See example above). On execution the
column variable is updated to the next column position. Subsequent calls
to Print using the variable will result in the output being a continuos
line allowing different attributes to be assigned within a line of text.
It is useful when printing a series of question/answer type forms also
as the variable will point to the next logical horizontal print area at
all times. There are also two overrides of this function that take only
Row,Column, Text parameters and get the rest of the information from the
defaults set into the CPage object.</font></font>
<center><a href="#toc">Back</a></center>
<hr WIDTH="100%">
<p><a NAME="PrintColumn"></a><b><font size=-1>void PrintColumn(int Top,int
Left,int Bottom,int Right,UINT flags,int PointSize,LPCSTR Text);</font></b>
<p><font size=-1>Print function to allow for newspaper style print columns.
The location variables function in the same manner as in Print() above
but have two extra dimensions to describe a bounding rectangle. All text
will be printed in the rectangle. If the flags variable includes TEXT_RECT
the bounding rectangle will be drawn on the output device. See Print()
for variable usage.</font>
<p><font size=-1>``</font>
<p><font size=-1>Example of use:</font>
<p><tt>Void PrintStuff (CPage* ps)</tt>
<br><tt>{</tt>
<br><tt> ps->PrintColumn(1.0,1.0,3.0,4.0,TEXT_BOLD|TEXT_RECT,8,</tt>
<br><tt> "This is a test of the column wrap feature");</tt>
<br><tt> ps->PrintColumn(1.00,4.1,3.0,7.0,TEXT_BOLD,8,</tt>
<br><tt> "This is a test of the column wrap feature ");</tt>
<br><tt>}</tt>
<center><a href="#toc">Back</a></center>
<hr WIDTH="100%">
<p><a NAME="SetLineSpacing"></a><b><font size=-1>double SetLineSpacing(double
Spacing);</font></b>
<p><font size=-1>Set the constant used in calculating the next logical
print line.. The amount needed to get the affect you want will vary so
experiment. Should be no smaller than 1.0</font>
<center>
<p><a href="#toc">Back</a></center>
<hr WIDTH="100%">
<p><a NAME="SetFont"></a><b><font size=-1>LPCSTR SetFont(LPCSTR FontName);</font></b>
<p><font size=-1>Set the default font name. The constructor sets it to
"Times New Roman". Spelling does count. The old font name is returned from
this function. If all you want is the font name use SetFont(NULL) to return
the current font name.</font>
<center><a href="#toc">Back</a></center>
<hr WIDTH="100%">
<br><a NAME="SetFontSize"></a><b><font size=-1>int SetFontSize(int sz);</font></b>
<br><font size=-1>Set default font pointsize.</font>
<center><a href="#toc">Back</a></center>
<hr WIDTH="100%">
<br><a NAME="SetColor"></a><b><font size=-1>COLORREF SetColor(COLORREF
Color);</font></b>
<br><font size=-1>If the output device supports color set the current color
here. Returns the old color.</font>
<center><a href="#toc">Back</a></center>
<hr WIDTH="100%">
<br><a NAME="SetRightmargin"></a><b><font size=-1>virtual int SetRightMargin(int
width)</font></b>
<br><font size=-1>Change the size of the default printing rectangle right
margin. A value of -1 will reset it to MaxWidth. A value of 0 will just
return the current value.Returns the previous width.</font>
<center><a href="#toc">Back</a></center>
<hr WIDTH="100%">
<br><a NAME="SetBottomMargin"></a><b><font size=-1>int SetBottomMargin(int
length);</font></b>
<br><font size=-1>Same as above except the margin affected is the bottom</font>
<center><a href="#toc">Back</a></center>
<hr WIDTH="100%">
<br><b><font size=-1>double SetRightMargin(double width);</font></b>
<br><font size=-1>See above</font>
<center><a href="#toc">Back</a></center>
<hr WIDTH="100%">
<br><b><font size=-1>double SetBottomMargin(double length);</font></b>
<br><font size=-1>See Above</font>
<center><a href="#toc">Back</a></center>
<hr WIDTH="100%">
<br><a NAME="GetDisplayContext"></a><b><font size=-1>CDC* GetDisplayContext();</font></b>
<br><font size=-1>Return the display context used for this page. Can be
used for direct manipulation of the context</font>
<p><font size=-1>Example of use:</font>
<p><tt>Void PrintStuff (CPage* ps)</tt>
<br><tt>{</tt>
<br><tt> CDC* pDc</tt>
<br><tt> pDc=ps->GetDisplayContext();</tt>
<br><tt>}</tt>
<center><a href="#toc">Back</a></center>
<hr WIDTH="100%">
<p><a NAME="PrintBitMap"></a><b><font size=-1>void PrintBitMap(int top,int
left,int bottom,int right,LPCSTR name);</font></b>
<br><b><font size=-1>void PrintBitMap(double top,double left,double bottom,double
right,LPCSTR name);</font></b>
<p><font size=-1>Prints a bitmap from a disk file into a region of the
page. The numeric parameteres are location vectors for the bounding rectangle
and the LPCSTR param is the name of the file to print. Disk based bitmaps
are directly supported as there are many ways to print a resource bitmap.</font>
<p><font size=-1>Example of use:</font>
<p><tt>Void PrintStuff (CPage* ps)</tt>
<br><tt>{</tt>
<br><tt> ps->PrintBitMap(1.0,1.0,4.0,5.0,"MyBitMap.bmp");</tt>
<br><tt>}</tt>
<center><a href="#toc">Back</a></center>
<hr WIDTH="100%">
<p><a NAME="GetNextLogCol"></a><b><font size=-1>double GetNextLogicalColumn(BOOL
Convert=TRUE,BOOL AddOffset=FALSE);</font></b>
<p><font size=-1>Returns the next logical print column based on the last
call to Print(). This must not be used prior to a call to Print() as garbage
will be returned. Parameters are:</font>
<p><font size=-1>BOOL Convert if true will return result in inches</font>
<br><font size=-1>BOOL AddOffset if true will add extra space to column
to give separation.</font>
<br><font size=-1>Example of use:</font>
<p><tt>Void PrintStuff (CPage* ps)</tt>
<br><tt>{</tt>
<br><tt> double Col;</tt>
<br><tt> ps->Print(6.5,4.0,TEXT_NORMAL,10,"This is a
test");</tt>
<br><tt> Col=ps->GetNextLogicalColumn(TRUE);</tt>
<br><tt> ps->Print(6.5,Col,TEXT_NORMAL|TEXT_ITALIC,10,"This
is a test Also");</tt>
<br><tt>}</tt>
<br><tt>Output will be "This is a test.<i>This is a test also</i>" starting
4 inches over and 6.5 inches down. The common usage is to apply special
formatting to indivivual words in a sentence.</tt>
<center><a href="#toc">Back</a></center>
<hr WIDTH="100%">
<p><a NAME="Line"></a><b><font size=-1>void Line(int top,int left,int bottom,int
right,int LineSize=1,UINT flag=PEN_SOLID);</font></b>
<br><b><font size=-1>void Box(int top,int left,int bottom,int right,int
LineSize=1,UINT Fillflags=FILL_NONE,UINT PenFlags=PEN_SOLID);</font></b>
<p><font size=-1>Drawing primitives exposed to user. Parameters can also
be doubles. If so they represent inches.Parameters are:</font>
<br><font size=-1>Int top,left,bottom,right: top/left define the position
of the left starting point</font>
<br><font size=-1>Bottom/right the right.</font>
<p><font size=-1>In the case of a rectangle the points describe the bounding
area to draw the rectangle around</font>
<br><font size=-1>Int Linesize Determines thickness of the line used to
draw the shape 1 is smallest</font>
<br><font size=-1>Int Fillflags determines if area is filled with color
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -