1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
|
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
#include <utilcls.h> // <---- ne pas oublier
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
Variant vMSWord, vWDocuments, vWDocument, vFileName;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
try
{
vMSWord = Variant::CreateObject("Word.Application");
}
catch(...)
{
vMSWord = Variant::CreateObject("Word.Application");
}
vMSWord.OlePropertySet("Visible", true);
vWDocuments = vMSWord.OlePropertyGet("Documents");
vWDocument = vWDocuments.OleFunction("Add");
if (Form1->Visible) // mettre l'appli toujours au premier plan
{
Form1->Visible = true;
Form1->BringToFront();
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
vWDocuments.OleFunction("Close", NULL, NULL);
vMSWord.OleFunction("Quit");
// on libere les Variants
vMSWord = Unassigned;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button3Click(TObject *Sender)
{
Application->Terminate();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button6Click(TObject *Sender)
{
// enveloppes
String addr = "Don Funk \r\n123 Skye St. \r\nOur Town \r\nWA 98040"; // destinataire
String AutoText = "";
String retaddr = "Karin Gallagher \r\n123 Main \r\nOther Town \r\nWA 98004"; // expediteur
vWDocuments.OleFunction("Add").OlePropertyGet("Envelope").OleFunction("Insert", false, addr.c_str(), AutoText.c_str(), false, retaddr.c_str());
vMSWord.OlePropertyGet("ActiveWindow").OlePropertyGet("View").OlePropertySet("Type", 3);
}
//--------------------------------------------------------------------------- |
Partager