//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "Outlook_2K_SRVR"
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
ns = OutlookApplication1->GetNamespace(WideString("MAPI"));
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
MAPIFolderPtr tmp;
TTreeNode *tmp_node;
tv->Items->Clear();
for (int i=1; i<=ns->Folders->Count; i++)
{
tmp = ns->Folders->Item(i);
tmp_node = tv->Items->Add(tv->TopItem,String(tmp->Name));
tmp_node->Data = tmp->EntryID;
if (tmp->Folders->Count)
EnumFolders(tmp,tmp_node);
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::EnumFolders(MAPIFolderPtr fldr, TTreeNode *parent)
{
MAPIFolderPtr tmp;
TTreeNode *tmp_node;
String str;
for (int i=1; i<=fldr->Folders->Count; i++)
{
tmp = fldr->Folders->Item(i);
str = tmp->Name;
tmp_node = tv->Items->AddChild(parent,str);
tmp_node->Data = tmp->EntryID;
if (tmp->Folders->Count)
EnumFolders(tmp,tmp_node);
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::tvDblClick(TObject *Sender)
{
MAPIFolderPtr fldr;
fldr = ns->GetFolderFromID((wchar_t *)tv->Selected->Data);
fldr->Display();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::add1Click(TObject *Sender)
{
if (!tv->Selected) return;
String fldr_name;
MAPIFolderPtr fldr = ns->GetFolderFromID((wchar_t *)tv->Selected->Data);
fldr_name = InputBox("enter.folder.name","folder name","");
if (fldr_name != "")
fldr->Folders->Add(WideString(fldr_name));
}
//---------------------------------------------------------------------------
|