<< Click to Display Table of Contents >> Analysing and Modifying the Layout Structure |
The following is a schematic overview, more detailed and complete source codes for C/C++, Visual Basic and Delphi are shipped with VPE.
The sample code demonstrates how to retrieve the complete layout structure from a template. In addition each object is modified, so that a frame is drawn around it.
Sample Code for the VPE Control
Dim tpl as TVPETemplatePage
Dim tpl_page As TVPETemplatePage
Dim obj as TVPEObject
VPE.OpenDoc
tpl = VPE.LoadTemplate("\dycodoc\samples\sample2.tpl")
SetFields(tpl) // this procedure had been declared in the very first sample
// In order to analyse the complete layout structure of a template, you
// need to iterate over each page
For i = 0 To tpl.PageCount - 1
// Get the Page Object (i) from the template
Set tpl_page = tpl.PageObject(i)
// Show how to retrieve the page dimensions and orientation
width = tpl_page.PageWidth
height = tpl_page.PageHeight
// Show how to retrieve the orientation and output paper bin
orientation = tpl_page.Orientation
paper_bin = tpl_page.PaperBin
// Show how to retrieve the margins as the user had defined in dycodoc
left_margin = tpl_page.nLeftMargin
top_margin = tpl_page.nTopMargin
right_margin = tpl_page.nRightMargin
bottom_margin = tpl_page.nBottomMargin
// Now iterate over all VPE Objects in this template page
For n = 0 To tpl_page.VpeObjectCount - 1
// Get the VPE Object (n) from the template page
Set obj = tpl_page.VpeObject(n)
// Make each object framed, except lines
If obj.Kind <> VOBJID_LINE Then
obj.PenSize = 0.03
End If
Next n
Next i
// Dump the template and show the preview
VPE.DumpTemplate(tpl)
VPE.Preview
Sample Code for the VPE DLL (C/C++)
VpeHandle hDoc = VpeOpenDoc(hWnd, "Sample", 0);
VpeHandle hTpl = VpeLoadTemplate(hDoc, "\\dycodoc\\samples\\Sample2.tpl");
if (hTpl == NULL)
return; // an error had occurred, e.g. the file was not found
SetFields(hTpl); // this procedure had been declared in the very first sample
// In order to analyse the complete layout structure of a template, you
// need to iterate over each page
for (long page = 0; page < VpeGetTplPageCount(hTpl); page++)
{
// Show how to retrieve the page dimensions and orientation
width = VpeGetTplPageWidth(hTpl, page);
height = VpeGetTplPageHeight(hTpl, page);
// Show how to retrieve the orientation and output paper bin
orientation = VpeGetTplPageOrientation(hTpl, page);
paper_bin = VpeGetTplPaperBin(hTpl, page);
// Show how to retrieve the margins as the user had defined in dycodoc
left_margin = VpeGetTplLeftMargin(hTpl, page);
top_margin = VpeGetTplTopMargin(hTpl, page);
right_margin = VpeGetTplRightMargin(hTpl, page);
bottom_margin = VpeGetTplBottomMargin(hTpl, page)
// Now iterate over all VPE Objects in this template page
for (n = 0; n < VpeGetTplVpeObjectCount(hTpl, page); n++)
{
// Get the VPE Object (n) from the template page
VpeHandle hVpeObject = VpeGetTplVpeObject(hTpl, page, n);
// Make each object framed, except lines
if (VpeGetObjKind(hVpeObject) != VOBJID_LINE)
VpeSetPenSize(hVpeObject, 0.03);
}
}
// Dump the template and show the preview
VpeDumpTemplate(hDoc, hTpl);
VpePreviewDoc(hDoc, NULL, VPE_SHOW_NORMAL);