Forráskód Böngészése

蘭雅CPG 异形群组版 增加窗口扩展和最小化按钮

蘭雅sRGB 2 hónapja
szülő
commit
175b6adcd7

+ 37 - 4
09_BoundaryGroup/BoundaryGroup.cpp

@@ -1,6 +1,7 @@
 #include "cdrapp.h"
 #include <cerrno>
 #include <cmath>
+#include <cstddef>
 
 bool isDPCurve(IVGShapePtr s) {
   auto dpc = (s->Type == cdrRectangleShape) || (s->Type == cdrEllipseShape) ||
@@ -40,6 +41,7 @@ bool isIntWith(corel *cdr, IVGShape *s1, IVGShape *s2) {
     auto scp = CreateBoundary(cdr, s1);
     isIn = scp->GetDisplayCurve()->IntersectsWith(s2->GetDisplayCurve());
     scp->Delete();
+
   } else {
     auto scp = CreateBoundary(cdr, s1);
     auto scp2 = CreateBoundary(cdr, s2);
@@ -68,6 +70,7 @@ bool BoundaryGroup(corel *cdr, IVGShapeRange *sr, IVGShapeRange *srs) {
   BoundingBox box, bound_box;
   double x, y;
   int OnSh = 0;
+  auto red = cdr->CreateCMYKColor(0, 100, 100, 0);
 
   // 处理文字和影响的物件
   auto txtbox = cdr->CreateShapeRange();
@@ -83,11 +86,35 @@ bool BoundaryGroup(corel *cdr, IVGShapeRange *sr, IVGShapeRange *srs) {
     sr->AddRange(txtbox);
   }
 
+
+  // auto stmp = sr->CreateBoundary(0, 0, true, false); // 建立异性边界物件
+  // auto ef1 = stmp->CreateContour(
+  //     cdrContourOutside, 0.2, 1, cdrDirectFountainFillBlend, red, NULL, NULL, 0,
+  //     0, cdrContourSquareCap, cdrContourCornerMiteredOffsetBevel, 15);
+
+  // auto bounds = ef1->Separate();
+  // stmp->Delete();
+  // // bounds->SetOutlineProperties(0.076, NULL, cdr->CreateCMYKColor(100, 50, 0,
+  // // 0), NULL, NULL, cdrUndefined,  cdrUndefined, cdrOutlineUndefinedLineCaps,
+  // // cdrOutlineUndefinedLineJoin, NULL, NULL, NULL, NULL, NULL);
+
+  // auto sbox = bounds->BreakApartEx();
+  // sbox->ApplyUniformFill(red);
+
+
   // 建立辅助的异性边界物件,需要填充颜色,搞了半天才搞定
   auto bounds = sr->CreateBoundary(0, 0, true, false); // 建立异性边界物件
   bounds->Fill->UniformColor->RGBAssign(255, 0, 0);    // 填充红色
   auto sbox = bounds->BreakApartEx(); // 把边界 拆分为多个边界 用来分组
 
+  if (sbox->Count > 2) {
+    //  VGCore::IVGShapeRange::Sort ( _bstr_t CompareExpression, long
+    //  StartIndex, long EndIndex, const _variant_t & Data );
+    sbox->Sort(
+      _bstr_t(
+            "@shape1.width * @shape1.height > @shape2.width * @shape2.height"),
+        1, sbox->Count, _variant_t());
+  }
 
   // 删除文字添加的方框
   if (sr_text->Count > 0) {
@@ -98,7 +125,7 @@ bool BoundaryGroup(corel *cdr, IVGShapeRange *sr, IVGShapeRange *srs) {
   // 按照边界框异形范围进行分组群组
   auto srgp = cdr->CreateShapeRange();
 
-  for (int k = 0; k < sbox->Count; k++) {
+  for (int k = 0; k < sbox->Count && sr->Count; k++) {
     sbox->Shapes->Item[k + 1]->GET_BOUNDING_BOX(bound_box);
 
     for (int i = 0; i < sr->Count; i++) {
@@ -114,14 +141,20 @@ bool BoundaryGroup(corel *cdr, IVGShapeRange *sr, IVGShapeRange *srs) {
           srgp->Add(sh);
       }
     }
+
     // 从Range中移除已分组的图形
     sr->RemoveRange(srgp);
-    srs->Add(srgp->Group());
+    if (srgp->Count > 1) {
+      srs->Add(srgp->Group());
+    } else {
+      srs->AddRange(srgp);
+    }
     srgp->RemoveAll();
   }
 
   // 删除辅助的异性边界物件
-  sbox->Delete();
+  if(!debug_flg)
+    sbox->Delete();
   return true;
 }
 
@@ -146,7 +179,7 @@ void run_BoundaryGroup(corel *cdr) {
 
   if (cnt > 300) {
     // 调用矩形分组,分布执行异形群组
-    if (BoxGrouping(cdr, sr, sr_box, 1.0)) {
+    if (BoxGrouping(cdr, sr, sr_box, 0.1)) {
       for (int i = 0; i < sr_box->Count; i++) {
         auto s = sr_box->Shapes->Item[i + 1];
         if (!s->IsSimpleShape) {

+ 282 - 249
09_BoundaryGroup/ToolsBox.cpp

@@ -1,293 +1,326 @@
 #include "cdrapi.h"
 #include "cdrapp.h"
+#include "resource.h"
 #include <stdio.h>
 #include <windows.h>
-#include "resource.h"
+
 
 corel *cdr = NULL;
 static HINSTANCE g_hResource = NULL;
+bool debug_flg = false; // 调试->高级模式
 char infobuf[256] = {0};
-BOOL APIENTRY DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
-{
-    if (fdwReason == DLL_PROCESS_ATTACH) {
-        g_hResource = (HINSTANCE)hinstDLL;
-    }
-    return TRUE;
+BOOL APIENTRY DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) {
+  if (fdwReason == DLL_PROCESS_ATTACH) {
+    g_hResource = (HINSTANCE)hinstDLL;
+  }
+  return TRUE;
 }
 
-class ToolsBoxPlugin : public VGCore::IVGAppPlugin
-{
+class ToolsBoxPlugin : public VGCore::IVGAppPlugin {
 private:
+  volatile ULONG m_ulRefCount;
+  long m_lCookie;
 
-    volatile ULONG m_ulRefCount;
-    long m_lCookie;
-
-    static intptr_t CALLBACK DlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
-    void OpenToolsBox();
-
+  static intptr_t CALLBACK DlgProc(HWND hDlg, UINT uMsg, WPARAM wParam,
+                                   LPARAM lParam);
+  void OpenToolsBox();
 
 public:
-    ToolsBoxPlugin();
-    VGCore::IVGApplication* m_pApp;
+  ToolsBoxPlugin();
+  VGCore::IVGApplication *m_pApp;
 
-// IUnknown
+  // IUnknown
 public:
-    STDMETHOD(QueryInterface)(REFIID riid, void** ppvObject);
-    STDMETHOD_(ULONG, AddRef)(void) { return ++m_ulRefCount; }
-    STDMETHOD_(ULONG, Release)(void)
-    {
-        ULONG ulCount = --m_ulRefCount;
-        if (ulCount == 0) {
-            delete this;
-        }
-        return ulCount;
+  STDMETHOD(QueryInterface)(REFIID riid, void **ppvObject);
+  STDMETHOD_(ULONG, AddRef)(void) { return ++m_ulRefCount; }
+  STDMETHOD_(ULONG, Release)(void) {
+    ULONG ulCount = --m_ulRefCount;
+    if (ulCount == 0) {
+      delete this;
     }
+    return ulCount;
+  }
 
-// IDispatch
+  // IDispatch
 public:
-    STDMETHOD(GetTypeInfoCount)(UINT* pctinfo) { return E_NOTIMPL; }
-    STDMETHOD(GetTypeInfo)(UINT iTInfo, LCID lcid, ITypeInfo** ppTInfo) { return E_NOTIMPL; }
-    STDMETHOD(GetIDsOfNames)(REFIID riid, LPOLESTR* rgszNames, UINT cNames, LCID lcid, DISPID* rgDispId) { return E_NOTIMPL; }
-    STDMETHOD(Invoke)(DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS* pDispParams, VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr);
-
-// IVGAppPlugin
+  STDMETHOD(GetTypeInfoCount)(UINT *pctinfo) { return E_NOTIMPL; }
+  STDMETHOD(GetTypeInfo)(UINT iTInfo, LCID lcid, ITypeInfo **ppTInfo) {
+    return E_NOTIMPL;
+  }
+  STDMETHOD(GetIDsOfNames)
+  (REFIID riid, LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId) {
+    return E_NOTIMPL;
+  }
+  STDMETHOD(Invoke)
+  (DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags,
+   DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExcepInfo,
+   UINT *puArgErr);
+
+  // IVGAppPlugin
 public:
-    STDMETHOD(raw_OnLoad)(VGCore::IVGApplication* Application);
-    STDMETHOD(raw_StartSession)();
-    STDMETHOD(raw_StopSession)();
-    STDMETHOD(raw_OnUnload)();
-
+  STDMETHOD(raw_OnLoad)(VGCore::IVGApplication *Application);
+  STDMETHOD(raw_StartSession)();
+  STDMETHOD(raw_StopSession)();
+  STDMETHOD(raw_OnUnload)();
 };
 
-ToolsBoxPlugin::ToolsBoxPlugin()
-{
-    m_pApp = NULL;
-    m_lCookie = 0;
-    m_ulRefCount = 1;
+ToolsBoxPlugin::ToolsBoxPlugin() {
+  m_pApp = NULL;
+  m_lCookie = 0;
+  m_ulRefCount = 1;
 }
 
-STDMETHODIMP ToolsBoxPlugin::QueryInterface(REFIID riid, void** ppvObject)
-{
-    HRESULT hr = S_OK;
-    m_ulRefCount++;
-    if (riid == IID_IUnknown) {
-        *ppvObject = (IUnknown*)this;
-    } else if (riid == IID_IDispatch) {
-        *ppvObject = (IDispatch*)this;
-    } else if (riid == __uuidof(VGCore::IVGAppPlugin)) {
-        *ppvObject = (VGCore::IVGAppPlugin*)this;
-    } else {
-        m_ulRefCount--;
-        hr = E_NOINTERFACE;
-    }
-    return hr;
+STDMETHODIMP ToolsBoxPlugin::QueryInterface(REFIID riid, void **ppvObject) {
+  HRESULT hr = S_OK;
+  m_ulRefCount++;
+  if (riid == IID_IUnknown) {
+    *ppvObject = (IUnknown *)this;
+  } else if (riid == IID_IDispatch) {
+    *ppvObject = (IDispatch *)this;
+  } else if (riid == __uuidof(VGCore::IVGAppPlugin)) {
+    *ppvObject = (VGCore::IVGAppPlugin *)this;
+  } else {
+    m_ulRefCount--;
+    hr = E_NOINTERFACE;
+  }
+  return hr;
 }
 
-STDMETHODIMP ToolsBoxPlugin::Invoke(DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS* pDispParams, VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr)
-{
-    switch (dispIdMember) {
-
-    case 0x0014: // DISPID_APP_ONPLUGINCMD
-        if (pDispParams != NULL && pDispParams->cArgs == 1) {
-            _bstr_t strCmd(pDispParams->rgvarg[0].bstrVal);
-            if (strCmd == _bstr_t("OpenToolsBox")) {
-                //   MessageBox(NULL, _bstr_t("OpenToolsBox"), _bstr_t("OpenToolsBox"), MB_ICONSTOP);
-                OpenToolsBox();
-            }
-        }
-        break;
-
-    case 0x0015: // DISPID_APP_ONPLUGINCMDSTATE
-        if (pDispParams != NULL && pDispParams->cArgs == 3) {
-            _bstr_t strCmd(pDispParams->rgvarg[2].bstrVal);
-            if (strCmd == _bstr_t("OpenToolsBox")) {
-                *pDispParams->rgvarg[1].pboolVal = VARIANT_TRUE;
-            }
-        }
-        break;
+STDMETHODIMP ToolsBoxPlugin::Invoke(DISPID dispIdMember, REFIID riid, LCID lcid,
+                                    WORD wFlags, DISPPARAMS *pDispParams,
+                                    VARIANT *pVarResult, EXCEPINFO *pExcepInfo,
+                                    UINT *puArgErr) {
+  switch (dispIdMember) {
+
+  case 0x0014: // DISPID_APP_ONPLUGINCMD
+    if (pDispParams != NULL && pDispParams->cArgs == 1) {
+      _bstr_t strCmd(pDispParams->rgvarg[0].bstrVal);
+      if (strCmd == _bstr_t("OpenToolsBox")) {
+        //   MessageBox(NULL, _bstr_t("OpenToolsBox"), _bstr_t("OpenToolsBox"),
+        //   MB_ICONSTOP);
+        OpenToolsBox();
+      }
     }
-    return S_OK;
-}
-
-STDMETHODIMP ToolsBoxPlugin::raw_OnLoad(VGCore::IVGApplication* Application)
-{
-    m_pApp = Application;
-    if (m_pApp) {
-        m_pApp->AddRef();
+    break;
+
+  case 0x0015: // DISPID_APP_ONPLUGINCMDSTATE
+    if (pDispParams != NULL && pDispParams->cArgs == 3) {
+      _bstr_t strCmd(pDispParams->rgvarg[2].bstrVal);
+      if (strCmd == _bstr_t("OpenToolsBox")) {
+        *pDispParams->rgvarg[1].pboolVal = VARIANT_TRUE;
+      }
     }
-    return S_OK;
+    break;
+  }
+  return S_OK;
 }
 
-STDMETHODIMP ToolsBoxPlugin::raw_StartSession()
-{
-    // 接口转交给cdr
-    cdr = m_pApp;
-
-    try {
-        m_pApp->AddPluginCommand(_bstr_t("OpenToolsBox"), _bstr_t("Tools Box"), _bstr_t("打开工具窗口"));
+STDMETHODIMP ToolsBoxPlugin::raw_OnLoad(VGCore::IVGApplication *Application) {
+  m_pApp = Application;
+  if (m_pApp) {
+    m_pApp->AddRef();
+  }
+  return S_OK;
+}
 
-        VGCore::ICUIControlPtr ctl = m_pApp->CommandBars->Item[_bstr_t("Standard")]->Controls->AddCustomButton(VGCore::cdrCmdCategoryPlugins, _bstr_t("OpenToolsBox"), 10, VARIANT_FALSE);
-        ctl->SetIcon2(_bstr_t("guid://d2fdc0d9-09f8-4948-944c-4297395c05b7"));
-        m_lCookie = m_pApp->AdviseEvents(this);
-    } catch (_com_error &e) {
-        MessageBox(NULL, e.Description(), _bstr_t("Error"), MB_ICONSTOP);
-    }
-    return S_OK;
+STDMETHODIMP ToolsBoxPlugin::raw_StartSession() {
+  // 接口转交给cdr
+  cdr = m_pApp;
+
+  try {
+    m_pApp->AddPluginCommand(_bstr_t("OpenToolsBox"), _bstr_t("Tools Box"),
+                             _bstr_t("打开工具窗口"));
+
+    VGCore::ICUIControlPtr ctl =
+        m_pApp->CommandBars->Item[_bstr_t("Standard")]
+            ->Controls->AddCustomButton(VGCore::cdrCmdCategoryPlugins,
+                                        _bstr_t("OpenToolsBox"), 10,
+                                        VARIANT_FALSE);
+    ctl->SetIcon2(_bstr_t("guid://d2fdc0d9-09f8-4948-944c-4297395c05b7"));
+    m_lCookie = m_pApp->AdviseEvents(this);
+  } catch (_com_error &e) {
+    MessageBox(NULL, e.Description(), _bstr_t("Error"), MB_ICONSTOP);
+  }
+  return S_OK;
 }
 
-STDMETHODIMP ToolsBoxPlugin::raw_StopSession()
-{
-    try {
-        m_pApp->UnadviseEvents(m_lCookie);
-        m_pApp->RemovePluginCommand(_bstr_t("OpenToolsBox"));
-    } catch (_com_error &e) {
-        MessageBox(NULL, e.Description(), _bstr_t("Error"), MB_ICONSTOP);
-    }
-    return S_OK;
+STDMETHODIMP ToolsBoxPlugin::raw_StopSession() {
+  try {
+    m_pApp->UnadviseEvents(m_lCookie);
+    m_pApp->RemovePluginCommand(_bstr_t("OpenToolsBox"));
+  } catch (_com_error &e) {
+    MessageBox(NULL, e.Description(), _bstr_t("Error"), MB_ICONSTOP);
+  }
+  return S_OK;
 }
 
-STDMETHODIMP ToolsBoxPlugin::raw_OnUnload()
-{
-    if (m_pApp) {
-        m_pApp->Release();
-        m_pApp = NULL;
-    }
-    return S_OK;
+STDMETHODIMP ToolsBoxPlugin::raw_OnUnload() {
+  if (m_pApp) {
+    m_pApp->Release();
+    m_pApp = NULL;
+  }
+  return S_OK;
 }
 
-void ToolsBoxPlugin::OpenToolsBox()
-{
-    m_pApp->StartupMode = VGCore::cdrStartupDoNothing;
-
-    intptr_t nHandle = m_pApp->AppWindow->Handle;
-    HWND hAppWnd = reinterpret_cast<HWND>(nHandle);
-
-    // 创建非模态对话框
-    HWND hDlgWnd = CreateDialogParam(g_hResource, MAKEINTRESOURCE(IDD_TOOLS_BOX), hAppWnd, DlgProc, (LPARAM)m_pApp);
-    // 在创建对话框之前存储 m_pApp 指针
-    SetWindowLongPtr(hDlgWnd, DWLP_USER, (LONG_PTR)m_pApp);
-
-    // 获取屏幕的宽度和高度
-    RECT rect;
-    GetWindowRect(GetDesktopWindow(), &rect);
-    int screenWidth = rect.right - rect.left;
-    int screenHeight = rect.bottom - rect.top;
-
-    // 计算对话框窗口的宽度和高度
-    RECT dlgRect;
-    GetWindowRect(hDlgWnd, &dlgRect);
-    int dlgWidth = dlgRect.right - dlgRect.left;
-    int dlgHeight = dlgRect.bottom - dlgRect.top;
-
-    // 计算对话框窗口的左上角坐标,使其居中显示
-    int x = (screenWidth - dlgWidth) / 2;
-    int y = (screenHeight - dlgHeight) / 2;
-
-    // 设置对话框窗口的位置
-    SetWindowPos(hDlgWnd, NULL, x, y, 0, 0, SWP_NOSIZE | SWP_NOZORDER);
-    // 设置对话框窗口的父窗口  // #define GWL_HWNDPARENT      (-8)
-    SetWindowLong(hDlgWnd, -8, (LONG)hAppWnd);
-    // 显示对话框窗口
-    ShowWindow(hDlgWnd, SW_SHOW);
+void ToolsBoxPlugin::OpenToolsBox() {
+  m_pApp->StartupMode = VGCore::cdrStartupDoNothing;
+
+  intptr_t nHandle = m_pApp->AppWindow->Handle;
+  HWND hAppWnd = reinterpret_cast<HWND>(nHandle);
+
+  // 创建非模态对话框
+  HWND hDlgWnd = CreateDialogParam(g_hResource, MAKEINTRESOURCE(IDD_TOOLS_BOX),
+                                   hAppWnd, DlgProc, (LPARAM)m_pApp);
+  // 在创建对话框之前存储 m_pApp 指针
+  SetWindowLongPtr(hDlgWnd, DWLP_USER, (LONG_PTR)m_pApp);
+
+  // 获取屏幕的宽度和高度
+  RECT rect;
+  GetWindowRect(GetDesktopWindow(), &rect);
+  int screenWidth = rect.right - rect.left;
+  int screenHeight = rect.bottom - rect.top;
+
+  // 计算对话框窗口的宽度和高度
+  RECT dlgRect;
+  GetWindowRect(hDlgWnd, &dlgRect);
+  int dlgWidth = dlgRect.right - dlgRect.left;
+  int dlgHeight = dlgRect.bottom - dlgRect.top;
+
+  // 计算对话框窗口的左上角坐标,使其居中显示
+  int x = (screenWidth - dlgWidth) / 2;
+  int y = (screenHeight - dlgHeight) / 2;
+
+  // 设置对话框窗口的位置
+  SetWindowPos(hDlgWnd, NULL, x, y, 0, 0, SWP_NOSIZE | SWP_NOZORDER);
+  // 设置对话框窗口的父窗口  // #define GWL_HWNDPARENT      (-8)
+  SetWindowLong(hDlgWnd, -8, (LONG)hAppWnd);
+  // 显示对话框窗口
+  ShowWindow(hDlgWnd, SW_SHOW);
 }
 
+// MessageBox(NULL, "更新提示信息: 激活CorelDRAW窗口", "CPG代码测试",
+// MB_ICONSTOP);
+#define UPDATE_INFO_ACTIVE_CDRWND                                              \
+  PutTextValue(hDlg, INFO_TEXT, infobuf);                                      \
+  Active_CorelWindows(hDlg);
+intptr_t CALLBACK ToolsBoxPlugin::DlgProc(HWND hDlg, UINT uMsg, WPARAM wParam,
+                                          LPARAM lParam) {
+  // 从附加数据中获取 m_pApp 指针
+  VGCore::IVGApplication *cdr = reinterpret_cast<VGCore::IVGApplication *>(
+      GetWindowLongPtr(hDlg, DWLP_USER));
+
+  if (uMsg == WM_COMMAND) {
+    try {
+      switch (LOWORD(wParam)) {
+
+      case ID_BOUNDARY_GROUP: {
+
+        if (BST_CHECKED == IsDlgButtonChecked(hDlg, DEBUG_FLG))
+          debug_flg = true;
+        else
+          debug_flg = false;
+        double exp = GetTextValue(hDlg, EXP_TEXT);
+
+        run_BoundaryGroup(cdr);
+        UPDATE_INFO_ACTIVE_CDRWND
+      } break;
+
+      case IDC_BOX_GROUP: {
+        double exp = GetTextValue(hDlg, EXP_TEXT);
+        AutoMakeSelection(cdr);
+        Box_AutoGroup(cdr, exp);
+        UPDATE_INFO_ACTIVE_CDRWND
+
+      } break;
+
+      case IDC_CQL_OUTLINE:
+        cql_OutlineColor(cdr);
+
+        UPDATE_INFO_ACTIVE_CDRWND
+        break;
+
+      case IDC_CQL_FILL:
+        cql_FillColor(cdr);
+
+        UPDATE_INFO_ACTIVE_CDRWND
+        break;
+
+      case IDC_CQL_SIZE:
+        cql_SameSize(cdr);
+
+        UPDATE_INFO_ACTIVE_CDRWND
+        break;
+
+      case IDC_CLEAR_FILL: {
+        double exp = GetTextValue(hDlg, EXP_TEXT);
+        AutoMakeSelection(cdr);
+        BBox_DrawRectangle(cdr, exp);
+
+        UPDATE_INFO_ACTIVE_CDRWND
+      } break;
 
-// MessageBox(NULL, "更新提示信息: 激活CorelDRAW窗口", "CPG代码测试", MB_ICONSTOP);
-#define UPDATE_INFO_ACTIVE_CDRWND  \
-    PutTextValue(hDlg, INFO_TEXT, infobuf); Active_CorelWindows(hDlg);
-intptr_t CALLBACK ToolsBoxPlugin::DlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
-{
-    // 从附加数据中获取 m_pApp 指针
-    VGCore::IVGApplication* cdr = reinterpret_cast<VGCore::IVGApplication*>(GetWindowLongPtr(hDlg, DWLP_USER));
-
-    if (uMsg == WM_COMMAND) {
-        try {
-            switch (LOWORD(wParam)) {
-
-            case ID_BOUNDARY_GROUP :{
-                    double exp = GetTextValue(hDlg, EXP_TEXT);
-                    AutoMakeSelection(cdr);
-                    run_BoundaryGroup(cdr);
-                    UPDATE_INFO_ACTIVE_CDRWND    
-                }
-                break;
-
-
-            case IDC_BOX_GROUP :{
-                    double exp = GetTextValue(hDlg, EXP_TEXT);
-                    AutoMakeSelection(cdr);
-                    Box_AutoGroup(cdr, exp);
-                    UPDATE_INFO_ACTIVE_CDRWND
-
-                }
-                break;
-
-            case IDC_CQL_OUTLINE:
-                cql_OutlineColor(cdr);
-
-                UPDATE_INFO_ACTIVE_CDRWND
-                break;
-
-            case IDC_CQL_FILL:
-                cql_FillColor(cdr);
-
-                UPDATE_INFO_ACTIVE_CDRWND
-                break;
-
-            case IDC_CQL_SIZE:
-                cql_SameSize(cdr);
-
-                UPDATE_INFO_ACTIVE_CDRWND
-                break;
-
-            case IDC_CLEAR_FILL:{
-                    double exp = GetTextValue(hDlg, EXP_TEXT);
-                    AutoMakeSelection(cdr);
-                    BBox_DrawRectangle(cdr, exp);
-                    
-                    UPDATE_INFO_ACTIVE_CDRWND
-                }
-                break;
-
-            case IDC_SR_FLIP:
-                Shapes_Filp(cdr);
-                break;
-
-            case IDC_CDR2AI:{    
-                CdrCopy_to_AdobeAI(cdr);
-                sprintf(infobuf, "把CorelDRAW软件中选择物件复制到剪贴板,请切换到AI软件粘贴");
-                UPDATE_INFO_ACTIVE_CDRWND
-                }
-
-                break;
-
-            case IDC_AI2CDR:{
-                AdobeAI_Copy_ImportCdr(cdr);
-                sprintf(infobuf, "请先在AI软件选择物件复制,再切换到CorelDRAW软件点执行本功能");
-                UPDATE_INFO_ACTIVE_CDRWND
-                }
-                break;
-
-            case IDOK:
-            case IDCANCEL:
-                EndDialog(hDlg, 0);
-                break;
-            }
-
-        } catch (_com_error &e) {
-            MessageBox(NULL, e.Description(), "Error", MB_ICONSTOP);
-            EndOpt(cdr);
-        }
-
-    } else if (uMsg == WM_INITDIALOG) {
-             SetWindowText(::GetDlgItem(hDlg, EXP_TEXT), "0");
-        return 1;
+      case IDC_SR_FLIP:
+        Shapes_Filp(cdr);
+        break;
+
+      case IDC_CDR2AI: {
+        CdrCopy_to_AdobeAI(cdr);
+        sprintf(infobuf,
+                "把CorelDRAW软件中选择物件复制到剪贴板,请切换到AI软件粘贴");
+        UPDATE_INFO_ACTIVE_CDRWND
+      }
+
+      break;
+
+      case IDC_AI2CDR: {
+        AdobeAI_Copy_ImportCdr(cdr);
+        sprintf(infobuf,
+                "请先在AI软件选择物件复制,再切换到CorelDRAW软件点执行本功能");
+        UPDATE_INFO_ACTIVE_CDRWND
+      } break;
+
+      case EXPAND_TOOLS: {
+        // 获取当前窗口的句柄
+        HWND hwnd = GetActiveWindow();
+        // 获取当前窗口的矩形区域
+        RECT rect;
+        GetWindowRect(hwnd, &rect);
+        // 计算新的宽度
+        int newWidth = rect.right - rect.left + 125; // 增加125单位
+        // 移动窗口到新的大小
+        SetWindowPos(hwnd, NULL, rect.left, rect.top, newWidth, rect.bottom - rect.top, SWP_NOZORDER | SWP_NOACTIVATE);
+        // 隐藏按钮 (假设按钮的句柄为 buttonHandle)
+        ShowWindow(::GetDlgItem(hDlg, EXPAND_TOOLS), SW_HIDE);
+      } break;
+
+      case MIN_TOOLS: {
+        RECT rect;
+        GetWindowRect(hDlg, &rect);
+        int currentWidth = rect.right - rect.left;
+        int newHeight = 98; // 设置新的高度为
+        SetWindowPos(hDlg, NULL, rect.left, rect.top, currentWidth, newHeight, SWP_NOZORDER | SWP_NOACTIVATE);
+      } break;
+
+      case IDOK:
+      case IDCANCEL:
+        EndDialog(hDlg, 0);
+        break;
+      }
+
+    } catch (_com_error &e) {
+      MessageBox(NULL, e.Description(), "Error", MB_ICONSTOP);
+      EndOpt(cdr);
     }
-    return 0;
+
+  } else if (uMsg == WM_INITDIALOG) {
+    SetWindowText(::GetDlgItem(hDlg, EXP_TEXT), "0");
+    return 1;
+  }
+  return 0;
 }
 
-extern "C" __declspec(dllexport) DWORD APIENTRY AttachPlugin(VGCore::IVGAppPlugin** ppIPlugin)
-{
-    *ppIPlugin = new ToolsBoxPlugin;
-    return 0x100;
+extern "C" __declspec(dllexport) DWORD APIENTRY
+    AttachPlugin(VGCore::IVGAppPlugin **ppIPlugin) {
+  *ppIPlugin = new ToolsBoxPlugin;
+  return 0x100;
 }

+ 17 - 14
09_BoundaryGroup/ToolsBox.rc

@@ -14,23 +14,26 @@
 // Dialog resources
 //
 LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
-IDD_TOOLS_BOX DIALOGEX 0, 0, 142, 129
+IDD_TOOLS_BOX DIALOGEX 0, 0, 135, 128
 STYLE DS_MODALFRAME | DS_SHELLFONT | WS_CAPTION | WS_POPUP | WS_SYSMENU
 CAPTION "蘭雅 CPG 插件 福利群版"
-FONT 8, "MS Shell Dlg", 400, 0, 1
+FONT 8, "MS Shell Dlg", 135, 0, 1
 {
-    CTEXT           "蘭雅 CorelDRAW CPG 插件\n2024.8.8 智能群组版", INFO_TEXT, 6, 105, 126, 17, SS_CENTER, WS_EX_LEFT
-    PUSHBUTTON      "方框智能群组", IDC_BOX_GROUP, 73, 2, 59, 21, 0, WS_EX_LEFT
-    PUSHBUTTON      "CQL轮廓色相同", IDC_CQL_OUTLINE, 9, 40, 59, 18, 0, WS_EX_LEFT
-    PUSHBUTTON      "边界画矩形", IDC_CLEAR_FILL, 74, 36, 59, 19, 0, WS_EX_LEFT
-    PUSHBUTTON      "批量镜像", IDC_SR_FLIP, 73, 57, 59, 19, 0, WS_EX_LEFT
-    PUSHBUTTON      "CQL颜色相同", IDC_CQL_FILL, 9, 57, 59, 22, 0, WS_EX_LEFT
-    PUSHBUTTON      "CQL尺寸相同", IDC_CQL_SIZE, 9, 22, 59, 18, 0, WS_EX_LEFT
-    PUSHBUTTON      "CDR复制到AI", IDC_CDR2AI, 9, 78, 59, 24, 0, WS_EX_LEFT
-    PUSHBUTTON      "AI粘贴到CDR", IDC_AI2CDR, 74, 78, 59, 24, 0, WS_EX_LEFT
-    LTEXT           "容差:(mm)", EXP_LT, 72, 25, 37, 9, SS_LEFT, WS_EX_LEFT
-    EDITTEXT        EXP_TEXT, 107, 23, 28, 14, NOT WS_TABSTOP | ES_AUTOHSCROLL, WS_EX_DLGMODALFRAME
-    PUSHBUTTON      "异形群组", ID_BOUNDARY_GROUP, 9, 2, 59, 19, 0, WS_EX_LEFT
+    AUTOCHECKBOX    "调试->高级模式", DEBUG_FLG, 142, 8, 70, 8, 0, WS_EX_LEFT
+    CTEXT           "蘭雅 CorelDRAW CPG 插件\n2024.8.30 异形群组版", INFO_TEXT, 5, 104, 124, 18, SS_CENTER, WS_EX_LEFT
+    PUSHBUTTON      "方框智能群组", IDC_BOX_GROUP, 69, 2, 59, 20, 0, WS_EX_LEFT
+    PUSHBUTTON      "CQL轮廓色相同", IDC_CQL_OUTLINE, 4, 61, 59, 20, 0, WS_EX_LEFT
+    PUSHBUTTON      "边界画矩形", IDC_CLEAR_FILL, 69, 39, 59, 20, 0, WS_EX_LEFT
+    PUSHBUTTON      "批量镜像", IDC_SR_FLIP, 69, 60, 59, 20, 0, WS_EX_LEFT
+    PUSHBUTTON      "CQL颜色相同", IDC_CQL_FILL, 4, 81, 59, 20, 0, WS_EX_LEFT
+    PUSHBUTTON      "CQL尺寸相同", IDC_CQL_SIZE, 69, 81, 59, 20, 0, WS_EX_LEFT
+    PUSHBUTTON      "CDR复制到AI", IDC_CDR2AI, 4, 21, 59, 20, 0, WS_EX_LEFT
+    PUSHBUTTON      "AI粘贴到CDR", IDC_AI2CDR, 4, 41, 59, 20, 0, WS_EX_LEFT
+    LTEXT           "容差:(mm)", EXP_LT, 66, 27, 41, 8, SS_LEFT, WS_EX_LEFT
+    EDITTEXT        EXP_TEXT, 103, 24, 22, 14, NOT WS_TABSTOP | ES_AUTOHSCROLL, WS_EX_LEFT
+    PUSHBUTTON      "异形群组", ID_BOUNDARY_GROUP, 4, 2, 59, 20, 0, WS_EX_LEFT
+    PUSHBUTTON      "∧", MIN_TOOLS, 125, 23, 12, 17, BS_NOTIFY, WS_EX_LEFT
+    PUSHBUTTON      ">>", EXPAND_TOOLS, 129, 53, 13, 39, BS_NOTIFY, WS_EX_LEFT
 }
 
 

+ 4 - 4
09_BoundaryGroup/boxAutoGroup.cpp

@@ -226,7 +226,7 @@ bool BoxGrouping(corel *cdr, IVGShapeRange *sr, IVGShapeRange *srs, double exp )
   std::map<int, std::vector<int>> groups;
   for (int i = 0; i < parent.size(); i++) {
     int root = find(parent, i);
-    groups[root].push_back(i + 1); // CorelDRAW Shapes 物件 Item 编号从1开始
+    groups[root].push_back(i + 1);
   }
 
   auto srgp = cdr->CreateShapeRange();
@@ -237,9 +237,9 @@ bool BoxGrouping(corel *cdr, IVGShapeRange *sr, IVGShapeRange *srs, double exp )
       
       if(sr->Count >1)
         srs->Add(srgp->Group());
-      else
-        srs->AddRange(srgp);  
-
+      else{
+        srs->AddRange(srgp); 
+      }
       srgp->RemoveAll();
   }
   return true;

+ 1 - 1
09_BoundaryGroup/cdrapi.h

@@ -1,4 +1,4 @@
-#ifndef CDRAPI_H_INCLUDED
+#ifndef CDRAPI_H_INCLUDED
 #define CDRAPI_H_INCLUDED
 
 #define _CRT_SECURE_NO_WARNINGS

+ 2 - 1
09_BoundaryGroup/cdrapp.h

@@ -1,4 +1,4 @@
-#ifndef CDRAPP_H_INCLUDED
+#ifndef CDRAPP_H_INCLUDED
 #define CDRAPP_H_INCLUDED
 #include "cdrapi.h"
 
@@ -22,6 +22,7 @@ void run_BoundaryGroup(corel *cdr);
 
 
 extern char infobuf[];
+extern bool debug_flg;
 
 #define GET_BOUNDING_BOX(box)                                                  \
   GetBoundingBox(&(box).x, &(box).y, &(box).w, &(box).h, false)

+ 3 - 0
09_BoundaryGroup/resource.h

@@ -4,6 +4,7 @@
 
 #define IDD_TOOLS_BOX                           100
 #define IDI_ICON1                               101
+#define EXPAND_TOOLS                            40015
 #define IDC_CQL_FILL                            40001
 #define IDC_CQL_OUTLINE                         40002
 #define IDC_CQL_SIZE                            40003
@@ -16,3 +17,5 @@
 #define INFO_TEXT                               40010
 #define IDC_BOX_GROUP                           40011
 #define ID_BOUNDARY_GROUP                       40012
+#define DEBUG_FLG                               40013
+#define MIN_TOOLS                               40014