Programming Events
Code for all of these events, unless otherwise noted, can be automatically
generated by the
SOLIDWORKS
add-in wizards. See Events
for additional information about these events.
C++
Typical steps for creating a C++ COM object that support events for
a new SOLIDWORKS interface are:
Create a SOLIDWORKS C++ add-in with the SOLIDWORKS
add-in wizard. SOLIDWORKS recommends a non-attributed add-in that supports IModelView events (see the SwOptions
tab).
Study the model view event host COM object in
DocView.h and DocView.cpp.
You will create a similar one for another interface that supports events,
such as IMouse.
Create a new COM object class that derives from
IDispEventImpl.
Click Project
> Add Class (e.g., MyMouseHandler).
Click ATL
> ATL
Simple Object > Add button.
Click Options
> leave all default
options selected > Finish
button.
Add a sink event map
and a sink entry for each event you want to support. For example:
BEGIN_SINK_MAP(CSwMouse)
SINK_ENTRY_EX(ID_MOUSE_EVENTS, DIID_DMouseEvents,
swMouseMoveNotify, MouseMoveNotify)
SINK_ENTRY_EX(ID_MOUSE_EVENTS, DIID_DMouseEvents,
swMouseSelectNotify, MouseSelectNotify)
SINK_ENTRY_EX(ID_MOUSE_EVENTS, DIID_DMouseEvents,
swMouseLBtnDownNotify, MouseLBtnDownNotify)
END_SINK_MAP())
VB.NET
Typical steps for creating a VB.NET
COM object that supports events for a new SOLIDWORKS interface are:
Create a SOLIDWORKS VB.NET add-in with the SOLIDWORKS
add-in wizard.
Study the DocView class. You will create a similar
one for another interface that supports events, such as IMouse.
Create a new class to host your interface’s events
(e.g. MyMouseHandler) and write an initialization function to store a
reference to the main add-in object (e.g., IMouse), and the add-in’s document
event handler (as shown in EventHandling.vb)
Write methods to call the .NET AddHandler to associate
class methods with the events on the events (e.g., IMouse events). Call
these methods in your initialization code when your add-in is loaded.