📄 form1.cpp
字号:
#include "stdafx.h"
#include "PrintDev.h"
#include "CPage.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
// note that there is not really a lot of code for what you get
void PrintForm1(CPage* pPage)
{
CString s;
double Row,LastTablePos;
// Print a title
Row=pPage->Print(0.0,0.0,TEXT_NORMAL|TEXT_CENTER,24,"Form Title");
// create and use a couple of print regions
CPrintRegion *Region1=pPage->CreateRegion(.5,0.0,1.5,3.9);
Region1->DrawBorder();
Region1->DrawTitle("Customer Information",8,TEXT_BOLD|TEXT_CENTER|TEXT_RECT,FILL_LTGRAY);
pPage->SetLineSpacing(1.0);
Row=pPage->Print(Region1,0.0,0.01,TEXT_NORMAL|TEXT_SINGLELINE,9,"The Customers Name");
Row=pPage->Print(Region1,Row,0.01,TEXT_NORMAL|TEXT_SINGLELINE,9,"The Customers Address");
Row=pPage->Print(Region1,Row,0.01,TEXT_NORMAL|TEXT_SINGLELINE,9,"The Customers City State Zip");
Row=pPage->Print(Region1,Row,0.01,TEXT_NORMAL|TEXT_SINGLELINE,9,"The Customers Phones etc");
CPrintRegion *Region2=pPage->CreateRegion(.5,4.0,1.5,7.9,FILL_LTGRAY);
Region2->DrawBorder();
Region2->DrawTitle("Store Information",8,TEXT_BOLD|TEXT_CENTER|TEXT_RECT,FILL_BLACK);
pPage->SetLineSpacing(1.0);
Row=pPage->Print(Region2,0.0,0.01,TEXT_NORMAL|TEXT_SINGLELINE,9,"The Store Name");
Row=pPage->Print(Region2,Row,0.01,TEXT_NORMAL|TEXT_SINGLELINE,9,"The Store Location");
Row=pPage->Print(Region2,Row,0.01,TEXT_NORMAL|TEXT_SINGLELINE,9,"The Store City State Zip");
Row=pPage->Print(Region2,Row,0.01,TEXT_NORMAL|TEXT_SINGLELINE,9,"The Store Phones etc");
Row=pPage->Print(Region2,Row,0.01,TEXT_NORMAL|TEXT_SINGLELINE,9,"Invoice Number Here");
pPage->Line(2.1,0.0,2.1,8.0,3);
Row=pPage->Print(2.2,0.0,TEXT_NORMAL|TEXT_CENTER,24,"INVOICE");
pPage->Line(Row,0.0,Row,8.0,3);
// create and use a couple of tables
TABLEHEADER* pTable=new TABLEHEADER;
pTable->PointSize=10;
pTable->LineSize=1; // default shown only for demp purposes
pTable->UseInches=TRUE;
pTable->AutoSize=FALSE;
pTable->Border=TRUE;
pTable->FillFlag=FILL_NONE;
pTable->NumColumns=5;
pTable->NumRows=12;
pTable->StartRow=Row+.1;
pTable->StartCol=0.0;
pTable->EndCol=8.0;
pTable->ColDesc[0].Init(1.0,"Item #");
pTable->ColDesc[1].Init(3.0,"Desc.");
pTable->ColDesc[2].Init(1.0,"# Items");
pTable->ColDesc[3].Init(1.0,"Cost");
pTable->ColDesc[4].Init(1.0,"Ext Cost",FILL_LTGRAY);
pPage->Table(pTable);
LastTablePos=pTable->EndRow;
pPage->Print(pTable,0,0,12,TEXT_LEFT|TEXT_BOLD,"123-009");
pPage->Print(pTable,0,1,6,TEXT_CENTER|TEXT_BOLD,"Small Cray Computer");
pPage->Print(pTable,0,2,12,TEXT_CENTER|TEXT_BOLD,"2");
pPage->Print(pTable,0,3,12,TEXT_RIGHT|TEXT_BOLD,"22.10");
pPage->Print(pTable,0,4,12,TEXT_RIGHT|TEXT_BOLD,"44.20");
pPage->Print(pTable,1,0,12,TEXT_LEFT|TEXT_BOLD,"123-119");
pPage->Print(pTable,1,1,12,TEXT_CENTER|TEXT_BOLD,"Microsoft JavaC++ Compiler for the Cray");
pPage->Print(pTable,1,2,12,TEXT_CENTER|TEXT_BOLD,"1");
pPage->Print(pTable,1,3,12,TEXT_RIGHT|TEXT_BOLD,"9022.10");
pPage->Print(pTable,1,4,12,TEXT_RIGHT|TEXT_BOLD,"9022.10");
delete pTable;
TABLEHEADER* pTable2=new TABLEHEADER;
pTable2->PointSize=10;
pTable2->LineSize=1; // default shown only for demp purposes
pTable2->UseInches=TRUE;
pTable2->AutoSize=FALSE;
pTable2->Border=TRUE;
pTable2->FillFlag=FILL_NONE;
pTable2->NumColumns=2;
pTable2->NumRows=3;
pTable2->StartRow=LastTablePos;
pTable2->StartCol=0.0;
pTable2->EndCol=8.0;
pTable2->ColDesc[0].Init(6.0,"taxes and Additional Charges",FILL_DKGRAY);
pTable2->ColDesc[1].Init(2.0,"Cost",FILL_BLACK);
pPage->Table(pTable2);
LastTablePos=pTable2->EndRow;
pPage->Print(pTable2,0,0,12,TEXT_LEFT|TEXT_BOLD,"State Local and Federal Sales and Income Taxes");
pPage->Print(pTable2,0,1,12,TEXT_RIGHT|TEXT_BOLD,"3000.00");
pPage->Print(pTable2,1,0,12,TEXT_LEFT|TEXT_BOLD,"Free Bill Gates Legal Fund");
pPage->Print(pTable2,1,1,12,TEXT_RIGHT|TEXT_BOLD,"100.00");
pPage->Print(pTable2,2,0,12,TEXT_LEFT|TEXT_BOLD,"GRAND TOTAL");
pPage->Print(pTable2,2,1,12,TEXT_RIGHT|TEXT_BOLD,"12166.30");
delete pTable2;
// show wordwrap and paragraph formatting
s="This demonstrates the use of Print Regions, Tables, and Print Functions used "
"in conjunction with the library. It is very easy to construct forms that modify "
"their apperance in accordance to the amount of data available. I have used these "
"functions to construct report writers, ad hoc reports etc. If this paragraph does not "
"do wordwrap correctly the problem is not with the routines but rather a problem with "
"the printer driver you are using. We have had trouble with some HP drivers not implementing "
"HP's very own PCL correctly. Well have fun";
Row=pPage->Print(LastTablePos+.5,0.0,TEXT_NORMAL,8,"%s",s);
}
void PrintForm2(CPage* pPage)
{
CString s;
CPrintRegion *Region1=pPage->CreateRegion(0.0,0.0,1.5,7.0,FILL_LTGRAY);
Region1->DrawBorder();
Region1->DrawTitle("SubForm 1",8,TEXT_CENTER|TEXT_BOLD|TEXT_RECT,FILL_BLACK);
s="This is a subform. If the form is moved all the data in it will be moved also "
"this makes designing forms a little easier if you break it down into logical "
"components and make each a subform a component";
pPage->PrintColumn(Region1,0.0,0.01,1.5,4.0,TEXT_NORMAL|TEXT_RECT,9,s);
pPage->CheckBox(Region1,"A Check Box",TRUE,0.0,4.1,8,LABEL_RIGHT);
pPage->CheckBox(Region1,"A Check Box",TRUE,0.2,4.1,8,LABEL_RIGHT);
pPage->CheckBox(Region1,"A Check Box",TRUE,0.4,4.1,8,LABEL_RIGHT);
pPage->Print(Region1,.6,4.1,TEXT_NORMAL,8,"Thats all there is to it. If a string is two long it will be formatted to fit as well as possible");
CPrintRegion* pSub1=pPage->CreateSubRegion(Region1,0.8,0.0,1.5,2.0,FILL_DKGRAY);
pSub1->DrawBorder();
pSub1->DrawTitle("Sub Sub Form 1",8,TEXT_CENTER|TEXT_BOLD|TEXT_RECT,FILL_BLACK);
pPage->Print(pSub1,0.0,0.0,TEXT_NORMAL,8,"Thats all there is to it. If a string is to long it will be formatted to fit as well as possible");
CPrintRegion* pSub2=pPage->CreateSubRegion(Region1,0.8,6.0,1.5,7.0,FILL_DKGRAY);
pSub2->DrawBorder();
pSub2->DrawTitle("Sub Sub Form 2",8,TEXT_BOLD|TEXT_RECT,FILL_BLACK);
CPrintRegion *Region2=pPage->CreateRegion(2.0,0.0,3.5,7.0);
Region2->DrawBorder();
Region2->DrawTitle("SubForm 2",8,TEXT_BOLD|TEXT_RECT|TEXT_CENTER,FILL_BLACK);
s="This is a subform. If the form is moved all the data in it will be moved also "
"this makes designing forms a little easier if you break it down into logical "
"components and make each a subform a component. Sub Form 1 above shows how the fill color parameter works.";
// the offsets are the same as above. All offsets in subregions are based on the region not the page
pPage->PrintColumn(Region2,0.0,0.01,1.5,4.0,TEXT_NORMAL|TEXT_RECT,9,s);
pPage->CheckBox(Region2,"A Check Box",TRUE,0.0,4.1,8,LABEL_RIGHT);
pPage->CheckBox(Region2,"A Check Box",TRUE,0.2,4.1,8,LABEL_RIGHT);
pPage->CheckBox(Region2,"A Check Box",TRUE,0.4,4.1,8,LABEL_RIGHT);
pPage->Print(Region2,.6,4.1,TEXT_NORMAL,8,"This form is the same as the one above except for location. All the data is in the exact same place .Look at the source code to see what I mean");
}
void PrintForm3(CPage* pPage)
{
CString s;
double Row,LastTablePos;
TABLEHEADER* pTable=new TABLEHEADER;
pTable->PointSize=10;
pTable->LineSize=1; // default shown only for demp purposes
pTable->NumPrintLines=2;
pTable->UseInches=TRUE;
pTable->AutoSize=FALSE;
pTable->Border=TRUE;
pTable->FillFlag=FILL_LTGRAY;
pTable->NumColumns=6;
pTable->NumRows=6;
pTable->StartRow=0.0;
pTable->StartCol=0.0;
pTable->EndCol=8.0;
pTable->HeaderLines=3;
pTable->ColDesc[0].Init(1.0,"Col\n1",FILL_LTGRAY);
pTable->ColDesc[1].Init(3.0,"Col\n2",FILL_DKGRAY);
pTable->ColDesc[2].Init(1.0,"Col\n3",FILL_LTGRAY);
pTable->ColDesc[3].Init(1.0,"Col\n4",FILL_BLACK);
pTable->ColDesc[4].Init(1.0,"Col\n5",FILL_LTGRAY);
pTable->ColDesc[5].Init(1.0,"Col\n5",FILL_BLACK);
pPage->Table(pTable);
LastTablePos=pTable->EndRow;
pPage->Print(pTable,0,0,8,TEXT_BOLD|TEXT_CENTER,"Demo of\nmultiple lines\nper cell");
pPage->Print(pTable,0,1,8,TEXT_BOLD|TEXT_CENTER,"This allows one to specify the logical number of printable lines based on table font. Actual milage may vary");
pPage->Print(pTable,1,0,8,TEXT_BOLD|TEXT_CENTER,"Demo of\nmultiple lines\nper cell");
pPage->Print(pTable,1,1,8,TEXT_BOLD|TEXT_CENTER,"Lines are calculated based on table font size so you may get more than you want if using a smaller font to print. Adjust to your specific needs");
pPage->Print(pTable,2,0,8,TEXT_BOLD|TEXT_CENTER,"Demo of\nmultiple lines\nper cell");
pPage->Print(pTable,2,1,8,TEXT_BOLD|TEXT_CENTER,"Word wrap and clipping is active in each indiviual cell");
pPage->Print(pTable,0,3,8,TEXT_BOLD|TEXT_CENTER,"Word wrap and clipping is active in each indiviual cell");
pPage->Print(pTable,1,3,8,TEXT_BOLD|TEXT_CENTER,"Word wrap and clipping is active in each indiviual cell");
pPage->Print(pTable,2,3,8,TEXT_BOLD|TEXT_CENTER,"Word wrap and clipping is active in each indiviual cell");
pPage->Print(pTable,2,4,8,TEXT_BOLD|TEXT_CENTER,"Word wrap and clipping is active in each indiviual cell");
pPage->Print(pTable,2,5,8,TEXT_BOLD|TEXT_CENTER,"Word wrap and clipping is active in each indiviual cell");
TABLEHEADER* pTable2=new TABLEHEADER;
pTable2->PointSize=10;
pTable2->LineSize=1; // default shown only for demp purposes
pTable2->UseInches=TRUE;
pTable2->AutoSize=FALSE;
pTable2->Border=TRUE;
pTable2->FillFlag=FILL_LTGRAY;
pTable2->NumColumns=2;
pTable2->NumRows=3;
pTable2->StartRow=LastTablePos;
pTable2->StartCol=0.0;
pTable2->EndCol=8.0;
pTable2->ColDesc[0].Init(6.0,"More Stuff");
pTable2->ColDesc[1].Init(2.0,"More stuff");
pPage->Table(pTable2);
LastTablePos=pTable2->EndRow;
TABLEHEADER* pTable3=new TABLEHEADER;
pTable3->PointSize=10;
pTable3->LineSize=1; // default shown only for demp purposes
pTable3->UseInches=TRUE;
pTable3->AutoSize=FALSE;
pTable3->Border=TRUE;
pTable3->FillFlag=FILL_BLACK;
pTable3->NumColumns=3;
pTable3->NumRows=12;
pTable3->StartRow=LastTablePos;
pTable3->StartCol=0.0;
pTable3->EndCol=8.0;
pTable3->ColDesc[0].Init(1.0,"#1",FILL_LTGRAY);
pTable3->ColDesc[1].Init(3.0,"#2");
pTable3->ColDesc[2].Init(1.0,"#3",FILL_LTGRAY);
pPage->Table(pTable3);
LastTablePos=pTable3->EndRow;
delete pTable;
delete pTable2;
delete pTable3;
s="See the forms demo for a sample of inserting data into tables. It "
"is very easily done and is a simple way to build a complex form quickly";
pPage->SetFont("Courier");
Row=pPage->Print(LastTablePos+.5,0.0,TEXT_ITALIC|TEXT_BOLD,12,"%s",s);
}
void PrintForm4(CPage* ps)
{
double row=ps->Print(0.0,0.0,TEXT_NORMAL|TEXT_CENTER,24,"Bitmap Printing");
row=ps->Print(row,0.0,TEXT_BOLD|TEXT_ITALIC|TEXT_CENTER,24,"\"A Few of my favorite Things\"");
ps->PrintBitMap(row,1.5,row+1,7.00,"10a.bmp");
// same bitmap different size bounding rectangle
ps->PrintBitMap(2.0,1.0,4.50,7.00,"money.bmp");
ps->PrintBitMap(5.0,2.0,6.5,6.00,"money.bmp");
// place text over bit map. Looks different in preview than in printing
ps->Print(5.75,4.5,TEXT_NORMAL,14," ALL MINE");
row=ps->Print(7.0,0.0,TEXT_NORMAL|TEXT_CENTER,24,"Ain't this Nice");
CString s="You can place a bitmap any where you wish and also print over the "
"bitmap. This allows you to do scanned forms, company logos, "
"boilerplate, etc. Color will be supported if the output device and "
"driver are color compatible. Remember if you are placing text over "
"a bitmap to print the bitmap FIRST and then add the text.";
row=ps->Print(row,0.0,TEXT_NORMAL,14,"%s",s);
ps->SetFontSize(12);
CString OldFont=ps->SetFont("Courier");
row=ps->Print(row,0.0,"This demonstrates the default print function");
ps->SetFont("Verdana");
row=ps->Print(row,0.0,"If all you need is simple print statements this is a lot easier to use");
ps->SetFont("MS Sans Serif");
row=ps->Print(row,0.0,"But you do sacrifice a great deal of control over the output.");
ps->SetFont(OldFont);
}
#define ID_1 0
#define ID_2 1
#define ID_3 2
#define ID_4 3
#define ID_5 4
LPCSTR MyFunction(int ID)
{
static CString S;
switch(ID)
{
case ID_1:
S="Called From User Function ID 1";
return S;
case ID_2:
return "Called From User Function ID 2";
case ID_3:
return "Called From User Function ID 3";
case ID_4:
return "Called From User Function ID 4";
case ID_5:
return "Called From User Function ID 5";
}
return "*****unknown ID Passed*****";
}
void PrintForm5(CPage* ps)
{
ps->SetUserFunction(MyFunction);
double row=ps->Print(0.0,0.0,TEXT_NORMAL|TEXT_CENTER,24,"User Function Demo");
row=ps->Print(row,0.0,TEXT_BOLD|TEXT_ITALIC|TEXT_CENTER,24,ID_1);
row=ps->Print(row,0.0,ID_2);
row=ps->Print(row,0.0,ID_3);
row=ps->Print(row,0.0,ID_4);
ps->PrintColumn(row,0.1,row+.5,2.0,TEXT_RECT|TEXT_CENTER,14,ID_5);
CPrintRegion *Region1=ps->CreateRegion(5.0,0.0,6.5,7.0);
Region1->DrawBorder();
Region1->DrawTitle("SubForm 1",12,TEXT_BOLD|TEXT_RECT|TEXT_CENTER,FILL_NONE);
row=.2;
row=ps->Print(Region1,row,1.0,TEXT_NORMAL,10,ID_1);
row=ps->Print(Region1,row,1.0,TEXT_BOLD,12,ID_2);
row=ps->Print(Region1,row,1.0,TEXT_BOLD|TEXT_ITALIC,16,ID_3);
}
void PrintForm6(CPage* ps)
{
CString s;
double row=0.0;
for(int y=0; y < 3600;y+=100)
{
s.Format("Rotated Text Demo:Factor %d",y);
ps->PrintRotatedText(5.5,4.0,9.0,8.0,TEXT_BOLD|TEXT_NOCLIP,16,s,y);
}
ps->PrintRotatedText(5.5,4.0,9.0,8.0,TEXT_BOLD|TEXT_NOCLIP,16,"Rotated Text Demo:Factor 0",0);
ps->Line(5.5,0.0,5.5,8.0,5);
ps->Line(1.0,4.0,10.0,4.0,5);
s="Text can be rotated thru 360 degrees using this function. "
" the rotation factor is expressed in 1/10 of a degree of rotation so that a "
"factor of 900 is actually 90 degreees of rotation.";
row=ps->Print(row,0.0,s);
}
void PrintForm7(CPage* ps)
{
double Row=0;
for(int y=0;y < 5;++y)
Row=ps->Print(Row,(double)y,TEXT_BOLD,12,"%d",y);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -