123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159 |
- #import "VGCoreAuto.tlb" // 导入VGCoreAuto类型库: 这个文件在CorelDRAW 软件目录下可以找到
- #define corel VGCore::IVGApplication
- using namespace VGCore;
- bool cql_OutlineColor(corel *cdr);
- int cpg_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();
- cql_OutlineColor(app);
- // 清理COM库的初始化
- CoUninitialize();
- }
- return 0;
- }
- bool cql_OutlineColor(corel *cdr)
- {
- 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);
- auto sr = cdr->ActivePage->Shapes->FindShapes(_bstr_t(), cdrNoShape, VARIANT_TRUE, cql);
- sr->CreateSelection();
- return true;
- }
- #include <windows.h>
- // 定义按钮的ID
- #define ID_BUTTON_TOOLS 1
- #define ID_BUTTON_MOVE 2
- #define ID_BUTTON_CLOSE 3
- // 声明cpg_main函数
- int cpg_main();
- // 窗口过程函数,处理窗口消息
- LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
- {
- // 根据消息类型处理不同的消息
- switch (uMsg) {
- case WM_COMMAND:
- // 处理按钮点击事件
- switch (LOWORD(wParam)) {
- case ID_BUTTON_TOOLS:{
- // 显示信息对话框
- // MessageBox(hwnd, "LYCPG CQL_OutlineColor!", "Info", MB_OK);
- // 调用app.cpp文件中的main函数
- cpg_main();
- }
- break;
- case ID_BUTTON_MOVE: {
- // 移动窗口到屏幕右上角
- MoveWindow(hwnd, GetSystemMetrics(SM_CXSCREEN) / 2, 0, 90, 30, TRUE);
- break;
- }
- case ID_BUTTON_CLOSE:
- // 发送关闭消息,关闭窗口
- PostMessage(hwnd, WM_CLOSE, 0, 0);
- break;
- }
- break;
- case WM_DESTROY:
- // 当窗口销毁时,发送退出消息
- PostQuitMessage(0);
- return 0;
- default:
- // 调用默认的窗口过程函数处理其他消息
- return DefWindowProc(hwnd, uMsg, wParam, lParam);
- }
- return 0;
- }
- HICON LoadSystemIcon(LPCTSTR iconName) { return LoadIcon(NULL, iconName); }
- // Windows程序的入口点
- int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
- {
- // 窗口类名
- const char CLASS_NAME[] = "NoTitleWindow";
- // 初始化窗口类结构体
- WNDCLASS wc = {};
- // 设置窗口过程函数
- wc.lpfnWndProc = WindowProc;
- // 设置实例句柄
- wc.hInstance = hInstance;
- // 设置类名为常量定义的名称
- wc.lpszClassName = CLASS_NAME;
- // 设置背景刷子为窗口默认颜色
- wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
- // 设置窗口风格为水平和垂直重绘
- wc.style = CS_HREDRAW | CS_VREDRAW;
- // 注册窗口类
- RegisterClass(&wc);
- // 窗口宽度和高度
- int windowWidth = 90; int windowHeight = 30;
- // 计算窗口显示位置
- int x = (GetSystemMetrics(SM_CXSCREEN) - windowWidth) / 2;
- int y = (GetSystemMetrics(SM_CYSCREEN) - windowHeight) / 2;
- // 创建主窗口
- HWND hwnd = CreateWindowEx(WS_EX_TOPMOST, CLASS_NAME, NULL, WS_POPUP, x, y, windowWidth, windowHeight, NULL, NULL, hInstance, NULL);
- if (hwnd == NULL) { return 0; }
- // 加载系统图标
- HICON hIconTools = LoadSystemIcon(IDI_APPLICATION);
- HICON hIconMove = LoadSystemIcon(IDI_ASTERISK);
- HICON hIconClose = LoadSystemIcon(IDI_ERROR);
- // 创建工具按钮
- HWND hButtonTools = CreateWindow("BUTTON", "LYCPG", WS_VISIBLE | WS_CHILD | BS_FLAT, 0, 0, 60, 30, hwnd,
- (HMENU)ID_BUTTON_TOOLS, (HINSTANCE)GetWindowLongPtr(hwnd, GWLP_HINSTANCE), NULL);
- // 创建移动按钮
- HWND hButtonMove = CreateWindow("BUTTON", NULL, WS_VISIBLE | WS_CHILD | BS_FLAT | BS_ICON, 60, 15, 30, 15, hwnd,
- (HMENU)ID_BUTTON_MOVE, (HINSTANCE)GetWindowLongPtr(hwnd, GWLP_HINSTANCE), NULL);
- SendMessage(hButtonMove, BM_SETIMAGE, IMAGE_ICON, (LPARAM)hIconMove);
- // 创建“X”按钮
- HWND hButtonClose = CreateWindow("BUTTON", NULL, WS_VISIBLE | WS_CHILD | BS_FLAT | BS_ICON, 60, 0, 30, 15, hwnd,
- (HMENU)ID_BUTTON_CLOSE, (HINSTANCE)GetWindowLongPtr(hwnd, GWLP_HINSTANCE), NULL);
- SendMessage(hButtonClose, BM_SETIMAGE, IMAGE_ICON, (LPARAM)hIconClose);
- // 显示和更新窗口
- ShowWindow(hwnd, nShowCmd);
- UpdateWindow(hwnd);
- // 消息循环
- MSG msg;
- while (GetMessage(&msg, NULL, 0, 0)) {
- TranslateMessage(&msg);
- DispatchMessage(&msg);
- }
- return 0;
- }
|