前提条件:CREO3.0 API 和VS2012安装完成
这两个路径根据自己的安装目录选择
附加依赖项:
mpr.lib
wsock32.lib
psapi.lib
netapi32.lib
protk_dllmd.lib
忽略特定默认库:
libcmtd.lib
msvcrt.lib
libcmt.lib
头文件:
#include "ProMenubar.h"
#include "ProMenu.h"
#include "ProUtil.h"
#pragma comment(lib,"netapi32")
测试代码(可直接复制到后面):
static uiCmdAccessState AccessDefault(uiCmdAccessMode access_mode)
{
return(ACCESS_AVAILABLE);
}
void Test1()
{
AfxMessageBox(_T("测试按钮A"));
}
void Test2()
{
AfxMessageBox(_T("测试按钮B"));
}
void Test3()
{
AfxMessageBox(L"我是第三个测试按钮");
}
extern "C" int user_initialize()
{
ProError status;
ProFileName MsgFile;
ProStringToWstring(MsgFile, "IconMessage.txt"); //注意此处的IconMessage与后面的text文件夹下的IconMessage.txt文件名必须相同
uiCmdCmdId PushButton1_cmd_id, PushButton2_cmd_id, PushButton3_cmd_id;
status = ProMenubarMenuAdd("MainMenu", "Function", "Help", PRO_B_TRUE, MsgFile);
ProCmdActionAdd("PushButton1_Act", (uiCmdCmdActFn)Test1, 12, AccessDefault, PRO_B_TRUE, PRO_B_TRUE, &PushButton1_cmd_id);
ProMenubarmenuPushbuttonAdd("MainMenu", "PushButton", "FirstButton", "this button will show a message", NULL, PRO_B_TRUE, PushButton1_cmd_id, MsgFile);
ProCmdActionAdd("PushButton2_Act", (uiCmdCmdActFn)Test2, uiCmdPrioDefault, AccessDefault, PRO_B_TRUE, PRO_B_TRUE, &PushButton2_cmd_id);
ProMenubarmenuPushbuttonAdd("MainMenu", "PushButton2", "SecondButton", "this button will show a message", NULL, PRO_B_TRUE, PushButton2_cmd_id, MsgFile);
ProCmdActionAdd("PushButton3_Act", (uiCmdCmdActFn)Test3, uiCmdPrioDefault, AccessDefault, PRO_B_TRUE, PRO_B_TRUE, &PushButton3_cmd_id);
ProMenubarmenuPushbuttonAdd("MainMenu", "PushButton3", "Thirdbutton", "this button will show a message", NULL, PRO_B_TRUE, PushButton3_cmd_id, MsgFile);
return status;
}
extern "C" void user_terminate()
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
}
1.把生成的.dll和lib另放到一个文件夹里:这里我放到:E:\testPro\creo3\CREOFILE
2.在路径E:\testPro\creo3\CREOFILE 下创建protk.dat用于注册
里面内容:(复制进去即可)
name 测试的插件
startup dll
exec_file E:\testPro\creo3\CREOFILE\MFCLibrary4.dll
text_dir E:\testPro\creo3\CREOFILE\TEXT
allow_stop true
delay_start false
end
3.在增加一个TEXT目录,里面放置一个文件,文件名称和代码中要对应,不是随便的
文件里内容:复制即可
Function
UserTestFunction
#
#
FirstButton
A Button
#
#
secondbutton
B Button
#
#
Thirdbutton
C Button
#
#
this button will show a message
this button will show a message
#
#
show first button
show first button
#
#
4.打开下面的creo图标:
5.使用工具”>“辅助应用程序”,点击“注册”,选择之前写好的“protk.dat”文件,选中“测试的插件”,点击“启动”,关闭“辅助应用程序”的小框,可以在工具栏的“工具”中看到实现了上述程序的功能