CorelDRAW CPG 扩展开发: CPG(Corel Plug-in Gallery)是 CorelDRAW 的一个扩展机制,可以开发自定义的插件和工具。
CorelDRAW-CPG C++ 编程傻瓜入门文档.xls 下载
- 学习编写CPG插件,一般只用到
VGCoreAuto.tlb
这个文件就够 - 类型库
vgcoreauto.tlb
的包装器实现:vgcoreauto.tlh
vgcoreauto.tli
这两个文件可以查看类型库的接口定义
-
下载
MSVC2022_X64_mini.7z
压缩包解压到任意目录下, 推荐C:\MSVC2022
-
配置
MSVC2022
运行环境,参考如下
INCLUDE=C:\MSVC2022\include
LIB=C:\MSVC2022\lib
Path=C:\MSVC2022\bin;%PATH%
cl.exe /nologo /W3 /EHsc /Ox /DNDEBUG /IC:\MSVC2022\include /ITypeLibs /c 01_lycpg64\main.cpp /Fo.\main.obj
link.exe /dll /nologo /LIBPATH:C:\MSVC2022\lib /out:lycpg64.dll Gdi32.lib user32.lib Kernel32.lib .\main.obj
- 答疑解惑网址: fersatgit/SmartDepart#1
STDMETHODIMP CVGAppPlugin::raw_StartSession()
{
try
{
m_pApp->AddPluginCommand(_bstr_t("ClearFill"), _bstr_t("Clear Fill"), _bstr_t("Clears fill from selected objects"));
// CorelDRAW X6 使用 VGCore::CommandBarControlPtr ctl
// CorelDRAW 2020 SDK 使用 VGCore::ICUIControlPtr ctl
// https://github.com/fersatgit/SmartDepart/issues/1 // 感谢 fersatgit 修复CorelDRAW 2020 使用错误
VGCore::ICUIControlPtr ctl = m_pApp->CommandBars->Item[_bstr_t("Standard")]->Controls->AddCustomButton(VGCore::cdrCmdCategoryPlugins, _bstr_t("ClearFill"), 1, VARIANT_FALSE);
// _bstr_t bstrPath(m_pApp->Path + _bstr_t("Plugins64\\ClearFill.bmp"));
ctl->SetIcon2(_bstr_t("guid://d2fdc0d9-09f8-4948-944c-4297395c05b7"));
m_lCookie = m_pApp->AdviseEvents(this);
}
catch(_com_error &e)
{
MessageBox(NULL, e.Description(), _T("Error"), MB_ICONSTOP);
}
return S_OK;
}
- 创建非模态对话框,使用附加数据传递m_pApp 指针: 使用API
CreateDialogParam
和SetWindowLongPtr
- 将焦点返回到父窗口:
SetFocus(GetParent(hDlg));
cl.exe /nologo /W3 /EHsc /Ox /DNDEBUG /I..\TypeLibs /c ToolsBox.cpp ToolsBox.obj
rc.exe -fo.\ToolsBox.res ToolsBox.rc
link.exe /dll /nologo /out:lycpg64.dll Gdi32.lib user32.lib Kernel32.lib ToolsBox.obj ToolsBox.res
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();
使用 Makefile
用来编译,参考视频
nmake
nmake install
nmake clean