POPMENU .CPP

// MyFirstMenu.cpp
//
#include "stdafx.h"
#include "ProUtil.h"
#include "ProMenu.h"
#include "ProMessage.h"
#include "ProMenuBar.h"
#define PRO_USE_VAR_ARGS 1
//设置菜单在不同模式下的状态//回调函数
static uiCmdAccessState AccessDefault(uiCmdAccessMode)
{
return ACCESS_AVAILABLE;
}

void First_fun()
{
AfxMessageBox(_T("first fun is working")); // 自定义功能函数
}
void Second_fun()
{
AfxMessageBox(_T("second fun is working"));// 自定义功能函数
}
void Third_fun()
{
AfxMessageBox(_T("third fun is working"));// 自定义功能函数
}
void fourth_fun()
{
AfxMessageBox(_T("fourth fun is working"));// 自定义功能函数
}

int ShowYourMenu() // 浮动菜单入口函数
{
int menu_id;
ProError err;
ProMode mode;
err = ProModeCurrentGet(&mode);
if(mode == PRO_MODE_PART || mode == PRO_MODE_ASSEMBLY) //指定只能在PART和ASM模式下使用
{
ProMenuFileRegister("User_functions", "Sample.mnu", &menu_id);
ProMenubuttonActionSet("User_functions", "The first", 
					   (ProMenubuttonAction)First_fun,NULL, 0);
ProMenubuttonActionSet("User_functions", "The second",
					   (ProMenubuttonAction)Second_fun, NULL, 0);
ProMenubuttonActionSet("User_functions", "The third", 
					   (ProMenubuttonAction)Third_fun,NULL, 0);
ProMenubuttonActionSet("User_functions", "The fourth", 
					   (ProMenubuttonAction)fourth_fun,NULL, 0);
/*
if(mode == PRO_MODE_PART) // 设置在PART 下"The first"是不可见状态
{
err = ProMenubuttonVisibilitySet("User_functions", "The first", PRO_B_FALSE);
}
//*/

ProMenuCreate(PROMENUTYPE_MAIN, "User_functions", &menu_id);
ProMenuProcess("User_functions", &menu_id);
}
return true;
}

// 自定义函数//回调函数
void Test()
{
//AfxMessageBox(_T("Hello World"));
	ShowYourMenu();
}

// 自定义函数//回调函数
void SayHello()
{
 AfxMessageBox(_T("Hello World"));
}
// 自定义函数//回调函数
void About()
{
 AfxMessageBox(_T("By ShiKun"));
}

int UserPopupmenusSetup(); //声明右键菜单入口函数

//函数入口,PROE 与VC 的接口
extern "C" int user_initialize()
{
	ProError status;
	ProFileName MsgFile;
	ProStringToWstring(MsgFile, "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)Test, // Test 是动作函数
	12, AccessDefault, PRO_B_TRUE, PRO_B_TRUE, &PushButton1_cmd_id);
	ProMenubarmenuPushbuttonAdd("MainMenu","PushButton1","FirstButton","this button will show a message", NULL, PRO_B_TRUE, PushButton1_cmd_id, MsgFile); //第一个菜单
	ProCmdIconSet (PushButton1_cmd_id, "PushButton1.gif"); //设置菜单图标
	ProCmdDesignate(PushButton1_cmd_id, "FirstButton", "this button will show a message", "show first button", MsgFile); //使菜单可以拖拽到工具栏

	ProCmdActionAdd("PushButton2_Act",(uiCmdCmdActFn)SayHello, // SayHello 是动作函数
	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); //第二个菜单
	ProCmdIconSet (PushButton2_cmd_id, "PushButton1.gif"); //设置菜单图标

	//uiCmdCmdId PushButton3_cmd_id;
	ProCmdActionAdd("PushButton3_Act",(uiCmdCmdActFn)About, // About 是动作函数
	1,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); //第三个菜单
	ProCmdIconSet (PushButton3_cmd_id, "PushButton1.gif"); //设置菜单图标

	UserPopupmenusSetup();
	return status;
}
//菜单终止时所调用的函数,一般可用来做一些程序的清理工作
extern "C" void user_terminate()
{
	AFX_MANAGE_STATE(AfxGetStaticModuleState());
}


// POPMENU .CPP
#include "stdafx.h"
#include <ProUtil.h>
#include <ProMenu.h>
#include <ProMessage.h>
#include <ProMenuBar.h>
#include <ProNotify.h>
#include <ProPopupmenu.h>
#include <ProSelbuffer.h>
#include <ProArray.h>
#define PRO_USE_VAR_ARGS 1
ProError UserPopmenuNotification(ProMenuName name);
void popaction();
uiCmdAccessState Accessall(uiCmdCmdId command, ProAppData appdata, ProSelection* sel_buffer)
{
return (ACCESS_AVAILABLE);
}
static uiCmdAccessState AccessDefault(uiCmdAccessMode)
{
return ACCESS_AVAILABLE;
}
int UserPopupmenusSetup() // 模型树右键菜单入口函数
{
ProError status;
uiCmdCmdId cmd_id;
ProFileName MsgFile;
ProStringToWstring(MsgFile, "Demo.txt");
// prepare action for right_mouse_menu
status = ProCmdActionAdd("mypopmenu1_act", (uiCmdCmdActFn)popaction,
uiProe2ndImmediate, AccessDefault, PRO_B_FALSE, PRO_B_FALSE, &cmd_id);
//add new menu to the model tree right_mouse_menu
status = ProMenubarmenuPushbuttonAdd("ActionMenu", //model tree menu of systerm
"popmenu1", //your pop menu button name
"mypopmenu1", // the lable(need exist in the msgfile)
"help info", // help info(need exist in the msgfile)
NULL, PRO_B_TRUE, cmd_id, MsgFile);
//add the popup menu notification to the session
status =ProNotificationSet(PRO_POPUPMENU_CREATE_POST,(ProFunction)UserPopmenuNotification);
return 0;
}
ProError UserPopmenuNotification(ProMenuName name) //点击右键时产生的消息
{
ProPopupMenuId menu_id;
uiCmdCmdId cmd_id;
ProError status;
ProLine lable1, lable2;
ProLine help;
//check if the menu being created matches the menu name we want
ProPopupmenuIdGet(name, &menu_id);
if(strcmp(name, "Sel Obj Menu") == 0)
{
// add exist command (popmenu1) to pop menu
status = ProCmdCmdIdFind("mypopmenu1_act", &cmd_id); // "mypopmenu1_act" 在前面已声明
ProStringToWstring(lable1, "first pop menu");
ProStringToWstring(help, "help info");
status = ProPopupmenuButtonAdd(menu_id, PRO_VALUE_UNUSED,
"thepopmenu1", // the lable(need exist in the msgfile)
lable1, help, cmd_id,
(ProPopupmenuAccessFunction)Accessall,
NULL);
// add new command to pop menu
uiCmdCmdId cmd_id_2;
status = ProCmdActionAdd("mypopmenu2_act",
(uiCmdCmdActFn)popaction,
uiProe2ndImmediate,
AccessDefault,
PRO_B_FALSE, PRO_B_FALSE, &cmd_id_2);
ProStringToWstring(lable2, "second pop menu");
status = ProPopupmenuButtonAdd(menu_id, PRO_VALUE_UNUSED,
"thepopmenu2", // the lable(need exist in the msgfile)
lable2, help, cmd_id_2,
(ProPopupmenuAccessFunction)Accessall,
NULL);
}
return PRO_TK_NO_ERROR;
}
void popaction() // 定义菜单函数的动作
{
ProError status;
ProSelection* ret_buff;
status = ProSelbufferSelectionsGet(&ret_buff);
if(status != PRO_TK_NO_ERROR) return;
int num;
status = ProArraySizeGet((ProArray)ret_buff, &num);
if(status != PRO_TK_NO_ERROR) return;
if(num ==1)
{
ProModelitem p_modelitem;
ProSelectionModelitemGet(ret_buff[0], &p_modelitem);
if(p_modelitem.type != PRO_PART)
return;
AfxMessageBox(_T("you choose a part"));
}
ProArrayFree((ProArray*)&ret_buff);
}

ProTK.dat
NAME MyTestMenu
STARTUP dll
EXEC_FILE E:\learn\program\vc\proE\chap2_PopMenu\release\HelloWorld.dll
TEXT_DIR  E:\learn\program\vc\proE\chap2_PopMenu\release\text
ALLOW_STOP TRUE
REVISION 2009
unicode_encoding FALSE
END

text\IconMessage.txt
Function
&UserFunction
#
#
FirstButton
Demo1
#
#
secondbutton
Demo2
#
#
thirdbutton
Demo3
#
#
this button will show a message
this button will show a message
this button will show a message
#
#
show first button
show first button
show first button
#
#

text\Demo.txt
mypopmenu1
mypopmenu1
#
#
help info
help info
#
#
thepopmenu1
thepopmenu1
#
#
thepopmenu2
thepopmenu2
#
#

text\menus\Sample.mnu
User_functions
#
#
The#first
activate Menu button1
#
The#second
activate Menu button2
#
The#third
activate Menu button3
#
The#fourth
activate Menu button4
#
Done
Exit
#

text\Resource
PushButton1.GIF


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值