visEvtConnect and the Connects and Connect objects?

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
 
P

Peter Suter

Hi Scott

The short VBA-code snippet shows how to get the two conected shapes and
the connectionpoints
'
iCCnt = oShp.Connects.Count
'
If iCCnt > 0 Then
For Each oConn In oShp.Connects
Set oShpTo = oConn.ToSheet
' detect begin/end
iFromPart = oConn.FromPart
' 9 = visBegin
' 12 = visEnd
' get ConnectionPointName in Shape:
iRow = oConn.ToPart - 100
sConnPointName =
oShpTo.Section(visSectionConnectionPts).Row(iRow).Name
MsgBox oShpTo.NameID & " " & iFromPart & " " & sConnPointName
Next
End If
'
--
Regards

Peter Suter
Ing.
CH 3255 Rapperswil BE


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
 
S

Scott Metzger

Thanks. My C++ code fails on the equivalent statement:

Your VB: For Each oConn In oShp.Connects
My C++ : vsoConnectorConnects.Item(i, vsoConnect)

What type is oConn ?
Is the index 0 based or 1 based ?

Anyone have some C++ code?

Thanks,
Scott Metzger
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top