Parcourir la source

CorelDRAW 小工具

蘭雅sRGB il y a 5 mois
Parent
commit
4f2693a405
4 fichiers modifiés avec 252 ajouts et 0 suppressions
  1. 119 0
      tools/DrawUI_FixMenu.cpp
  2. 57 0
      tools/clip2pdf.cpp
  3. 0 0
      tools/dwgthumbnail.cpp
  4. 76 0
      tools/pdf2clip.cpp

+ 119 - 0
tools/DrawUI_FixMenu.cpp

@@ -0,0 +1,119 @@
+// This is free and unencumbered software released into the public domain.
+// For more information, please refer to  https://github.com/hongwenjun
+
+// 兰雅VBA代码分享  https://lyvba.com/
+
+#include <stdio.h>
+#include <string.h>
+#include <string>
+
+using std::string;
+
+bool readfile_DrawUI(string &str, const char *filename);
+bool savefile_DrawUI(string &str, const char *filename);
+int main() {
+  const char *filename = "DrawUI.xml";
+  FILE *fp = fopen(filename, "r");
+  if (fp == NULL) {
+    printf("无法打开文件 DrawUI.xml\n");
+    return 1;
+  }
+
+  string drawui_text;
+  bool flag = readfile_DrawUI(drawui_text, filename);
+  bool saveflag = false;
+
+  printf("%d\n", drawui_text.size());
+
+  char guid[] = "f3016f3c-2847-4557-b61a-a2d05319cf18";
+  char line[2048];
+
+  string str;
+  string menu = "type=\"menu\"";
+  string toolbar = "type=\"toolbar\"";
+
+  while (fgets(line, sizeof(line), fp) != NULL) {
+    line[strlen(line) - 1] = '\0';
+
+    if (strstr(line, guid) != NULL) {
+      str = string(line);
+      // 使用 C++ 标准库的 replace() 方法替换单词
+      size_t pos = str.find(menu);
+      if (pos != string::npos) {
+        str.replace(pos, menu.length(), toolbar);
+        printf("%s", str.c_str());
+
+        pos = drawui_text.find(string(line));
+        if (pos != string::npos) {
+          saveflag = savefile_DrawUI(drawui_text, "DrawUI.xml_BAK");
+          drawui_text.replace(pos, string(line).length(), str);
+        }
+      }
+    }
+  }
+
+  fclose(fp);
+
+  if (saveflag)
+    savefile_DrawUI(drawui_text, filename);
+
+  return 0;
+}
+
+bool readfile_DrawUI(string &str, const char *filename) {
+  FILE *fp;
+  long size;
+  char *buffer;
+
+  // 打开文件
+  fp = fopen(filename, "rb");
+  if (fp == NULL) {
+    printf("打开文件失败\n");
+    return false;
+  }
+
+  // 获取文件大小
+  fseek(fp, 0, SEEK_END);
+  size = ftell(fp);
+  rewind(fp);
+
+  // 分配内存空间
+  buffer = (char *)malloc(size + 1);
+  if (buffer == NULL) {
+    printf("内存分配失败\n");
+    fclose(fp);
+    return false;
+  }
+  // 读取文件内容到内存
+  if (fread(buffer, 1, size, fp) != size) {
+    printf("读取文件失败\n");
+    free(buffer);
+    fclose(fp);
+    return false;
+  }
+
+  // 添加字符串结尾标志
+  buffer[size] = '\0';
+  str = string(buffer);
+  // 释放资源
+  free(buffer);
+  fclose(fp);
+  return true;
+}
+
+bool savefile_DrawUI(string &str, const char *filename) {
+  FILE *fp;
+  const char *content = str.c_str();
+
+  // 打开文件,以写入模式
+  fp = fopen(filename, "wb");
+  if (fp == NULL) {
+    printf("打开文件失败\n");
+    return false;
+  }
+  // 写入字符串到文件
+  fputs(content, fp);
+  // 关闭文件
+  fclose(fp);
+  return true;
+}

+ 57 - 0
tools/clip2pdf.cpp

