S
Scott Metzger
Hi,
I am having trouble getting both Shape Objects that are on either side
of a 'connector' in the vsiEvtConnect event. For example
[shape1]-----[shape2]
When shape1 and shape2 are connected the visEvtConnect event fires, but
I am having trouble getting both shape1 and shape2 objects from within
my 'mapped' event.
Here is how I map the event:
void CVisioReadDlg::OnBnClickedEvtConnect()
{// this maps the connection event
IUnknown FAR* pSink = NULL;
CVisioEventList vsoEList;
CVisioEvent vsoEvent;
if ( SUCCEEDED(vsoApp.EventList(vsoEList)) )
{
if (SUCCEEDED(CoCreateAddonSink(OnConnection, &pSink)) )
{
if ( SUCCEEDED(vsoEList.AddAdvise( (short)(visEvtConnect
| visEvtAdd), VVariant(pSink), VBstr(_T("")),
VBstr(_T("")), vsoEvent)) )
{
vsoEvent.ID(&stclOnConnectionEventID);
}
} // end if created sink event
} // end if got list of events
}
Here is my event 'handler' function:
HRESULT __stdcall OnConnection( IN IUnknown* ipSink,
IN short nEventCode,
IN IDispatch* pSourceObj,
IN long lEventID,
IN long lEventSeqNum,
IN IDispatch* pSubjectObj,
IN VARIANT vMoreInfo,
OUT VARIANT* pvResult)
{
LPVISIOCONNECTS pConnects = NULL;
bool success = false;
if (!SUCCEEDED(pSubjectObj->QueryInterface(IID_IVConnects,
(LPVOID*)&pConnects)) )
return ERROR;
CVisioConnects vsoConnects(pConnects);
CVisioShape fromShape;
CVisioShape toShape;
vsoConnects.FromSheet(fromShape);
vsoConnects.ToSheet(toShape);
// The from object is the connector itself, is that correct?
CVisioCell vCellValue;
fromShape.CellsSRC(visSectionProp, visRowProp + 0, visCustPropsValue,
vCellValue);
VBstr cell_value;
vCellValue.getFormula(cell_value);
// The To object is the shape the connecter attaches to
toShape.CellsSRC(visSectionProp, visRowProp + 0, visCustPropsValue,
vCellValue);
vCellValue.getFormula(cell_value);
CVisioConnects vsoConnectorConnects;
//fromShape.FromConnects(vsoConnects);
fromShape.Connects(vsoConnectorConnects);
CVisioConnect vsoConnect;
long numConnections;
vsoConnectorConnects.Count(&numConnections); // 2 as I expected
for (int i=0; i<numConnections; i++)
{
if ( !SUCCEEDED(vsoConnectorConnects.Item(i, vsoConnect)) )
break; // the above call in the if statement always fails
}
}
I thought for sure if I
1) Got the ShapeConnector object
2) Got its Connects object
3) Got the individual Connect objects // this fails
4) Got the Shape object
I would then have each shape object.
I know I must be missing something, but I just can't seem to figure out
how I can use the Connects object in the event to get [shape1] and
[shape2] from the Connects object.
Thanks,
Scott Metzger
I am having trouble getting both Shape Objects that are on either side
of a 'connector' in the vsiEvtConnect event. For example
[shape1]-----[shape2]
When shape1 and shape2 are connected the visEvtConnect event fires, but
I am having trouble getting both shape1 and shape2 objects from within
my 'mapped' event.
Here is how I map the event:
void CVisioReadDlg::OnBnClickedEvtConnect()
{// this maps the connection event
IUnknown FAR* pSink = NULL;
CVisioEventList vsoEList;
CVisioEvent vsoEvent;
if ( SUCCEEDED(vsoApp.EventList(vsoEList)) )
{
if (SUCCEEDED(CoCreateAddonSink(OnConnection, &pSink)) )
{
if ( SUCCEEDED(vsoEList.AddAdvise( (short)(visEvtConnect
| visEvtAdd), VVariant(pSink), VBstr(_T("")),
VBstr(_T("")), vsoEvent)) )
{
vsoEvent.ID(&stclOnConnectionEventID);
}
} // end if created sink event
} // end if got list of events
}
Here is my event 'handler' function:
HRESULT __stdcall OnConnection( IN IUnknown* ipSink,
IN short nEventCode,
IN IDispatch* pSourceObj,
IN long lEventID,
IN long lEventSeqNum,
IN IDispatch* pSubjectObj,
IN VARIANT vMoreInfo,
OUT VARIANT* pvResult)
{
LPVISIOCONNECTS pConnects = NULL;
bool success = false;
if (!SUCCEEDED(pSubjectObj->QueryInterface(IID_IVConnects,
(LPVOID*)&pConnects)) )
return ERROR;
CVisioConnects vsoConnects(pConnects);
CVisioShape fromShape;
CVisioShape toShape;
vsoConnects.FromSheet(fromShape);
vsoConnects.ToSheet(toShape);
// The from object is the connector itself, is that correct?
CVisioCell vCellValue;
fromShape.CellsSRC(visSectionProp, visRowProp + 0, visCustPropsValue,
vCellValue);
VBstr cell_value;
vCellValue.getFormula(cell_value);
// The To object is the shape the connecter attaches to
toShape.CellsSRC(visSectionProp, visRowProp + 0, visCustPropsValue,
vCellValue);
vCellValue.getFormula(cell_value);
CVisioConnects vsoConnectorConnects;
//fromShape.FromConnects(vsoConnects);
fromShape.Connects(vsoConnectorConnects);
CVisioConnect vsoConnect;
long numConnections;
vsoConnectorConnects.Count(&numConnections); // 2 as I expected
for (int i=0; i<numConnections; i++)
{
if ( !SUCCEEDED(vsoConnectorConnects.Item(i, vsoConnect)) )
break; // the above call in the if statement always fails
}
}
I thought for sure if I
1) Got the ShapeConnector object
2) Got its Connects object
3) Got the individual Connect objects // this fails
4) Got the Shape object
I would then have each shape object.
I know I must be missing something, but I just can't seem to figure out
how I can use the Connects object in the event to get [shape1] and
[shape2] from the Connects object.
Thanks,
Scott Metzger