Product : Engine, Version : 4.1.6.1028, ArticleID : 41023354

HowTo : Perform Zoom in/out and drag in c++

Article41023354
TypeHowTo
ProductEngine
Version4.1.6.1028
Date Added12/29/2003
Submitted byitzik
Keywords

Subject

Perform Zoom in/out and drag in c++

Summary

Perform Zoom in/out and drag c++

Solution

Follow an example of Drag And Drop Implementation
You need to add the event handlers: MouseDown to begin drag
and VDDragDropEx to control the way that VectorDraw accept Dragging objects (see help for more details).
 
 
#include "vdDocument.h"
#include "vdDataObject.h"
 
//press the RightMouse down and drag the objects to a VectorDraw Control or 
//  AutoCAD or Window Explorer or Microsoft Word document
void CvdrawForm::OnMouseDownVdstd1(short Button, short Shift, double x, double y) 
{
 // TODO: Add your control notification handler code here
 double x1,y1,z1,x2,y2,z2,pt[3];
 long i = 0;
 if(Button != 2) return;//Begin dragdrop with the RightMouse Down
 COleSafeArray extends = m_vdraw.GetActiveDocument().GetBoundExtends();
 extends.GetElement(&i,&x1);i++;
 extends.GetElement(&i,&y1);i++;
 extends.GetElement(&i,&x2);i++;
 extends.GetElement(&i,&y2);i++;
 extends.GetElement(&i,&z1);i++;
 extends.GetElement(&i,&z2);
 pt[0] = (x1+x2) / 2.0;
 pt[1] = (y1+y2) / 2.0;
 pt[2] = (z1+z2) / 2.0;
 COleSafeArray basepoint ;
 basepoint.CreateOneDim(VT_R8,3,pt);
 m_vdraw.GetCommandAction().DoDragDrop(COleVariant("ALL"),//begin drag with all entities
                                    1,//VdDropEffect_Copy
                                          basepoint,//basepoint is the midle point of selected entities
            100,100,//Image width and Image height for Bitmap Droping contenairs(World document for example)
            3/*+1 support drop images
                                             +2 support drop file
            */
            );
 /*Note: You can drop it into a Windows Explorer as a dwf file.
         You can drop it into an AutoCAD Document as Blockreference
   You can drop it into a Microsoft World Document as Bitmap Image
   You can drop it into a VectorDraw Document  as Blockreference
    */
 
         
 
}
 

//example drag and drop files from Windows explorer on VectorDraw control
//this will also accept drag and drop between  VectorDraw controls
void CvdrawForm::OnVDDragDropExVdstd1(LPDISPATCH DataObject, double Xpos, double Ypos, double ZPos, long DropEffect, short FAR* Cancel) 
{
 // TODO: Add your control notification handler code here
 *Cancel = 1;//we only accept dropping files and cancel the default implementation
 CvdDataObject data;
 data.AttachDispatch(DataObject,FALSE);
 //sereach the dataObject is a File is in the Draging Data
 //example drag and drop a file from the Windows Explorer
 long itempos = data.FindItemType(CF_HDROP);
 if(itempos == 0xffff) return;
    long itemtype;
 COleSafeArray Dropfiles = data.GetItem(itempos,&itemtype);//itemtype sould be CF_HDROP = 15
 if(Dropfiles.vt == VT_EMPTY) return;
 long i = 0;
 BSTR bstrFile = NULL;
 CString filename=_T("");
 //we only get the first selected file
 Dropfiles.GetElement(&i,&bstrFile);
 filename = bstrFile;
 //check to see if is a supported file format
 if(!(filename.Right(4).CompareNoCase(_T(".dwg")) == 0  ||
  filename.Right(4).CompareNoCase(_T(".dxf")) == 0  ||
  filename.Right(4).CompareNoCase(_T(".vdi")) == 0  ||
  filename.Right(4).CompareNoCase(_T(".vdf")) == 0 
  ))
  return;
 
 //insert the file as block in the current cursor position;
 COleVariant pt = m_vdraw.GetCursorPos();
 m_vdraw.GetCommandAction().CmdInsert(COleVariant(filename),pt,COleVariant(1.0),COleVariant(1.0),COleVariant(0.0));
 m_vdraw.GetCommandAction().Zoom(COleVariant(_T("e")),COleVariant(_T("")),COleVariant(_T("")));
 
}
 
Follow an Example of Zoom in and out
Note: Also the VectorDraw by default can zoom in out with the a mouse wheel scrolling.
void CvdrawForm::OnViewZoomin() 
{
 // TODO: Add your command handler code here
 m_vdraw.GetCommandAction().Zoom(COleVariant(_T("S")),COleVariant(1.0/0.9),COleVariant(_T("")));
}
 
void CvdrawForm::OnViewZoomout() 
{
 // TODO: Add your command handler code here
 m_vdraw.GetCommandAction().Zoom(COleVariant(_T("S")),COleVariant(0.9),COleVariant(_T("")));
}