@@ -0,0 +1,57 @@
+#include <windows.h>
+#include <stdio.h>
+
+#define CUSTOM_FORMAT  RegisterClipboardFormatA("Portable Document Format")
+
+int main(int argc, char* argv[])
+{
+    // 要保存的PDF文件路径
+    const char* outputFile = "output.pdf";
+    if(2 == argc)
+        outputFile = argv[1];
+
+    // 打开剪贴板
+    if (!OpenClipboard(NULL)) {
+        printf("Failed to open clipboard.\n");
+        return 1;
+    }
+
+    // 获取剪贴板中的PDF数据
+    HANDLE hData = GetClipboardData(CUSTOM_FORMAT);
+    if (!hData) {
+        printf("Failed to get clipboard data.\n");
+        CloseClipboard();
+        return 1;
+    }
+
+    // 锁定内存并获取指针
+    void* pdfData = GlobalLock(hData);
+    if (!pdfData) {
+        printf("Failed to lock global memory.\n");
+        CloseClipboard();
+        return 1;
+    }
+
+    // 获取PDF数据的大小
+    size_t fileSize = GlobalSize(hData);
+
+    // 将PDF数据写入文件
+    FILE* file = fopen(outputFile, "wb");
+    if (!file) {
+        printf("Failed to open output file.\n");
+        GlobalUnlock(hData);
+        CloseClipboard();
+        return 1;
+    }
+
+    fwrite(pdfData, 1, fileSize, file);
+    fclose(file);
+
+    // 解锁内存并关闭剪贴板
+    GlobalUnlock(hData);
+    CloseClipboard();
+
+    printf("PDF binary data from clipboard saved to file: %s\n", outputFile);
+
+    return 0;
+}

+ 0 - 0
cad/dwgthumbnail.cpp → tools/dwgthumbnail.cpp


+ 76 - 0
tools/pdf2clip.cpp

@@ -0,0 +1,76 @@
+#include <windows.h>
+#include <stdio.h>
+
+#define CUSTOM_FORMAT  RegisterClipboardFormatA("Portable Document Format")
+
+int main(int argc, char* argv[])
+ {
+    // PDF文件路径
+    const char* pdffile = "file.pdf";
+    if(2 == argc)
+        pdffile = argv[1];
+
+    // 打开剪贴板
+    if (!OpenClipboard(NULL)) {
+        printf("Failed to open clipboard.\n");
+        return 1;
+    }
+
+    // 清空剪贴板
+    EmptyClipboard();
+
+    // 读取PDF文件到内存
+    FILE* file = fopen(pdffile, "rb");
+    if (!file) {
+        printf("Failed to open file.\n");
+        CloseClipboard();
+        return 1;
+    }
+
+    // 获取文件大小
+    fseek(file, 0, SEEK_END);
+    size_t fileSize = ftell(file);
+    fseek(file, 0, SEEK_SET);
+
+    // 分配内存并读取文件内容
+    void* pdfData = malloc(fileSize);
+    if (!pdfData) {
+        printf("Failed to allocate memory.\n");
+        fclose(file);
+        CloseClipboard();
+        return 1;
+    }
+
+    fread(pdfData, 1, fileSize, file);
+    fclose(file);
+
+    // 将二进制数据写入剪贴板
+    HGLOBAL hGlobal = GlobalAlloc(GHND, fileSize);
+    if (!hGlobal) {
+        printf("Failed to allocate global memory.\n");
+        free(pdfData);
+        CloseClipboard();
+        return 1;
+    }
+
+    memcpy(GlobalLock(hGlobal), pdfData, fileSize);
+    GlobalUnlock(hGlobal);
+
+    if (!SetClipboardData(CUSTOM_FORMAT, hGlobal)) {
+        printf("Failed to set clipboard data.\n");
+        GlobalFree(hGlobal);
+        free(pdfData);
+        CloseClipboard();
+        return 1;
+    }
+
+    // 关闭剪贴板
+    CloseClipboard();
+
+    printf("PDF binary data copied to clipboard using custom format.\n");
+
+    // 不要忘记释放内存
+    free(pdfData);
+
+    return 0;
+}