home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 1999 January
/
pcwk_01_1999.iso
/
Wtestowe
/
Vistdstd
/
Install
/
Data.Z
/
VGenericMFC.CPP
< prev
next >
Wrap
C/C++ Source or Header
|
1997-07-07
|
7KB
|
259 lines
//*****************************************************************************
// VGENERICMFC.CPP - Generated by the "MFC VAddon VSL Wizard."
// Copyright (C) 1997 Visio Corporation. All rights reserved.
#include "stdafx.h"
#include "vGenericMFC.h" // Your wizard-generated subclass of VAddon
// The name that you give the VGenericMFC in its constructor
// is the text which shows up in the Visio Tools/Macros menu.
// _T(" - DEBUG") is automatically appended to the debug version
// for you by the VAddon class:
VGenericMFC g_vGenericMFCAddon(_T("GenericMFC"));
//*****************************************************************************
// Constructor and destructor:
VGenericMFC::VGenericMFC(LPCTSTR pName) :
VAddon(ATTS, VAO_ENABLEALWAYS, 0, 0, pName)
{
}
VGenericMFC::~VGenericMFC()
{
}
//*****************************************************************************
//
// Handy little "error handling" macro...
// Requires a "CU:" (clean-up) label somewhere in the function
#define check_valid(hr, obj) \
if ( !SUCCEEDED(hr) || !((obj).IsSet()) ) \
goto CU;
//*****************************************************************************
// VAddon Overrides:
// The Run method is pure virtual, with no implementation
// in the parent class. This method *MUST* be overridden,
// but it doesn't *HAVE* to do anything. (As you can see below,
// we're basically just returning VAORC_SUCCESS.)
// The code in Run gets executed when the user chooses the
// Visio Tools menu item corresponding to your addon. It also
// gets executed when a shape sheet cell formula RUNADDON or
// RUNADDONWARGS gets evaluated.
VAORC VGenericMFC::Run(LPVAOV2LSTRUCT pV2L)
{
BOOL bMadeIt= FALSE;
CVisioApplication app;
if (SUCCEEDED(GetApp(app)))
{
// Two non-wrapped event sinks which we must
// 'Release' manually:
IUnknown FAR *pSink= NULL;
IUnknown FAR *pAnotherSink= NULL;
HRESULT hr= NOERROR;
static BOOL bFirstTime= TRUE; // only add event callbacks once...
// The rest of these will be 'Release'd (if necessary) when
// the function exits and they go out of scope:
CVisioEventList eList;
CVisioEvent event;
CVisioEvent anotherEvent;
CVisioDocuments docs;
CVisioDocument doc;
CVisioPages pages;
CVisioPage page;
CVisioShape shape;
CVisioShape shape1;
CVisioMasters masters;
CVisioMaster master;
CVisioDocument stencil;
CVisioCell cell;
CVisioCell cell1;
// Add a 'Document Created' event notification and a 'Shape Added' notification
// to the Application's EventList:
#if 0
if (bFirstTime && (SUCCEEDED(app.EventList(eList))))
{
bFirstTime= FALSE;
if (SUCCEEDED(CoCreateAddonSink(ReceiveNotifyFromVisio, &pSink)))
{
if (SUCCEEDED(eList.AddAdvise(visEvtCodeDocCreate, VVariant(pSink),
VBstr(""), VBstr(""), event)))
{
event.ID(&stc_nEventID);
}
pSink->Release();
pSink= NULL;
}
if (SUCCEEDED(CoCreateAddonSink(ReceiveAnotherNotifyFromVisio, &pAnotherSink)))
{
if (SUCCEEDED(eList.AddAdvise((short)(visEvtShape|visEvtAdd), VVariant(pAnotherSink),
VBstr(""), VBstr(""), anotherEvent)))
{
anotherEvent.ID(&stc_nAnotherEventID);
}
pAnotherSink->Release();
pAnotherSink= NULL;
}
}
#endif
// Add a new Document based on "sample.vst" and then drop two shapes
// and glue them together...
hr= app.Documents(docs);
check_valid(hr, docs);
hr= docs.Add(VBstr("sample.vst"), doc);
check_valid(hr, doc);
hr= doc.Pages(pages);
check_valid(hr, pages);
hr= pages.Item(VVariant(1L), page);
check_valid(hr, page);
hr= docs.Item(VVariant("sample.vss"), stencil);
check_valid(hr, stencil);
hr= stencil.Masters(masters);
check_valid(hr, masters);
hr= masters.Item(VVariant("Executive"), master);
check_valid(hr, master);
hr= page.Drop(master, 6.0, 6.0, shape);
check_valid(hr, shape);
// Re-using "master" without explicit 'Release' is OK --
// wrapper classes take care of it for you
hr= masters.Item(VVariant("Position"), master);
check_valid(hr, master);
hr= page.Drop(master, 3.0, 3.0, shape1);
check_valid(hr, shape1);
hr= shape.Cells(VBstr("Connections.X4"), cell);
check_valid(hr, cell);
hr= shape1.Cells(VBstr("Controls.X1"), cell1);
check_valid(hr, cell1);
hr= cell1.GlueTo(cell);
bMadeIt= TRUE;
}
CU:
if (!bMadeIt)
{
MessageBox(GetActiveWindow(), "Premature termination of GenericMFC. Is sample.vst/vss in the path?", "GenericMFC", MB_OK);
}
return VAORC_SUCCESS;
}
// The rest of the methods call the parent class,
// which performs default actions.
// IsEnabled, Help and About are yours. The default
// actions in the parent class are: "Yes, I'm enabled"
// and a big fat no-op for Help and About.
VAORC VGenericMFC::IsEnabled(LPVAOV2LSTRUCT pV2L)
{
return VAddon::IsEnabled(pV2L);
}
VAORC VGenericMFC::About(LPVAOV2LSTRUCT pV2L)
{
TCHAR szText[]= _T("GenericMFC Addon generated by MFC VAddon VSL Wizard.\n\nCopyright (c) 1997 by Visio Corporation.\nAll rights reserved.");
TCHAR szCaption[_MAX_PATH]= _T("About ");
_tcscat(szCaption, GetName());
MessageBox(GetActiveWindow(), szText, szCaption, MB_OK);
return VAORC_SUCCESS;
}
VAORC VGenericMFC::Help(LPVAOV2LSTRUCT pV2L)
{
TCHAR szText[]= _T("Code to jump to GenericMFC's help file is missing.");
TCHAR szCaption[_MAX_PATH]= _T("");
_tcscpy(szCaption, GetName());
_tcscat(szCaption, _T(" Help"));
MessageBox(GetActiveWindow(), szText, szCaption, MB_OK);
return VAORC_SUCCESS;
}
// You should always call VAddon::Load, Unload and
// KillSession and GetInstance or do the things that they
// do in your methods. See the source in "vaddon.cpp"
// and "vao.c" for more details.
VAORC VGenericMFC::Load(WORD wVersion, LPVOID p)
{
return VAddon::Load(wVersion, p);
}
VAORC VGenericMFC::Unload(WORD wParam, LPVOID p)
{
m_app= NULL;
return VAddon::Unload(wParam, p);
}
VAORC VGenericMFC::KillSession(LPVAOV2LSTRUCT pV2L)
{
return VAddon::KillSession(pV2L);
}
HINSTANCE VGenericMFC::GetInstance(long nFlags /*= 0L*/)
{
return VAddon::GetInstance(nFlags);
}
//*****************************************************************************
// VGenericMFC convenience methods:
HRESULT VGenericMFC::GetApp(CVisioApplication &app)
{
if (m_app.IsSet() || VAO_SUCCESS==vaoGetObjectWrap(m_app))
{
app= m_app;
return NOERROR;
}
return E_FAIL;
}