| Article | 70002592 |
| Type | HowTo |
| Product | Engine |
| Date Added | 11/15/2024 12:00:00 AM |
| Fixed | 11.3.2.0 (11/15/2024 12:00:00 AM) |
| Submitted by | VectorDraw Team |
Summary
Howto Fire VDF events in CPP COM project
Solution
//NOTE:when using CPP COM project is moe safe to set project->properties->Platform ToolSet to Visual Studio 2010
//Fire VDF events in CPP COM project
Example 1
//In this example we create a CProgressMeterEvents_Imp class that fires the events of vdDocument->MeterProgress
//Import the VDF neccesary tlbs //The folder of VDF libraries must set to the Additional Include Directories of CPP project properties
#import "System.Drawing.tlb"
#import "mscorlib.tlb" rename("ReportEvent","_ReportEvent")
#import "VectorDraw.Serialize.tlb"
#import "VectorDraw.Geometry.tlb"
#import "VectorDraw.Render.tlb"
#import "VectorDraw.Actions.tlb"
#import "VectorDraw.Professional.tlb" rename("GetEnvironmentVariable", "GetEnvVar")
#import "vdrawi5.tlb" \
rename("RGB","_RGB") \
rename("GetOpenFileName","_GetOpenFileName") \
#include "afxctl.h"
//define the IID of the IProgressMeterEvents interface that defines the method events
#define eventIID __uuidof(VectorDraw_Serialize::IProgressMeterEvents)
class CProgressMeterEvents_Imp : public CCmdTarget
{
DECLARE_DYNCREATE(CProgressMeterEvents_Imp)
//the vdDocument->MeterProgress object that fire the events
VectorDraw_Serialize::IProgressMeterPtr mObjectSender;
//a refernce to the event connection
DWORD m_dwCookie;
public:
CProgressMeterEvents_Imp() {
EnableAutomation();
}
//Method that make the connection between meterprogress sender and this object
void Connect(VectorDraw_Serialize::IProgressMeterPtr pDisp)
{
LPUNKNOWN disp = this->GetIDispatch(FALSE);
BOOL success = AfxConnectionAdvise(pDisp, eventIID, disp, FALSE, &m_dwCookie);
if (!success) return;
mObjectSender = pDisp;
}
//disconect when finish with them and need any more
void Disconect()
{
if (mObjectSender == NULL) return;
LPUNKNOWN disp = this->GetIDispatch(FALSE);
BOOL success = AfxConnectionUnadvise(mObjectSender, eventIID, disp, FALSE, m_dwCookie);
if (success) disp->Release();
mObjectSender = NULL;
}
// Event override Methods from : VectorDraw_Serialize::IProgressMeterEvents
void OnProgress(
const _variant_t& sender,
__int64 percent,
LPCTSTR jobDescription)
{
VectorDraw_Serialize::IProgressMeterPtr src = sender;
TCHAR path[100];
_stprintf_s(path, 100, _T("\njobDescription = %s , percent = %i"), (LPTSTR)src->jobDescription,(int) percent);
OutputDebugString(path);
}
void OnProgressStart(
const _variant_t& sender,
LPCTSTR jobDescription,
__int64 meterLimit)
{
VectorDraw_Serialize::IProgressMeterPtr src = sender;
TCHAR path[100];
_stprintf_s(path, 100, _T("\nProgress Started : jobDescription = %s , meterLimit = %i"), (LPTSTR)src->jobDescription, (int)meterLimit);
OutputDebugString(path);
}
void OnProgressStop(
const _variant_t& sender,
LPCTSTR jobDescription)
{
VectorDraw_Serialize::IProgressMeterPtr src = sender;
TCHAR path[100];
_stprintf_s(path, 100, _T("\nProgress Stoped : jobDescription = %s"), jobDescription);
OutputDebugString(path);
}
~CProgressMeterEvents_Imp() {}
DECLARE_DISPATCH_MAP()
DECLARE_INTERFACE_MAP()
};
IMPLEMENT_DYNCREATE(CProgressMeterEvents_Imp, CCmdTarget)
BEGIN_DISPATCH_MAP(CProgressMeterEvents_Imp, CCmdTarget)
//Here we define all events of the VectorDraw_Serialize::IProgressMeterEvents interface see DISP_FUNCTION_ID for details
DISP_FUNCTION_ID(CProgressMeterEvents_Imp, "OnProgress", 1, OnProgress, VT_EMPTY, VTS_VARIANT VTS_I8 VTS_BSTR)
DISP_FUNCTION_ID(CProgressMeterEvents_Imp, "OnProgressStart", 2, OnProgressStart, VT_EMPTY, VTS_VARIANT VTS_BSTR VTS_I8 )
DISP_FUNCTION_ID(CProgressMeterEvents_Imp, "OnProgressStop", 3, OnProgressStop, VT_EMPTY, VTS_VARIANT VTS_BSTR)
END_DISPATCH_MAP()
BEGIN_INTERFACE_MAP(CProgressMeterEvents_Imp, CCmdTarget)
INTERFACE_PART(CProgressMeterEvents_Imp, eventIID, Dispatch)
END_INTERFACE_MAP()
//code:
//suppose we already have a CVdraw object control created
CVdraw vdraw;
//get the default document of the control
VectorDraw_Professional::IvdDocumentPtr doc = vdraw->GetActiveDocument().GetWrapperObject();
//create a new document object
VectorDraw_Professional::IvdDocumentPtr tmpdoc = doc->Activator->CreateInstance("vdDocument");
//create the connection event object
CProgressMeterEvents_Imp* eventsVd1 = new CProgressMeterEvents_Imp();
//connect new document progress with our connection object
eventsVd1->Connect((VectorDraw_Serialize::IProgressMeterPtr)tmpdoc->MeterProgress);
//open a file to see the procedure progress to fire inside the connection object methods
tmpdoc->Open(_bstr_t(sourceFilePath));
//disconect
eventsVd1->Disconect();
Example 2 vdDocument events
//Import the VDF neccesary tlbs //The folder of VDF libraries must set to the Additional Include Directories of CPP project properties
#import "System.Drawing.tlb"
#import "mscorlib.tlb" rename("ReportEvent","_ReportEvent")
#import "VectorDraw.Serialize.tlb"
#import "VectorDraw.Geometry.tlb"
#import "VectorDraw.Render.tlb"
#import "VectorDraw.Actions.tlb"
#import "VectorDraw.Professional.tlb" rename("GetEnvironmentVariable", "GetEnvVar")
#import "vdrawi5.tlb" \
rename("RGB","_RGB") \
rename("GetOpenFileName","_GetOpenFileName") \
#include "afxctl.h"
#define documenteventIID __uuidof(VectorDraw_Professional::IvdDocumentEvents)
class CvdDocumentEvents_Imp : public CCmdTarget
{
DECLARE_DYNCREATE(CvdDocumentEvents_Imp)
//the vdDocument object that fire the events
VectorDraw_Professional::IvdDocumentPtr mObjectSender;
//a refernce to the event connection
DWORD m_dwCookie;
public:
CvdDocumentEvents_Imp() {
EnableAutomation();
}
//Method that make the connection between document sender and this object
void Connect(VectorDraw_Professional::IvdDocumentPtr pDisp)
{
LPUNKNOWN disp = this->GetIDispatch(FALSE);
BOOL success = AfxConnectionAdvise(pDisp, documenteventIID, disp, FALSE, &m_dwCookie);
if (!success) return;
mObjectSender = pDisp;
}
//disconect when finish with them and need any more
void Disconect()
{
if (mObjectSender == NULL) return;
LPUNKNOWN disp = this->GetIDispatch(FALSE);
BOOL success = AfxConnectionUnadvise(mObjectSender, documenteventIID, disp, FALSE, m_dwCookie);
if (success) disp->Release();
mObjectSender = NULL;
}
// Event override Methods from :VectorDraw_Professional::IvdDocumentEvents
void OnIsValidOpenFormat(
IDispatch* sender,
LPCTSTR extension,
VARIANT_BOOL* success){}
void OnGetOpenFileFilterFormat(
BSTR* openFilter){
//Write your code here
}
void OnGetSaveFileFilterFormat(
BSTR* saveFilter) {
//Write your code here
}
void OnUndoStoreValue(
IDispatch* sender,
VARIANT_BOOL isRedo,
const _variant_t& propObject,
LPCTSTR propName,
const _variant_t& value,
VARIANT_BOOL* Cancel) {
//Write your code here
}
void OnAfterUndoStoreValue(
IDispatch* sender,
VARIANT_BOOL isRedo,
const _variant_t& propObject,
LPCTSTR propName,
const _variant_t& value) {
//Write your code here
}
void OnLoadUnknownFileName(
IDispatch* sender,
LPCTSTR FileName,
VARIANT_BOOL* success) {
//Write your code here
}
void OnSaveUnknownFileName(
IDispatch* sender,
LPCTSTR FileName,
VARIANT_BOOL* success) {
//Write your code here
}
void OnProgress(
IDispatch* sender,
__int64 percent,
LPCTSTR jobDescription) {
//Write your code here
}
void OnBeforeOpenDocument(
IDispatch* sender) {
//Write your code here
}
void OnAfterOpenDocument(
IDispatch* sender) {
//Write your code here
}
void OnAfterNewDocument(
IDispatch* sender) {
//Write your code here
}
void OnOpenUrl(
IDispatch* sender,
BSTR* urlname,
VARIANT_BOOL* Cancel) {
//Write your code here
}
void OnNoFileFind(
IDispatch* sender,
BSTR* FileName,
VARIANT_BOOL* success) {
//Write your code here
}
void OnResizeControlWindow(
IDispatch* sender,
long cx,
long cy,
VARIANT_BOOL* Cancel) {
//Write your code here
}
void OnScroll(
IDispatch* sender,
double* cx,
double* cy,
VARIANT_BOOL* Cancel) {
//Write your code here
}
void OnPrompt(
IDispatch* sender,
BSTR* promptstr) {
//Write your code here
}
void GripSelectionModified(
IDispatch* sender,
struct IvdLayout* layout,
struct IvdSelection* gripSelection) {
//Write your code here
}
void ActionLayoutActivated(
IDispatch* sender,
struct IvdLayout* deactivated,
struct IvdLayout* activated) {
//Write your code here
}
void GetDimensionText(
IDispatch* sender,
BSTR* newText) {
//Write your code here
}
void ActionError(
IDispatch* sender,
LPTSTR actionName) {
//Write your code here
}
void ActionEnd(
IDispatch* sender,
LPTSTR actionName) {
//Write your code here
}
void ActionStart(
IDispatch* sender,
LPTSTR actionName,
VARIANT_BOOL* Cancel) {
//Write your code here
}
void GetPassWord(
IDispatch* sender,
LPCTSTR drawingname,
BSTR* password,
VARIANT_BOOL* Cancel) {
//Write your code here
}
void GenericError(
IDispatch* sender,
LPCTSTR Membername,
LPCTSTR errormessage) {
//Write your code here
}
void OnPolarTrackToolTip(
IDispatch* sender,
struct VectorDraw_Geometry::IgPoint* referencePoint,
struct VectorDraw_Geometry::IgPoint* currentPoint,
BSTR* tooltipText,
VARIANT_BOOL* Cancel) {
//Write your code here
}
void OnPolarTrackAngleValidate(
IDispatch* sender,
struct VectorDraw_Geometry::IgPoint* referencePoint,
struct VectorDraw_Geometry::IgPoint* currentPoint,
double DefaultEquality,
double* NewTrackingAngle,
VARIANT_BOOL* isValid,
VARIANT_BOOL* Cancel) {
//Write your code here
}
void OnObjectHandleChanged(
IDispatch* sender,
struct IvdObject* obj,
LPCTSTR ExistingHandleHEX) {
//Write your code here
}
void OnRequestLicVal(
IDispatch* sender,
LPCTSTR UrlFileName,
BSTR* LicenseValue) {
//Write your code here
}
void OnFilterOsnap(
IDispatch* sender,
struct IFilterOsnapEventArgs* args) {
//Write your code here
}
void LoadUnknownObjects(
const _variant_t& sender,
struct ILoadUnknownObjectsEventArgs* eventArgs) {
//Write your code here
}
void OnActionMouseMove(
IDispatch* sender,
struct VectorDraw_Actions::IBaseAction* action) {
//Write your code here
}
void OnFigureMouseOver(
IDispatch* sender,
struct IFigureMouseEventArgs* args) {
//Write your code here
}
void OnViewCubeClick(
IDispatch* sender,
struct IViewCubeClickArgs* args) {
//Write your code here
}
void FilterActionPoint(
IDispatch* sender,
IDispatch* action,
struct VectorDraw_Geometry::IgPoint** Pt) {
//Write your code here
}
void OnBeforeDocumentClear(
struct IvdDocument* sender) {
//Write your code here
}
~CvdDocumentEvents_Imp() {}
DECLARE_DISPATCH_MAP()
DECLARE_INTERFACE_MAP()
};
IMPLEMENT_DYNCREATE(CvdDocumentEvents_Imp, CCmdTarget)
BEGIN_DISPATCH_MAP(CvdDocumentEvents_Imp, CCmdTarget)
//Here we define all events of the VectorDraw_Professional::IvdDocumentEvents interface see DISP_FUNCTION_ID for details
DISP_FUNCTION_ID(CvdDocumentEvents_Imp, "OnIsValidOpenFormat", 60001, OnIsValidOpenFormat, VT_EMPTY, VTS_DISPATCH VTS_BSTR VTS_PBOOL)
DISP_FUNCTION_ID(CvdDocumentEvents_Imp, "OnGetOpenFileFilterFormat", 60003, OnGetOpenFileFilterFormat, VT_EMPTY, VTS_PBSTR)
DISP_FUNCTION_ID(CvdDocumentEvents_Imp, "OnGetSaveFileFilterFormat", 60004, OnGetSaveFileFilterFormat, VT_EMPTY, VTS_PBSTR)
DISP_FUNCTION_ID(CvdDocumentEvents_Imp, "OnUndoStoreValue", 60005, OnUndoStoreValue, VT_EMPTY, VTS_DISPATCH VTS_BOOL VTS_VARIANT VTS_BSTR VTS_VARIANT VTS_PBOOL)
DISP_FUNCTION_ID(CvdDocumentEvents_Imp, "OnAfterUndoStoreValue", 60006, OnAfterUndoStoreValue, VT_EMPTY, VTS_DISPATCH VTS_BOOL VTS_VARIANT VTS_BSTR VTS_VARIANT )
DISP_FUNCTION_ID(CvdDocumentEvents_Imp, "OnLoadUnknownFileName", 60007, OnLoadUnknownFileName, VT_EMPTY, VTS_DISPATCH VTS_BSTR VTS_PBOOL)
DISP_FUNCTION_ID(CvdDocumentEvents_Imp, "OnSaveUnknownFileName", 60008, OnSaveUnknownFileName, VT_EMPTY, VTS_DISPATCH VTS_BSTR VTS_PBOOL)
DISP_FUNCTION_ID(CvdDocumentEvents_Imp, "OnProgress", 60009, OnProgress, VT_EMPTY, VTS_DISPATCH VTS_I8 VTS_BSTR)
DISP_FUNCTION_ID(CvdDocumentEvents_Imp, "OnBeforeOpenDocument", 60010, OnBeforeOpenDocument, VT_EMPTY, VTS_DISPATCH )
DISP_FUNCTION_ID(CvdDocumentEvents_Imp, "OnAfterOpenDocument", 60011, OnAfterOpenDocument, VT_EMPTY, VTS_DISPATCH)
DISP_FUNCTION_ID(CvdDocumentEvents_Imp, "OnAfterNewDocument", 60012, OnAfterNewDocument, VT_EMPTY, VTS_DISPATCH)
DISP_FUNCTION_ID(CvdDocumentEvents_Imp, "OnOpenUrl", 60013, OnOpenUrl, VT_EMPTY, VTS_DISPATCH VTS_PBSTR VTS_PBOOL)
DISP_FUNCTION_ID(CvdDocumentEvents_Imp, "OnNoFileFind", 60022, OnNoFileFind, VT_EMPTY, VTS_DISPATCH VTS_PBSTR VTS_PBOOL)
DISP_FUNCTION_ID(CvdDocumentEvents_Imp, "OnResizeControlWindow", 60032, OnResizeControlWindow, VT_EMPTY, VTS_DISPATCH VTS_I4 VTS_I4 VTS_PBOOL)
DISP_FUNCTION_ID(CvdDocumentEvents_Imp, "OnScroll", 60033, OnScroll, VT_EMPTY, VTS_DISPATCH VTS_PR8 VTS_PR8 VTS_PBOOL)
DISP_FUNCTION_ID(CvdDocumentEvents_Imp, "OnPrompt", 60034, OnPrompt, VT_EMPTY, VTS_DISPATCH VTS_PBSTR)
DISP_FUNCTION_ID(CvdDocumentEvents_Imp, "GripSelectionModified", 60036, GripSelectionModified, VT_EMPTY, VTS_DISPATCH VTS_DISPATCH VTS_DISPATCH)
DISP_FUNCTION_ID(CvdDocumentEvents_Imp, "ActionLayoutActivated", 60037, ActionLayoutActivated, VT_EMPTY, VTS_DISPATCH VTS_DISPATCH VTS_DISPATCH)
DISP_FUNCTION_ID(CvdDocumentEvents_Imp, "GetDimensionText", 60040, GetDimensionText, VT_EMPTY, VTS_DISPATCH VTS_PBSTR)
DISP_FUNCTION_ID(CvdDocumentEvents_Imp, "ActionError", 60041, ActionError, VT_EMPTY, VTS_DISPATCH VTS_BSTR)
DISP_FUNCTION_ID(CvdDocumentEvents_Imp, "ActionEnd", 60042, ActionEnd, VT_EMPTY, VTS_DISPATCH VTS_BSTR)
DISP_FUNCTION_ID(CvdDocumentEvents_Imp, "ActionStart", 60043, ActionStart, VT_EMPTY, VTS_DISPATCH VTS_BSTR VTS_PBOOL)
DISP_FUNCTION_ID(CvdDocumentEvents_Imp, "GetPassWord", 60044, GetPassWord, VT_EMPTY, VTS_DISPATCH VTS_BSTR VTS_PBSTR VTS_PBOOL)
DISP_FUNCTION_ID(CvdDocumentEvents_Imp, "GenericError", 60045, GenericError, VT_EMPTY, VTS_DISPATCH VTS_BSTR VTS_BSTR)
DISP_FUNCTION_ID(CvdDocumentEvents_Imp, "OnPolarTrackToolTip", 60047, OnPolarTrackToolTip, VT_EMPTY, VTS_DISPATCH VTS_DISPATCH VTS_DISPATCH VTS_PBSTR VTS_PBOOL)
DISP_FUNCTION_ID(CvdDocumentEvents_Imp, "OnPolarTrackAngleValidate", 60048, OnPolarTrackAngleValidate, VT_EMPTY, VTS_DISPATCH VTS_DISPATCH VTS_DISPATCH VTS_R8 VTS_PR8 VTS_PBOOL VTS_PBOOL)
DISP_FUNCTION_ID(CvdDocumentEvents_Imp, "OnObjectHandleChanged", 60049, OnObjectHandleChanged, VT_EMPTY, VTS_DISPATCH VTS_DISPATCH VTS_BSTR)
DISP_FUNCTION_ID(CvdDocumentEvents_Imp, "OnRequestLicVal", 60050, OnRequestLicVal, VT_EMPTY, VTS_DISPATCH VTS_BSTR VTS_PBSTR)
DISP_FUNCTION_ID(CvdDocumentEvents_Imp, "OnFilterOsnap", 60051, OnFilterOsnap, VT_EMPTY, VTS_DISPATCH VTS_DISPATCH)
DISP_FUNCTION_ID(CvdDocumentEvents_Imp, "LoadUnknownObjects", 60052, LoadUnknownObjects, VT_EMPTY, VTS_VARIANT VTS_DISPATCH)
DISP_FUNCTION_ID(CvdDocumentEvents_Imp, "OnActionMouseMove", 60053, OnActionMouseMove, VT_EMPTY, VTS_DISPATCH VTS_UNKNOWN)
DISP_FUNCTION_ID(CvdDocumentEvents_Imp, "OnFigureMouseOver", 70001, OnFigureMouseOver, VT_EMPTY, VTS_DISPATCH VTS_DISPATCH)
DISP_FUNCTION_ID(CvdDocumentEvents_Imp, "OnViewCubeClick", 70151, OnViewCubeClick, VT_EMPTY, VTS_DISPATCH VTS_UNKNOWN)
DISP_FUNCTION_ID(CvdDocumentEvents_Imp, "FilterActionPoint", 70152, FilterActionPoint, VT_EMPTY, VTS_DISPATCH VTS_DISPATCH VTS_PDISPATCH)
DISP_FUNCTION_ID(CvdDocumentEvents_Imp, "OnBeforeDocumentClear", 80011, OnBeforeDocumentClear, VT_EMPTY, VTS_DISPATCH )
END_DISPATCH_MAP()
BEGIN_INTERFACE_MAP(CvdDocumentEvents_Imp, CCmdTarget)
INTERFACE_PART(CvdDocumentEvents_Imp, documenteventIID, Dispatch)
END_INTERFACE_MAP()
//code:
//suppose we already have a CVdraw object control created
CVdraw vdraw;
//get the default document of the control
VectorDraw_Professional::IvdDocumentPtr doc = vdraw->GetActiveDocument().GetWrapperObject();
vdraw->FreezeDrawEvents(0);
vdraw->FreezeEntityEvents(0);
vdraw->SetFreezeDrawEntityEvents(FALSE);
vdraw->FreezeEvents(FALSE);
vdraw->SetDisableMouseStockEvents(TRUE);
vdraw->SetUndoMode(TRUE);
doc->GlobalRenderProperties->SelectionPreview = VectorDraw_Render::SelectionPreviewFlags::SelectionPreviewFlags_ON;//for mouse over entity
doc->ViewCube->Display = VectorDraw_Professional::ViewCubeDisplayFlags::ViewCubeDisplayFlags_VisibleAll;
//create the connection event object
CvdDocumentEvents_Imp* eventsVd = new CvdDocumentEvents_Imp();
eventsVd->Connect(doc);
//Use drawing VDF control editor to open drawings create / edit entities to see how the CvdDocumentEvents_Imp method events are called
