1
0
Эх сурвалжийг харах

CorelDRAW CPG工具初步完成

Hongwenjun 8 сар өмнө
parent
commit
c7f05954aa

+ 104 - 59
05_ToolsBox_CreateDialog/ToolsBox.cpp

@@ -95,7 +95,7 @@ STDMETHODIMP ToolsBoxPlugin::Invoke(DISPID dispIdMember, REFIID riid, LCID lcid,
         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);
+           //   MessageBox(NULL, _bstr_t("OpenToolsBox"), _bstr_t("OpenToolsBox"), MB_ICONSTOP);
                 OpenToolsBox();
             }
         }
@@ -158,38 +158,38 @@ STDMETHODIMP ToolsBoxPlugin::raw_OnUnload()
 
 void ToolsBoxPlugin::OpenToolsBox()
 {
-        m_pApp->StartupMode = VGCore::cdrStartupDoNothing;
-
-        INT_PTR 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);
+    m_pApp->StartupMode = VGCore::cdrStartupDoNothing;
+
+    INT_PTR 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);
 }
 
 
@@ -201,44 +201,89 @@ INT_PTR CALLBACK ToolsBoxPlugin::DlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LP
     if (uMsg == WM_COMMAND) {
         try {
             switch (LOWORD(wParam)) {
-            case IDC_NEWDOC:
-                {
-                // sr.ApplyUniformFill CreateCMYKColor(0, 100, 100, 0)
-                auto sr = cdr->ActiveSelectionRange;
-                auto red = cdr->CreateCMYKColor(0, 100, 100, 0);
-                sr->ApplyUniformFill(red);
+            case IDC_RED : {
+                    // sr.ApplyUniformFill CreateCMYKColor(0, 100, 100, 0)
+                    auto sr = cdr->ActiveSelectionRange;
+                    auto red = cdr->CreateCMYKColor(0, 100, 100, 0);
+                    sr->ApplyUniformFill(red);
+                    MessageBox(NULL, "选择物件填充红色", "填充颜色测试", MB_ICONSTOP);
                 }
 
                 break;
 
-            case IDC_LASTDOC:
-                {
-                auto red = cdr->CreateCMYKColor(0, 100, 100, 0);
-                red->ConvertToRGB();
-                auto r = red->RGBRed;
-                auto g = red->RGBGreen;
-                auto b = red->RGBBlue;
-
-                char buf[256] = { 0 };
-                sprintf(buf, "@Outline.Color.rgb[.r='%d' And .g='%d' And .b='%d']" , r, g, b );
-                auto cql = _bstr_t(buf);
-               // MessageBox(NULL, cql, "cql 红色轮廓", MB_ICONSTOP);
-                auto sr = cdr->ActivePage->Shapes->FindShapes(_bstr_t(),cdrNoShape,VARIANT_TRUE, cql);
-                sr->CreateSelection();
+            case IDC_CQL_OUTLINE: {
+                    auto col = cdr->CreateCMYKColor(0, 100, 100, 0);
+                    auto s = cdr->ActiveShape;
+                    col-> CopyAssign (s->Outline->Color);
+                    col->ConvertToRGB();
+
+                    auto r = col->RGBRed;
+                    auto g = col->RGBGreen;
+                    auto b = col->RGBBlue;
+
+                    char buf[256] = { 0 };
+                    sprintf(buf, "@Outline.Color.rgb[.r='%d' And .g='%d' And .b='%d']", r, g, b);
+                    auto cql = _bstr_t(buf);
+                    // MessageBox(NULL, cql, "cql 轮廓颜色", MB_ICONSTOP);
+                    auto sr = cdr->ActivePage->Shapes->FindShapes(_bstr_t(), cdrNoShape, VARIANT_TRUE, cql);
+                    sr->CreateSelection();
                 }
 
+                // 将焦点返回到父窗口 关闭对话框窗口
+                SetFocus(GetParent(hDlg));
+                break;
+
+            case IDC_CQL_FILL: {
+                    auto col = cdr->CreateCMYKColor(0, 100, 100, 0);
+                    auto s = cdr->ActiveShape;
+                    col-> CopyAssign (s->Fill->UniformColor);
+                    col->ConvertToRGB();
+
+                    auto r = col->RGBRed;
+                    auto g = col->RGBGreen;
+                    auto b = col->RGBBlue;
+
+                    char buf[256] = { 0 };
+                    sprintf(buf, "@Fill.Color.rgb[.r='%d' And .g='%d' And .b='%d']", r, g, b);
+                    auto cql = _bstr_t(buf);
+
+                    auto sr = cdr->ActivePage->Shapes->FindShapes(_bstr_t(), cdrNoShape, VARIANT_TRUE, cql);
+                    sr->CreateSelection();
+                }
+
+                // 将焦点返回到父窗口 关闭对话框窗口
+                SetFocus(GetParent(hDlg));
+                break;
+
+
+            case IDC_CQL_SIZE: {
+                    cdr->ActiveDocument->Unit = cdrMillimeter;
+                    auto s = cdr->ActiveShape;
+
+                    char buf[256] = { 0 };
+                    sprintf(buf, "@width = {%lf mm} and @height = {%lf mm}", s->SizeWidth, s->SizeHeight);
+                    auto cql = _bstr_t(buf);
+
+                //  MessageBox(NULL, cql, "cql 尺寸相同", MB_ICONSTOP);
+                    auto sr = cdr->ActivePage->Shapes->FindShapes(_bstr_t(), cdrNoShape, VARIANT_TRUE, cql);
+                    sr->CreateSelection();
+                }
+
+                // 复制dll改名到CorelDRAW 插件目录
+                // copy /y lycpg64.dll  "C:\Program Files\Corel\CorelDRAW Technical Suite X6\Draw\Plugins64\lycpg64.cpg"
+
+                SetFocus(GetParent(hDlg));
                 break;
 
             case IDC_CLEAR_FILL:
                 cdr->ActiveSelection->Fill->ApplyNoFill();
                 break;
 
-            case IDC_SR_FLIP:
-                {
-                  auto sr = cdr->ActiveSelectionRange;
-                  // CorelDRAW Shapes 物件 Item 编号从1开始
-                  for (auto i = 0; i != sr->Count; i++)
-                      sr->Shapes->Item[i + 1]->Flip(VGCore::cdrFlipHorizontal);
+            case IDC_SR_FLIP: {
+                    auto sr = cdr->ActiveSelectionRange;
+                    // CorelDRAW Shapes 物件 Item 编号从1开始
+                    for (auto i = 0; i != sr->Count; i++)
+                        sr->Shapes->Item[i + 1]->Flip(VGCore::cdrFlipHorizontal);
                 }
                 break;
 

+ 16 - 5
05_ToolsBox_CreateDialog/ToolsBox.rc

@@ -10,17 +10,28 @@
 
 
 
+//
+// Bitmap resources
+//
+LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
+IDB_BITMAP1        BITMAP         ".\\cpg.bmp"
+
+
+
 //
 // Dialog resources
 //
 LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
-IDD_TOOLS_BOX DIALOGEX 0, 0, 164, 73
+IDD_TOOLS_BOX DIALOGEX 0, 0, 136, 166
 STYLE DS_MODALFRAME | DS_SHELLFONT | WS_CAPTION | WS_POPUP | WS_SYSMENU
 CAPTION "Tools Box"
 FONT 8, "MS Shell Dlg", 400, 0, 1
 {
-    PUSHBUTTON      "Ìî³äºìÉ«", IDC_NEWDOC, 7, 7, 68, 24, 0, WS_EX_LEFT
-    PUSHBUTTON      "CQLÑ¡Ôñ", IDC_LASTDOC, 88, 7, 68, 24, 0, WS_EX_LEFT
-    PUSHBUTTON      "ÎÞÌîÉ«", IDC_CLEAR_FILL, 7, 38, 68, 24, 0, WS_EX_LEFT
-    PUSHBUTTON      "ÅúÁ¿¾µÏñ", IDC_SR_FLIP, 89, 39, 68, 24, 0, WS_EX_LEFT
+    CONTROL         IDB_BITMAP1, 0, WC_STATIC, SS_BITMAP, 1, 89, 133, 75, WS_EX_LEFT
+    PUSHBUTTON      "Ìî³äºìÉ«", IDC_RED, 71, 3, 59, 24, 0, WS_EX_LEFT
+    PUSHBUTTON      "CQLÂÖÀªÉ«Ïàͬ", IDC_CQL_OUTLINE, 7, 2, 59, 24, 0, WS_EX_LEFT
+    PUSHBUTTON      "ÎÞÌîÉ«", IDC_CLEAR_FILL, 71, 30, 59, 24, 0, WS_EX_LEFT
+    PUSHBUTTON      "ÅúÁ¿¾µÏñ", IDC_SR_FLIP, 71, 58, 59, 24, 0, WS_EX_LEFT
+    PUSHBUTTON      "CQLÑÕÉ«Ïàͬ", IDC_CQL_FILL, 7, 30, 59, 24, 0, WS_EX_LEFT
+    PUSHBUTTON      "CQL³ß´çÏàͬ", IDC_CQL_SIZE, 7, 58, 59, 24, 0, WS_EX_LEFT
 }

+ 7 - 5
05_ToolsBox_CreateDialog/lycpg64_build_log.html

@@ -4,8 +4,8 @@
 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /></head>
 <body>
 <tt>
-开始构建:<u>20-06-2024 at 17:44.02</u><br />
-构建结束于:<u>20-06-2024 at 17:44.03</u><p />
+开始构建:<u>21-06-2024 at 23:25.36</u><br />
+构建结束于:<u>21-06-2024 at 23:25.37</u><p />
 <b>-------------- 构建: Release 在 lycpg64 中 (编译器: Microsoft Visual C++ 2022)---------------</b><br />
 cl.exe /nologo /W3 /EHsc  /Ox /DNDEBUG    /I..\TypeLibs /IC:\MSVC2022\include /IC:\Users\vip\Desktop\05_ToolsBox_CreateDialog /c ToolsBox.cpp /Foobj\Release\ToolsBox.obj<br />
 rc.exe /IC:\MSVC2022\include /IC:\Users\vip\Desktop\05_ToolsBox_CreateDialog  -foobj\Release\ToolsBox.res ToolsBox.rc<br />
@@ -14,12 +14,14 @@ Microsoft (R) Windows (R) Resource Compiler Version 10.0.10011.16384<br />
 Copyright (C) Microsoft Corporation.  All rights reserved.<br />
 <font color="#0000ff">ToolsBox.cpp(190): warning C4311: “类型强制转换”: 从“HWND”到“LONG”的指针截断</font><br />
 <font color="#0000ff">ToolsBox.cpp(190): warning C4302: “类型强制转换”: 从“HWND”到“LONG”截断</font><br />
-<font color="#0000ff">ToolsBox.cpp(223): warning C4996: 'sprintf': This function or variable may be unsafe. Consider using sprintf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.</font><br />
+<font color="#0000ff">ToolsBox.cpp(225): warning C4996: 'sprintf': This function or variable may be unsafe. Consider using sprintf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.</font><br />
+<font color="#0000ff">ToolsBox.cpp(247): warning C4996: 'sprintf': This function or variable may be unsafe. Consider using sprintf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.</font><br />
+<font color="#0000ff">ToolsBox.cpp(264): warning C4996: 'sprintf': This function or variable may be unsafe. Consider using sprintf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.</font><br />
 link.exe /dll /nologo /LIBPATH:C:\MSVC2022\lib /out:bin\Release\lycpg64.dll Gdi32.lib user32.lib Kernel32.lib obj\Release\ToolsBox.obj  obj\Release\ToolsBox.res<br />
   正在创建库 bin\Release\lycpg64.lib 和对象 bin\Release\lycpg64.exp<br />
-输出文件为 bin\Release\lycpg64.dll,大小为 153.50 KB<br />
+输出文件为 bin\Release\lycpg64.dll,大小为 161.50 KB<br />
 <font color="#0000ff">程序退出, 返回状态码:0 (0 分, 0 秒)</font><br />
-<font color="#0000ff">0个错误, 3个警告 (0 分, 0 秒)</font><br />
+<font color="#0000ff">0个错误, 5个警告 (0 分, 0 秒)</font><br />
 </tt>
 </body>
 </html>

+ 7 - 4
05_ToolsBox_CreateDialog/resource.h

@@ -3,7 +3,10 @@
 #endif
 
 #define IDD_TOOLS_BOX                           100
-#define IDC_NEWDOC                              1001
-#define IDC_LASTDOC                             1002
-#define IDC_CLEAR_FILL                          1003
-#define IDC_SR_FLIP                             1004
+#define IDB_BITMAP1                             101
+#define IDC_RED                                 40000
+#define IDC_CQL_FILL                            40001
+#define IDC_CQL_OUTLINE                         40002
+#define IDC_CQL_SIZE                            40003
+#define IDC_SR_FLIP                             40004
+#define IDC_CLEAR_FILL                          40005

+ 0 - 0
05_ToolsBox_CreateDialog/lycpg64.cpg → bin/lycpg64.cpg