Browse Source

CDR插件绘制圆形和矩形_版本01

蘭雅sRGB 6 months ago
parent
commit
31242a515b
5 changed files with 149 additions and 0 deletions
  1. 41 0
      base/callcdr.cpp
  2. 22 0
      base/exeCallCorelDRAW.cpp
  3. 42 0
      cdrapp.cpp
  4. 15 0
      cdrapp.h
  5. 29 0
      main.cpp

+ 41 - 0
base/callcdr.cpp

@@ -0,0 +1,41 @@
+#import "VGCoreAuto.tlb"
+#include <Windows.h>
+
+#define corel VGCore::IVGApplication
+using namespace VGCore;
+
+void Call_CorelDRAW();
+bool fill_red(corel *cdr);
+
+corel *cdr = NULL;
+int main() {
+  HRESULT hr = CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED);
+  if (SUCCEEDED(hr)) {
+    try {
+      Call_CorelDRAW();
+
+    } catch (_com_error &e) {
+      MessageBox(NULL, e.Description(), "Error", MB_ICONSTOP);
+    }
+    CoUninitialize();
+  }
+  return 0;
+}
+void Call_CorelDRAW() {
+  IVGApplicationPtr app(L"CorelDRAW.Application.16");  // 我的电脑 X6 正常 ; 毛子版 CorelDRAW 2020  绑定不上,没法使用
+  app->Visible = VARIANT_TRUE;
+
+  auto doc = app->ActiveDocument;
+  if (!doc)
+    doc = app->CreateDocument();
+
+  cdr = app;
+  fill_red(cdr);
+}
+
+bool fill_red(corel *cdr) {
+  auto sr = cdr->ActiveSelectionRange;
+  auto red = cdr->CreateCMYKColor(0, 100, 100, 0);
+  sr->ApplyUniformFill(red);
+  return true;
+}

+ 22 - 0
base/exeCallCorelDRAW.cpp

@@ -0,0 +1,22 @@
+#import "VGCoreAuto.tlb"     // 导入VGCoreAuto类型库: 这个文件在CorelDRAW 软件目录下可以找到
+int main() {
+  // 初始化COM库,使用多线程公寓模型
+  HRESULT hr = CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED);
+
+  if (SUCCEEDED(hr)) {
+    // 创建一个指向CorelDRAW应用程序的指针,经测试 CorelDRAW 16 可以正常绑定, 安装毛子版的 CorelDRAW 2020 无法正常绑定
+    VGCore::IVGApplicationPtr app(L"CorelDRAW.Application.16");
+
+    // 设置应用程序为可见状态
+    app->Visible = VARIANT_TRUE;
+    // 获取当前活动的文档,如果没有则创建一个新文档
+    auto doc = app->ActiveDocument;
+    if (!doc)
+      doc = app->CreateDocument();
+
+    // 清理COM库的初始化
+    CoUninitialize();
+  }
+
+  return 0;
+}

+ 42 - 0
cdrapp.cpp

@@ -0,0 +1,42 @@
+#include "cdrapp.h"
+#include <stdio.h>
+
+#define ZERO_4PC 0, 0, 0, 0
+bool test(corel* cdr){
+    cdr->ActiveDocument->Unit = cdrMillimeter;
+    double x, y;
+
+//  IVGShapePtr ActiveShape;
+    auto s = cdr->ActiveShape;
+
+//  建立矩形和圆形函数原型
+//  IVGShapePtr IVGLayer::CreateRectangle2 ( double x, double y, double Width, double Height, 
+//                      double RadiusUL, double RadiusUR, double RadiusLR, double RadiusLL );
+
+//  IVGShapePtr IVGLayer::CreateEllipse2 ( double CenterX, double CenterY, double Radius1, 
+//                   double Radius2, double StartAngle, double EndAngle, VARIANT_BOOL Pie );
+
+//  获取节点函数原型
+//  IVGNodePtr IVGNodes::GetItem ( long Index );
+//  IVGNodePtr IVGNodeRange::GetItem ( long Index );
+
+    for(auto i = 0; i < s->DisplayCurve->Nodes->Count; i++){
+        auto n = s->DisplayCurve->Nodes->Item[i+1];   
+
+        x = n->PositionX;  
+        y = n->PositionY;
+        printf("%f, %f\n", x, y);
+
+        auto sy = cdr->ActiveLayer->CreateEllipse2(x, y, 5, ZERO_4PC); 
+        sy->Outline->Color->RGBAssign(255, 0, 0);
+
+        auto sj = cdr->ActiveLayer->CreateRectangle2(x, y, 10, 10, ZERO_4PC); 
+        sj->Outline->Color->RGBAssign(0, 255, 0);
+        sj->PutCenterX(x);
+        sj->PutCenterY(y);
+
+    }
+
+    return true;
+}
+

+ 15 - 0
cdrapp.h

@@ -0,0 +1,15 @@
+#ifndef CDRAPP_H_INCLUDED
+#define CDRAPP_H_INCLUDED
+
+#import "VGCoreAuto.tlb"
+
+
+#define corel VGCore::IVGApplication
+using namespace VGCore;
+
+void Call_CorelDRAW();
+
+
+bool test(corel* cdr);
+
+#endif // CDRAPP_H_INCLUDED

+ 29 - 0
main.cpp

@@ -0,0 +1,29 @@
+#include "cdrapp.h"
+
+corel *cdr = NULL;
+int main() {
+  HRESULT hr = CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED);
+  if (SUCCEEDED(hr)) {
+    try {
+      Call_CorelDRAW();
+    } catch (_com_error &e) {
+      MessageBox(NULL, e.Description(), "Error", MB_ICONSTOP);
+    }
+    CoUninitialize();
+  }
+  return 0;
+}
+void Call_CorelDRAW() {
+  IVGApplicationPtr app(L"CorelDRAW.Application.16");  // 我的电脑 X6 正常 ; 毛子版 CorelDRAW 2020  绑定不上,没法使用
+  app->Visible = VARIANT_TRUE;
+
+  auto doc = app->ActiveDocument;
+  if (!doc)
+    doc = app->CreateDocument();
+
+  cdr = app;
+
+  //  调用CDR功能
+  test(cdr);
+
+}