📄 makeform.cpp
字号:
//===========================================================================
//
// Module: MAKEFORM.CPP
//
// Description:
// Sample C++ API program that demonstrates how to use LNForm
// and it's related classes to create and modify forms.
//
// Syntax: MAKEFORM
//
//===========================================================================
#include <iostream>
#include <iomanip>
#include <stdio.h>
// Notes C++ API headers.
#include "lncppapi.h"
#include "editdflt.h"
using namespace std;
char CommandBuf[80];
// Prototype definitions for this sample.
void PrintProperties(LNForm &form );
void PrintAutoLaunchSettings(LNForm &form );
void SetProperties(LNForm &form );
void SetAutoLaunchProperties(LNForm &form );
void CreateActionBar ( LNForm & sampleForm,
const LNString & approvalAddress,
const LNString & ccList );
//---------------------------------------------------------------------------
//
// MAIN
//
//---------------------------------------------------------------------------
int main(int argc, char *argv[])
{
int ProgramStatus = 0;
LNNotesSession Session;
// Begin TRY block.
// Throw all errors encountered during command execution.
LNSetThrowAllErrors (TRUE);
try
{
LNDatabase Db;
LNForm newform;
LNForm referenceform;
LNForm newform2;
// Initialize the API.
Session.Init (argc, argv);
// Get the user of this machine to use later in the Create Action
// Bar Function. NOTE: you could provide your own approval name,
// and cclist and initialize them here instead for your own purposes.
LNString user1 = Session.GetUserName();
LNString ccusers = user1;
// Include the following Background Graphic code for all
// platforms except Mac and unix.
#if !defined(UNIX) && !defined (OS2)
// Get the file name and path for an import Bitmap
// that will be added in a form background later.
LNString bitmapfilepath;
bitmapfilepath = Session.GetDataDirectory();
bitmapfilepath << "/bkground.bmp";
// Check the file path length.
LNINT len = bitmapfilepath.GetByteLength();
if ( len > LNMAXPATH )
throw "Data Directory path too long.";
#endif
// Get the Notes database.
Session.GetDatabase( "fdesign.ntf", &Db );
// Open the database.
Db.Open();
// If this sample has been previously run, delete the forms
// that were created by it so it can run again...
if ( Db.FormExists("New Default Form") )
Db.DeleteForm("New Default Form");
if ( Db.FormExists("Brand New Form") )
Db.DeleteForm("Brand New Form");
cout << "***** Getting the Master Default Form from ******" << endl << endl;
// Get an existing form from the database.
Db.GetForm( "Master Default Form", &referenceform );
referenceform.Open();
// Print out all of the current property settings on the form.
// This function is just below this Main() function and
// demonstrates most of LNForm's Get methods.
PrintProperties(referenceform);
PrintAutoLaunchSettings(referenceform);
cout << "***** Copying the Master Form to a new form. ******" << endl
<< "***** Changing the name of the new form. ******" << endl
<< "***** Adding alias names to the new form. ******" << endl
<< "***** Adding a new background graphic. ******" << endl
<< "***** Changing the RichTextField1 name. ******" << endl
<< "***** Saving, closing, re-opening New Form. ******" << endl
<< endl;
// Use the copy constructor to copy the existing form to newform.
Db.CreateForm(referenceform, &newform);
newform.Open();
// Close the reference form. We will use the newform as the
// copy of it from now on.
referenceform.Close();
// Set the name of this copied form. Add in alias names too...
newform.SetName("New Default Form | $DForm1 | simpleform");
// Include the following Background Graphic code for all
// platforms except Mac and unix.
#if !defined(UNIX) && !defined (OS2)
// Get a background graphic from the bitmap file we set above...
LNRichText rt;
LNRTCursor cursor;
LNGraphic graphic;
rt.GetCursor( &cursor);
rt.Import( bitmapfilepath, &cursor );
cursor.GotoFirst( LNRTTYPE_GRAPHIC, &graphic );
// Set the background graphic for this form.
newform.SetBackgroundGraphic( graphic );
#endif
// Change the static text heading for this copied form.
// Change the default color for the form's text to stand
// out against the background etc.
LNRichText formbody1;
LNRTCursor cursor1;
LNRTCursor cursor2;
LNFontStyle fs1;
// Get the Form $Body some cursors, and the fontstyle.
newform.GetFormBody ( &formbody1 );
formbody1.GetCursor( &cursor1 );
formbody1.GetCursor( &cursor2 );
formbody1.GetFontStyle( cursor1, &fs1 );
fs1.SetColor( LNCOLOR_YELLOW );
// Replace the string "Master Default Form"
// With the string "New Default Form"
cursor1.GotoFirst( "Master Default" );
cursor2.GotoFirst( "Default Form" );
formbody1.Delete( &cursor1, &cursor2 );
formbody1.Insert( "New ", &cursor1 );
// Replace the string "Basic Form created with UI"
// With the string "Copy of Master Default Form"
cursor1.GotoFirst( "Basic Form" );
cursor2.GotoFirst( ")" );
formbody1.Delete( &cursor1, &cursor2 );
formbody1.Insert( "Copy of Master Default Form", &cursor1 );
// Reset cursors to start and end of $Body item.
// and set the over all font style.
formbody1.GetCursor( &cursor1 );
formbody1.GetEndCursor( &cursor2 );
formbody1.SetFontStyle( cursor1, cursor2, fs1 );
// Change font point size for the field headings.
cursor1.GotoFirst( "Text Field 1" );
fs1.SetPointSize( 12 );
formbody1.SetFontStyle( cursor1, cursor2, fs1 );
// Get the RichTextFeld1 and change it's name just for kicks.
LNFormField rtField;
newform.GetFormField("RichTextField1", &rtField);
rtField.SetName("NewRichTextField");
// Save, Close and re-open the new form just for fun.
newform.Save();
newform.Close();
newform.Open();
// Print out the properties of this new form now that it has been
// refreshed to disk.
PrintProperties(newform);
PrintAutoLaunchSettings(newform);
//
// **** The next section creates a brand new form from scratch ****
//
cout << endl << endl << "*****************************************************" << endl;
cout << "***** Now Create a brand new form from scratch ******" << endl;
cout << "*****************************************************" << endl << endl;
// Now Create a brand new (default) form from scratch.
Db.CreateForm( "Brand New Form", &newform2 );
// Print out all of the current property settings on the form.
PrintProperties(newform2);
PrintAutoLaunchSettings(newform2);
cout << "***** Changing some properties on this form. ******" << endl << endl;
// make some changes (calls to Set functions)
SetProperties(newform2);
cout << "***** Creating a new rich text form field, ******" << endl
<< "***** and inserting it into the form. ******" << endl
<< "***** Adding a static text heading above ******" << endl
<< "***** the rich text field. Setting auto ******" << endl
<< "***** launch features for this form. ******" << endl
<< endl;
// Create a new rich text form field and insert it
// Into the form $Body item, with a static text
// heading above it. Use Cursors, Fontstyle etc...
LNRichText formbody;
LNRTCursor startcursor;
LNRTCursor endcursor;
LNFontStyle fs;
newform2.GetFormBody ( &formbody );
formbody.Append( "Here is a New Rich Text Field Created using the C++ API" );
formbody.GetCursor( &startcursor );
formbody.GetEndCursor( &endcursor );
fs.SetColor( LNCOLOR_DARK_BLUE );
fs.SetFaceID( LNFACEID_ROMAN );
fs.SetPointSize( 24 );
fs.SetAttributes( LNFONTATTRIBUTEFLAGS_BOLD );
formbody.SetFontStyle( startcursor, endcursor, fs );
formbody.StartNewParagraph( &endcursor );
formbody.CreateFormField( "RichTextField1", LNRTTYPE_RICH_TEXT_FIELD, &endcursor );
// Set up some of the Auto Launch features. Use RichTextField1 as
// The richtext field for the launch OLE object in field.
SetAutoLaunchProperties(newform2);
// Change the background color of this form.
newform2.SetBackgroundColor(LNCOLOR_RED);
cout << "***** Saving, closing, and re-opening it. ******" << endl << endl;
// Create an Action Bar and insert it into the form.
CreateActionBar ( newform2, user1, ccusers );
// Save, Close and re-open the brand new form just for fun.
newform2.Save();
newform2.Close();
newform2.Open();
// Print out all the form property settings now...
PrintProperties(newform2);
PrintAutoLaunchSettings(newform2);
// Close the Brand New form for the last time...
newform2.Close();
// Close the database, we are all done now...
Db.Close();
cout << "***** Notes Template file: Fdesign.ntf is ******" << endl
<< "***** modified and two new forms have been ******" << endl
<< "***** added. You can open it with Notes ******" << endl
<< "***** Designer for Domino to examine it. ******" << endl
<< endl << "All Done. ";
ProgramStatus = 0;
} // END try
catch (LNSTATUS lnerror)
{
char ErrorBuf[LNERROR_MESSAGE_LENGTH];
LNGetErrorMessage(lnerror, ErrorBuf, LNERROR_MESSAGE_LENGTH);
cout << "\nError: " << ErrorBuf << endl;
ProgramStatus = 2;
}
catch (const char *pErrorMessage)
{
cout << "\nError: " << pErrorMessage << endl << endl;
ProgramStatus = 1;
}
cout << "Hit return to exit: ";
cin.getline(CommandBuf, 50);
// Terminate the API.
Session.Term();
return (ProgramStatus);
} // END MAIN
//---------------------------------------------------------------------------
//
// Name:
// PrintProperties
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -