Corel Draw


Tip
Corel Draw include Visual Basic for Applications (VSA) to create macros. You will find VSA under the Tools menu. You may save a macro and then review it using VSA in the recorded macros section to know what command were executed.
Corel Draw incluye Visual Basic para Aplicaciones (VSA) para crear macros. Usted encontrará VSA en el menú de herramientas. Usted puede grabar un macro y luego verlo en VSA en la sección de los macro grabados para conocer los comandos ejecutados.

Tip
Use Corel Draw web site to know more know more about COM and Corel.

https://community.coreldraw.com/sdk/api/draw/18/c/Application
Use el sitio web de Corel Draw para saber más de COM y Corel

https://community.coreldraw.com/sdk/api/draw/18/c/Application

Problem 1
Create a Dialog application using Wintempla called CorelDw to draw an ellipse using Corel Draw.
Cree una aplicación de Diálogo usando Wintempla llamada CorelDw para dibujar una elipse usando Corel Draw.

EllipseLateBinding

CorelDw.h
#pragma once //______________________________________ CorelDw.h
#include "Resource.h"
class CorelDw: public Win::Dialog
{
public:
     CorelDw()
     {
          ::CoInitialize(NULL);
     }
     ~CorelDw()
     {
          ::CoUninitialize();
     }
     ...
};

CorelDw.cpp
...
void CorelDw::Window_Open(Win::Event& e)
{
     Com::Object Application;
     Com::Object Document;
     Com::Object ActiveLayer;
     Com::Object ShapeEllipse;
     _variant_t result;
     try
     {
          Application.CreateInstance(L"CorelDRAW.Application.13", false);
          Application.Put(L"Visible", true);
          Application.Method(L"CreateDocument", Document);
          //______________________________________________________ Get The Active Layer
          Document.Get(L"ActiveLayer", ActiveLayer);
          //______________________________________________________ Draw an Ellipse
          ActiveLayer.Method(L"CreateEllipse2",
               1.784543, //CenterX
               9.548469, //CenterY
               1.091268, //Radius1
               -1.030642, //Radius2
               90.0, //StartAngle,
               90.0, //EndAngle
               false, //Pie
               ShapeEllipse);     
          //Com::Container::DisplayInterfaceFunctions(hWnd, ActiveLayer);
     }
     catch(Com::Exception excep)
     {
          excep.Display(hWnd, L"CorelDw");
          Application.Method(L"Quit");
     }
}


Tip
Corel Draw can be browse by adding in the Object Browser: Corel - CorelDRAW 13.0 Library and Corel - Vector Graphics Core 13.0 Type Library.
Corel Draw puede explorarse agregando en el Explorador de Objectos: Corel - CorelDRAW 13.0 Library y Corel - Vector Graphics Core 13.0 Type Library.

Problem 2
Create a Dialog application using Wintempla called ImportCorelDraw to Draw an ellipse with Corel Draw with #import.
Cree una aplicación de Diálogo usando Wintempla llamada ImportCorelDraw para dibujar una elise con Corel Draw y #import.

stdafx.h
...
// To generate vgcoreauto.tlh, vgcoreauto.tli
#import "C:\\Program Files (x86)\\Corel\\CorelDRAW Graphics Suite 13\\Programs\VGCoreAuto.tlb" \
     rename("FindWindow", "FindWindowx") \
     rename("CopyFile", "CopyFilex") \
     rename("GetCommandLine", "GetCommandLinex")

// To generate coreldraw.tlh, coreldraw.tli
#import "C:\\Program Files (x86)\\Corel\\CorelDRAW Graphics Suite 13\\Programs\\CorelDraw.tlb" \
     rename("FindWindow", "FindWindowx")


ImportCorelDraw.h
#pragma once //______________________________________ ImportCorelDraw.h
#include "Resource.h"
#include "vgcoreauto.tlh"
#include "coreldraw.tlh"
class ImportCorelDraw: public Win::Dialog
{
public:
     ImportCorelDraw()
     {
          ::CoInitialize(NULL);
     }
     ~ImportCorelDraw()
     {
          ::CoUninitialize();
     }
protected:
     ...
};

ImportCorelDraw.cpp
...
void ImportCorelDraw::Window_Open(Win::Event& e)
{
     CorelDRAW::IDrawApplicationPtr Application;
     CorelDRAW::IDrawDocumentPtr Document;
     CorelDRAW::IDrawLayerPtr ActiveLayer;
     HRESULT hr;
     Com::Exception ex;

     try
     {
          //__________________________________________________________ CorelDRAW.Application
          hr = Application.CreateInstance(L"CorelDRAW.Application.13");
          ex.ok(L"Application.CreateInstance", hr);
          //___________________________________________________________ Application->put_Visible
          hr = Application->put_Visible(VARIANT_TRUE);
          ex.ok(L"Application->put_Visible", hr);
          //___________________________________________________________ Application->CreateDocument
          Document = Application->CreateDocument();
          //___________________________________________________ Get The Active Layer
          ActiveLayer = Application->GetActiveLayer();
          ActiveLayer->CreateEllipse2(1.784543, 9.548469, 1.091268, -1.030642, 90.0, 90.0, false);
     }
     catch(Com::Exception& excep)
     {
          excep.Display(hWnd, L"ImportCorelDraw");
     }
     catch(_com_error excep)
     {
          Com::Exception::Display(hWnd, excep, L"ImportCorelDraw");
     }
}


Tip
The following code illustrates how to open a file in Corel Draw XVII and export the file to PNG.
El código siguiente ilustra como abrir un archivo en Corel Draw XVII y exportar el archivo a PNG.

Program.cpp
//_______________________________________________________ Importing Corel Draw
VGCore::IVGApplicationPtr Application;
VGCore::IVGDocumentPtr Document;
HRESULT hr;
Com::Exception ex;
_bstr_t inputFilename = L"C:\\selo\\test.cdr";
_bstr_t outputFilename(L"C:\\selo\\test.png");
long imageWidth = 400;
long imageHeight = 300;
long resolutionX = 300;
long resolutionY = 300;
VGCore::ICorelExportFilterPtr corelExportFilter;

try
{
     //__________________________________________________________ CorelDRAW.Application
     hr = Application.CreateInstance(L"CorelDRAW.Application.17");
     ex.ok(L"Application.CreateInstance", hr);
     //___________________________________________________________ Application->put_Visible
     hr = Application->put_Visible(VARIANT_TRUE);
     ex.ok(L"Application->put_Visible", hr);
     //___________________________________________________________ Application->CreateDocument
     Document = Application->OpenDocument(inputFilename, 0);
     //___________________________________________________________ Document->ExportBitmap
     corelExportFilter = Document->ExportBitmap(outputFilename, VGCore::cdrPNG, VGCore::cdrCurrentPage, VGCore::cdrRGBColorImage,
          imageWidth, imageHeight, resolutionX, resolutionY, VGCore::cdrSupersampling, VARIANT_FALSE, VARIANT_TRUE, VARIANT_FALSE,
          VARIANT_FALSE, VGCore::cdrCompressionNone, NULL, NULL);
     if (corelExportFilter == NULL)
     {
          ex.ok(L"Document->ExportBitmap", hr);
     }
     corelExportFilter->Finish();

     Application->Quit();
}
catch (Com::Exception& excep)
{
     excep.Display(hWnd, L"ImportCorelDraw");
     Application->Quit();
}
catch (_com_error excep)
{
     Com::Exception::Display(hWnd, excep, L"ImportCorelDraw");
     Application->Quit();
}


Program.cpp
//_______________________________________________________ Without Importing Corel Draw
Com::Object Application;
Com::Object Document;
Com::Object ActiveLayer;
Com::Object ShapeEllipse;
Com::Object SaveAsOptions;
_variant_t result;
_variant_t inputFilename(L"C:\\selo\\test.cdr");
_variant_t outputFilename(L"C:\\selo\\test.png");
_variant_t cdrBMP = 769;
_variant_t cdrGIF = 773;
_variant_t cdrJPG = 774;
_variant_t cdrPNG = 802;
_variant_t cdrCurrentPage = 1;
_variant_t cdrRGBColorImage = 4;
_variant_t imageWidth = 400;
_variant_t imageHeight = 300;
_variant_t dpiX = 300;
_variant_t dpiY = 300;
_variant_t cdrSupersampling = 2;
_variant_t Dithered = false;
_variant_t Transparent = true;
_variant_t UseColorProfile = false;
_variant_t MaintainLayers = false;
_variant_t cdrCompressionNone = 0; // BMP
_variant_t cdrCompressionLZW = 1; // GIF
_variant_t cdrCompressionPNG = 7; // PNG
_variant_t cdrCompressionJPEG = 8; // JPG
//_____________________________________ Palette Options
Com::Object PaletteOptions;
_variant_t vtPaletteOptions;
vtPaletteOptions.vt = VT_BYREF | VT_DISPATCH;
vtPaletteOptions.ppdispVal = &(PaletteOptions.dispatch.GetInterfacePtr());
//_____________________________________ Export Area
Com::Object ExportArea;
_variant_t vtExportArea;
vtExportArea.vt = VT_BYREF | VT_DISPATCH;
vtExportArea.ppdispVal = &(ExportArea.dispatch.GetInterfacePtr());
//_____________________________________ Export Result
Com::Object CorelExportFilter;
_variant_t vtCorelExportFilter;
vtCorelExportFilter.vt = VT_BYREF | VT_DISPATCH;
vtCorelExportFilter.ppdispVal = &(CorelExportFilter.dispatch.GetInterfacePtr());

try
{
     Application.CreateInstance(L"CorelDRAW.Application.17", false);
     Application.Put(L"Visible", true);
     Application.Method(L"OpenDocument", inputFilename, Document);
     Document.Method(L"ExportBitmap", outputFilename, cdrPNG, cdrCurrentPage, cdrRGBColorImage, imageWidth, imageHeight, dpiX, dpiY, cdrSupersampling,
          Dithered, Transparent, UseColorProfile, MaintainLayers, cdrCompressionNone, vtPaletteOptions, vtExportArea, CorelExportFilter);
     //
     CorelExportFilter.Method(L"Finish");
     Application.Method(L"Quit");
}
catch (Com::Exception excep)
{
     excep.Display(hWnd, L"IconCreator");
     Application.Method(L"Quit");
}


Tip
The following code illustrates how to open a file in Corel Draw XVII and export the file to JPG.
El código siguiente ilustra como abrir un archivo en Corel Draw XVII y exportar el archivo a JPG.

Program.cpp
//_______________________________________________________ Without Importing Corel Draw
Com::Object Application;
Com::Object Document;
Com::Object ActiveLayer;
Com::Object ShapeEllipse;
Com::Object SaveAsOptions;
_variant_t result;
_variant_t inputFilename(L"C:\\selo\\test.cdr");
_variant_t outputFilename(L"C:\\selo\\test.jpg");
_variant_t cdrBMP = 769;
_variant_t cdrGIF = 773;
_variant_t cdrJPG = 774;
_variant_t cdrPNG = 802;
_variant_t cdrCurrentPage = 1;
_variant_t cdrRGBColorImage = 4;
_variant_t dpiX = 300;
_variant_t dpiY = 300;
_variant_t cdrSupersampling = 2;
_variant_t Dithered = false;
_variant_t Transparent = true;
_variant_t UseColorProfile = false;
_variant_t MaintainLayers = false;
_variant_t cdrCompressionNone = 0; // BMP
_variant_t cdrCompressionLZW = 1; // GIF
_variant_t cdrCompressionPNG = 7; // PNG
_variant_t cdrCompressionJPEG = 8; // JPG
//_____________________________________ Palette Options
Com::Object PaletteOptions;
_variant_t vtPaletteOptions;
vtPaletteOptions.vt = VT_BYREF | VT_DISPATCH;
vtPaletteOptions.ppdispVal = &(PaletteOptions.dispatch.GetInterfacePtr());
//_____________________________________ Export Area
Com::Object ExportArea;
_variant_t vtExportArea;
vtExportArea.vt = VT_BYREF | VT_DISPATCH;
vtExportArea.ppdispVal = &(ExportArea.dispatch.GetInterfacePtr());
//_____________________________________ Export Result
Com::Object CorelExportFilter;
_variant_t vtCorelExportFilter;
vtCorelExportFilter.vt = VT_BYREF | VT_DISPATCH;
vtCorelExportFilter.ppdispVal = &(CorelExportFilter.dispatch.GetInterfacePtr());

try
{
     Application.CreateInstance(L"CorelDRAW.Application.17", false);
     Application.Put(L"Visible", true);
     Application.Method(L"OpenDocument", inputFilename, Document);
     Document.Method(L"ExportBitmap", outputFilename, cdrJPG, cdrCurrentPage, cdrRGBColorImage, 0, 0, dpiX, dpiY, cdrSupersampling,
          Dithered, Transparent, UseColorProfile, MaintainLayers, cdrCompressionJPEG, vtPaletteOptions, vtExportArea, CorelExportFilter);
     //
     //CorelExportFilter.Put(L"Optimized", true); // GIF
     CorelExportFilter.Put(L"Compression", 0);
     CorelExportFilter.Method(L"Finish");
     Application.Method(L"Quit");
}
catch (Com::Exception excep)
{
     excep.Display(hWnd, L"Program");
     Application.Method(L"Quit");
}


Corel Photo Paint

The code illustrates how to create a new Corel Photo Paint document from the clipboard and export the image as a BMP file using IDispatch.
El código ilustra cómo crear un nuevo documento de Corel Photo Paint desde el portapapeles y exportar la imagen a un archivo BMP usando IDispatch.

BmpCreator.h
class BmpCreator: public Win::Dialog
{
public:
     BmpCreator()
     {
          ::CoInitialize(NULL);
     }
     ~BmpCreator()
     {
          ::CoUninitialize();
     }
     ...
};


BmpCreator.cpp
...
void BmpCreator::Window_Open(Win::Event& e)
{
     HRESULT hr;
     Com::Object Application;
     Com::Object Document;
     _variant_t vtFileName(L"C:\\image.bmp");
     _variant_t vtFilter = 769; //cdrBMP = 769
     //_______________________________ Options
     Com::Object Options;
     _variant_t vtOptions;
     vtOptions.vt = VT_BYREF | VT_DISPATCH;
     vtOptions.ppdispVal = &(Options.dispatch.GetInterfacePtr());
     //_______________________________ PaletteOptions
     Com::Object PaletteOptions;
     _variant_t vtPaletteOptions;
     vtPaletteOptions.vt = VT_BYREF | VT_DISPATCH;
     vtPaletteOptions.ppdispVal = &(PaletteOptions.dispatch.GetInterfacePtr());
     //_______________________________ CorelExportFilter
     Com::Object CorelExportFilter;
     _variant_t vtCorelExportFilter;
     _variant_t vtFalse(false);

     try
     {
          Application.CreateInstance(L"CorelPHOTOPAINT.Application.17", false);
          //_____________________________________________________ CreateDocumentFromClipboard
          Application.Method(L"CreateDocumentFromClipboard", Document);
          //Com::Container::DisplayInterfaceFunctions(hWnd, Application);
          //Com::Container::DisplayInterfaceFunctions(hWnd, Document);
          hr = Document.Method(L"Export", vtFileName, vtFilter, vtOptions, vtPaletteOptions, vtCorelExportFilter);
          CorelExportFilter.dispatch = vtCorelExportFilter.pdispVal;
          CorelExportFilter.RefreshFuncInfo();
          //Com::Container::DisplayInterfaceFunctions(hWnd, CorelExportFilter);
          CorelExportFilter.Method(L"Finish");
          Document.Put(L"Dirty", vtFalse);
          Application.Method(L"Quit");
     }
     catch (Com::Exception excep)
     {
          excep.Display(hWnd, L"BmpCreator");
          Application.Method(L"Quit");
     }
}


Tip
The following code illustrates how to open a Corel Photo Paint file.
El código siguiente ilustra como abrir un archivo de Corel Photo Paint.

Program.h
void Program::Window_Open(Win::Event& e)
{
     Com::Object Application;
     Com::Object Document;
     _variant_t vtInputFileName(L"C:\\Users\\Jhon.cpt");
     _variant_t vtOpenDocumentFilter = 0; // cdrAutoSense = 0
     _variant_t vtOpenDocumentLoadMode = 0; // pntLoadAll = 0

     try
     {
          Application.CreateInstance(L"CorelPHOTOPAINT.Application.17", false);
          Application.Put(L"Visible", vtTrue);
          Application.Method(L"OpenDocument",
               vtInputFileName,
               vtOpenDocumentFilter, // cdrAutoSense = 0
               vtOpenDocumentLoadMode, // pntLoadAll = 0
               0, //__int32 Left
               0, // __int32 Top
               0, // __int32 Width
               0, // __int32 Height
               72, // __int32 DpiX
               72, // __int32 DpiY,
               1, // __int32 StartFrame
               1, //__int32 EndFrame,
               Document); // Com::Object Document;
          Document.Method(L"Activate");

          Com::Container::DisplayInterfaceFunctions(hWnd, Document);
     }
     catch (Com::Exception excep)
     {
          excep.Display(hWnd, L"Program");
          Application.Method(L"Quit");
     }
}


Tip
The following code illustrates how to get CorelScript to execute commands.
El código siguiente ilustra cómo obtener CorelScript para ejecutar comandos.

Program.h
void Program::Window_Open(Win::Event& e)
{
     Com::Object Application;
     Com::Object Document;
     Com::Object CorelScript;
     _variant_t vtInputFileName(L"C:\\Users\\Jhon.cpt");
     _variant_t vtOpenDocumentFilter = 0; // cdrAutoSense = 0
     _variant_t vtOpenDocumentLoadMode = 0; // pntLoadAll = 0
     _variant_t vtResult;

     try
     {
          Application.CreateInstance(L"CorelPHOTOPAINT.Application.17", false);
          Application.Put(L"Visible", vtTrue);
          Application.Method(L"OpenDocument",
               vtInputFileName,
               vtOpenDocumentFilter, // cdrAutoSense = 0
               vtOpenDocumentLoadMode, // pntLoadAll = 0
               0, //__int32 Left
               0, // __int32 Top
               0, // __int32 Width
               0, // __int32 Height
               72, // __int32 DpiX
               72, // __int32 DpiY,
               1, // __int32 StartFrame
               1, //__int32 EndFrame,
               Document); // Com::Object Document;
          Document.Method(L"Activate");
          Application.Method(L"CorelScript", CorelScript);
          Com::Container::DisplayInterfaceFunctions(hWnd, CorelScript);
          CorelScript.Method(L"ImageHSL",
                    0, //__int32 Hue,
                    -100, // __int32 Saturation,
                    50,//__int32 Lightness
                    vtResult);
          CorelScript.Method(L"EndColorEffect");
     }
     catch (Com::Exception excep)
     {
          excep.Display(hWnd, L"Program");
          Application.Method(L"Quit");
     }
}


Visual Basic

You can use Visual Basic inside Corel Photo Paint to execute a program. From the menu Tools > Macros > Macro Manager .
Usted puede usar Visual Basic dentro Corel Photo Paint para ejecutar un programa. Desde el menú Tools > Macros > Macro Manager .

CorelScript

You can run a Corel Script inside Corel Photo Paint, from the menu Windows > Docker > Recorder .
Usted puede ejecutar un Corel Script dentro Corel Photo Paint, desde el menú Windows > Docker > Recorder .

Tip
It is also possible to use #import to import Corel Photo Paint as illustrated below.
Es posible usar #import para importar Corel Photo Paint cómo se ilustra debajo.

stdafx.h
...
#import "C:\\Program Files\\Corel\\CorelDRAW Graphics Suite X7\\Programs64\\CorelPP.tlb" \
     rename("GetCommandLine", "GetCommandLineX")


BmpCreator.h
class BmpCreator: public Win::Dialog
{
public:
     BmpCreator()
     {
          ::CoInitialize(NULL);
     }
     ~BmpCreator()
     {
          ::CoUninitialize();
     }
     ...
};


BmpCreator.cpp
...

void BmpCreator::Window_Open(Win::Event& e)
{
     PHOTOPAINT::IPaintApplicationPtr Application;
     PHOTOPAINT::IPaintDocumentPtr Document;
     PHOTOPAINT::IStructSaveOptionsPtr SaveOptions = NULL;
     PHOTOPAINT::IStructPaletteOptionsPtr PaletteOptions = NULL;
     PHOTOPAINT::ICorelExportFilterPtr ExportFilter = NULL;

     HRESULT hr;
     Com::Exception ex;
     try
     {
          //__________________________________________ PHOTOPAINT.Application
          hr = Application.CreateInstance(L"CorelPHOTOPAINT.Application.17");
          ex.ok(L"Application.CreateInstance", hr);
          //___________________________________________ Application.Visible
          hr = Application->put_Visible(VARIANT_TRUE);
          ex.ok(L"Application->put_Visible", hr);
          //____________________________________________ CreateDocumentFromClipboard
          Document = Application->CreateDocumentFromClipboard();
          if (Document == NULL) ex.ThrowNullPointer(L"Application->CreateDocumentFromClipboard");
          //____________________________________________ Export
          ExportFilter = Document->Export(_bstr_t(L"C:\\my_image.bmp"), PHOTOPAINT::cdrFilter::cdrBMP, SaveOptions, PaletteOptions);
          if (ExportFilter == NULL) ex.ThrowNullPointer(L"Document->Export");
          //___________________________________________ ExportFilter.Finish()
          hr = ExportFilter->Finish();
          ex.ok(L"ExportFilter->Finish", hr);
          //___________________________________________
     }
     catch(Com::Exception& excep)
     {
          excep.Display(hWnd, L"BmpCreator");
     }
     catch(_com_error excep)
     {
          Com::Exception::Display(hWnd, excep, L"BmpCreator");
     }
}

© Copyright 2000-2021 Wintempla selo. All Rights Reserved. Jul 22 2021. Home