|
先看下效果哈(要看效果先回复哦):
其中All Components对话框1
其中All Components对话框2
其中All Components对话框3
二级菜单UI对话框实例
模式菜单
下面附上源代码:
#include"roMenu.h"
#include"roUtil.h"
#include"roMenubar.h"
#include<roMessage.h>
#include<roUIDialog.h>
#include<roUIPushbutton.h>
#include<roUIRadiogroup.h>
#include<roUILabel.h>
#include<roUICheckbutton.h>
#include<roUIInputpanel.h>
#include<ProArray.h>
int ShowMessage();
int ModeMenuActFn();
int MenuActFn();
int MenuActFn1();
static uiCmdAccessState AccessAvailable(uiCmdAccessMode);
static uiCmdAccessState AccessUnAvailable(uiCmdAccessMode);
static uiCmdAccessState AccessRemove(uiCmdAccessMode);
int MenuButton1ActFn();
int MenuButton2ActFn();
int MenuButton3ActFn();
int CheckButton(uiCmdCmdId,uiCmdValue*);
int SetCheckButtonValue(uiCmdCmdId,uiCmdValue*);
int RadioButton(uiCmdCmdId,uiCmdValue*);
int SetRadioButtonValue(uiCmdCmdId,uiCmdValue*);
int ContrlPashButtonShow(uiCmdCmdId,uiCmdValue*);
int ContrlCheckButton(uiCmdCmdId,uiCmdValue*);
void OK_Action(char*,char*,ProAppData);
void CANCEL_Action(char*,char*,ProAppData);
void SelectType_Action(char*,char*,ProAppData);
void Check_Action(char*,char*,ProAppData);
void InputText_Action(char*,char*,ProAppData);
void OK_Action1(char *,char *,ProAppData);
void CANCEL_Action1(char *,char *,ProAppData);
#define OK 1
#define CANCEL 0
typedef struct user_check_but
{
uiCmdCmdId command_ID;
ProBoolean state;
} UserCheckBut;
static ProMenuItemName RadioItemName;
uiCmdAccessId access_id,access_id1;
static UserCheckBut check_button[3];
extern "C" int user_initialize()
{
ProError status;
ProFileName MsgFile;
uiCmdCmdId PushButton_cmd_id,PushButton_cmd_id1,PushButton_cmd_id2,ModeMenu_cmd_id,radio_act;
ProStringToWstring(MsgFile,"Message.txt");//设置菜单信息文件名
//添加菜单条
status=ProMenubarMenuAdd("UserMenuBar","UserMenu","Utilities",PRO_B_TRUE,MsgFile);
//菜单按钮设置
status=ProCmdActionAdd("PushButtonAct",(uiCmdCmdActFn)ShowMessage,uiCmdPrioDefault,
AccessAvailable,PRO_B_TRUE,PRO_B_TRUE,&PushButton_cmd_id);//动态函数设置
status=ProMenubarmenuPushbuttonAdd("UserMenuBar","PushButton","PushButton1",
"Adding a push button to the ProE menu bar",NULL,PRO_B_TRUE,PushButton_cmd_id,MsgFile);//添加菜单按钮
//显示UI对话框所有的元素
status=ProCmdActionAdd("PushButtonAct2",(uiCmdCmdActFn)MenuActFn1,uiCmdPrioDefault,
AccessAvailable,PRO_B_TRUE,PRO_B_TRUE,&PushButton_cmd_id2);//动态函数设置
status=ProMenubarmenuPushbuttonAdd("UserMenuBar","PushButton_UIAll","All Components",
"View all of the components in the UI dialog box",NULL,PRO_B_TRUE,PushButton_cmd_id2,MsgFile);//添加菜单按钮
//菜单复选按钮设置
status=ProCmdOptionAdd("CheckButtonAct",(uiCmdCmdActFn)CheckButton,PRO_B_TRUE,
(uiCmdCmdValFn)SetCheckButtonValue,AccessAvailable,PRO_B_TRUE,PRO_B_TRUE,&check_button[0].command_ID);//动作函数设置
status=ProMenubarmenuChkbuttonAdd("UserMenuBar","CheckButton","CheckButton1",
"Adding a check button to the ProE menu bar",NULL,PRO_B_TRUE,check_button[0].command_ID,MsgFile);//添加复选按钮
//菜单单选按钮组设置
status=ProCmdOptionAdd("RadioGroupOpt",(uiCmdCmdActFn)RadioButton,PRO_B_FALSE,
(uiCmdCmdValFn)SetRadioButtonValue,AccessAvailable,PRO_B_TRUE,PRO_B_TRUE,&radio_act);//动作函数设置
ProMenuItemName radio_group_items[]={"RadioButton1","RadioButton2","RadioButton3",""};//各单选按钮标识名
static ProMenuItemLabel radio_group_labels[]={"RadioButton1","RadioButton2","RadioButton3",""};//各单选按钮标签名
static ProMenuLineHelp radio_group_help[]={"Select radio button 1","Select radio button 2","Select radio button 3"};//各单选按钮提示信息关键字
status=ProMenubarmenuRadiogrpAdd("UserMenuBar","RadioGroup",3,radio_group_items,
radio_group_labels,radio_group_help,NULL,PRO_B_TRUE,radio_act,MsgFile);//添加单选按钮
//下级子菜单设置
status=ProMenubarmenuMenuAdd("UserMenuBar","SubMenu","SubMenu",NULL,PRO_B_TRUE,MsgFile);//添加下级子菜单项
//添加复选按钮来控制“菜单按钮1”项的显示与移除
status=ProCmdOptionAdd("CheckButtonAct1",(uiCmdCmdActFn)ContrlPashButtonShow,PRO_B_TRUE,
(uiCmdCmdValFn)SetCheckButtonValue,AccessAvailable,PRO_B_TRUE,PRO_B_TRUE,&check_button[1].command_ID);//动作函数设置
status=ProMenubarmenuChkbuttonAdd("SubMenu","CheckButton1","RemovePushButton1",
"Switch Push Button Test",NULL,PRO_B_TRUE,check_button[1].command_ID,MsgFile);//添加复选按钮
//添加复选按钮来控制“菜单复选按钮1”项不可选或可选
status=ProCmdOptionAdd("CheckButtonAct2",(uiCmdCmdActFn)ContrlCheckButton,PRO_B_TRUE,
(uiCmdCmdValFn)SetCheckButtonValue,AccessAvailable,PRO_B_TRUE,PRO_B_TRUE,&check_button[2].command_ID);//动作函数设置
status=ProMenubarmenuChkbuttonAdd("SubMenu","CheckButton2","CheckButton1Disenabled",
"Check Button 1 Disenabled Test",NULL,PRO_B_TRUE,check_button[2].command_ID,MsgFile);//添加复选按钮
//添加模式菜单
status=ProCmdActionAdd("ModeMenu",(uiCmdCmdActFn)ModeMenuActFn,uiCmdPrioDefault,
AccessAvailable,PRO_B_TRUE,PRO_B_TRUE,&ModeMenu_cmd_id);//动作函数设置
status=ProMenubarmenuPushbuttonAdd("UserMenuBar","ModeMenu","ModeMenu",
"Starting a mode-specific menu",NULL,PRO_B_TRUE,ModeMenu_cmd_id,MsgFile);//添加模式菜单按钮
//UI对话框菜单按钮设置
status=ProCmdActionAdd("PushButtonAct1",(uiCmdCmdActFn)MenuActFn,uiCmdPrioDefault,
AccessAvailable,PRO_B_TRUE,PRO_B_TRUE,&PushButton_cmd_id1);//动态函数设置
status=ProMenubarmenuPushbuttonAdd("SubMenu","PushButton_UI","UIDialogBox",
"Open a UI Dialog Box",NULL,PRO_B_TRUE,PushButton_cmd_id1,MsgFile);//添加菜单按钮
return status;
}
extern "C" void user_terminate()
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
}
//菜单项访问权限设置
static uiCmdAccessState AccessAvailable(uiCmdAccessMode)
{
return(ACCESS_AVAILABLE);
}
static uiCmdAccessState AccessUnAvailable(uiCmdAccessMode)
{
return(ACCESS_UNAVAILABLE);
}
static uiCmdAccessState AccessRemove(uiCmdAccessMode)
{
return(ACCESS_REMOVE);
}
int ShowMessage()
{
ProFileName MsgFile;
ProStringToWstring(MsgFile,"Message.txt");
ProMessageDisplay(MsgFile,"Push button pressed");
return true;
}
int CheckButton(uiCmdCmdId command,uiCmdValue *p_value)
{
ProFileName MsgFile;
ProStringToWstring(MsgFile,"Message.txt");
check_button[0].state=(ProBoolean)!check_button[0].state;//切换菜单复选按钮项的开关状态
ProMenubarmenuChkbuttonValueGet(p_value,&check_button[0].state);//获得复选按钮之值
if(check_button[0].state)
ProMessageDisplay(MsgFile,"Check button selected");
else
ProMessageDisplay(MsgFile,"Check button cancel");
return 0;
}
int ContrlPashButtonShow(uiCmdCmdId command,uiCmdValue *p_value)
{
ProFileName MsgFile;
ProStringToWstring(MsgFile,"Message.txt");
uiCmdCmdId PushButton_cmd_id;
check_button[1].state=(ProBoolean)!check_button[1].state;
ProCmdCmdIdFind("PushButtonAct",&PushButton_cmd_id);
if(check_button[1].state)
{
ProCmdAccessFuncAdd(PushButton_cmd_id,(uiCmdAccessFn)AccessRemove,&access_id);
ProMessageDisplay(MsgFile,"Push button disappear");
}
else
if(access_id!=(uiCmdAccessId)NULL)
{
ProCmdAccessFuncRemove(PushButton_cmd_id,access_id);
ProMessageDisplay(MsgFile,"Push button appear");
}
return 0;
}
int ContrlCheckButton(uiCmdCmdId command,uiCmdValue *p_value)
{
ProFileName MsgFile;
ProStringToWstring(MsgFile,"Message.txt");
uiCmdCmdId CheckButton_cmd_id;
check_button[2].state=(ProBoolean)!check_button[2].state;
ProCmdCmdIdFind("CheckButtonAct",&CheckButton_cmd_id);
if(check_button[2].state)
{
ProCmdAccessFuncAdd(CheckButton_cmd_id,(uiCmdAccessFn)AccessUnAvailable,&access_id);
ProMessageDisplay(MsgFile,"Check button can't be selected");
}
else
if(access_id!=(uiCmdAccessId)NULL)
{
ProCmdAccessFuncRemove(CheckButton_cmd_id,access_id);
ProMessageDisplay(MsgFile,"Check button can be selected");
}
return 0;
}
int SetCheckButtonValue(uiCmdCmdId command,uiCmdValue *p_value)
{
for(int i=0;i<3;i++)
if(check_button.command_ID==command)
{
ProMenubarmenuChkbuttonValueSet(p_value,check_button.state);
break;
}
return 0;
}
int SetRadioButtonValue(uiCmdCmdId command,uiCmdValue *p_value)
{
ProMenubarMenuRadiogrpValueSet(p_value,RadioItemName);
return 0;
}
int RadioButton(uiCmdCmdId command,uiCmdValue *p_value)
{
ProFileName MagFile;
ProStringToWstring(MagFile,"Message.txt");
ProMenubarMenuRadiogrpValueGet(p_value,RadioItemName);
if(strcmp(RadioItemName,"RadioButton1")==0)
ProMessageDisplay(MagFile,"Radio button 1 selected");
if(strcmp(RadioItemName,"RadioButton2")==0)
ProMessageDisplay(MagFile,"Radio button 2 selected");
if(strcmp(RadioItemName,"RadioButton3")==0)
ProMessageDisplay(MagFile,"Radio button 3 selected");
return 0;
}
//模式菜单设计
int ModeMenuActFn()
{
int menu_id;
//注册菜单文件(.mnu为完整菜单扩展名,.aux为辅助菜单扩展名)
ProMenuFileRegister("Mode_specific","ModeMenu.mnu",&menu_id);
//动作函数设置(包括三个选择按钮和一个退出按钮)
ProMenubuttonActionSet("Mode_specific","Menu Button1",
(ProMenubuttonAction)MenuButton1ActFn,NULL,0);
ProMenubuttonActionSet("Mode_specific","Menu Button2",
(ProMenubuttonAction)MenuButton2ActFn,NULL,0);
ProMenubuttonActionSet("Mode_specific","Menu Button3",
(ProMenubuttonAction)MenuButton3ActFn,NULL,0);
ProMenubuttonActionSet("Mode_specific","Done",
(ProMenubuttonAction)ProMenuDelete,NULL,0);
//创建模式菜单
ProMenuCreate(PROMENUTYPE_MAIN,"Mode_specific",&menu_id);
//激活模式菜单
ProMenuProcess("",&menu_id);
return true;
}
//三个按钮的动作函数
int MenuButton1ActFn()
{
AfxMessageBox(L"选择菜单项1!",MB_OK);
return true;
}
int MenuButton2ActFn()
{
AfxMessageBox(L"选择菜单项2!",MB_OK);
return true;
}
int MenuButton3ActFn()
{
AfxMessageBox(L"选择菜单项3!",MB_OK);
return true;
}
//UI对话框的动作函数
int MenuActFn()
{
ProError status;
char *dialog_name="Usr_sample";
int ActiveDialog_status;
//装入对话框资源
status=ProUIDialogCreate(dialog_name,dialog_name);
if(status!=PRO_TK_NO_ERROR)
{
AfxMessageBox(L"UIDialog CreateCreate error!");
return status;
}
//设置对话框指定元件的动作函数
ProUIRadiogroupSelectActionSet(dialog_name,"SelectType",SelectType_Action,NULL);//设置单选按钮组的动作函数
ProUICheckbuttonActivateActionSet(dialog_name,"Checkbutton1",Check_Action,NULL);//设置复选按钮1的动作函数
ProUICheckbuttonActivateActionSet(dialog_name,"Checkbutton2",Check_Action,NULL);//设置复选按钮2的动作函数
ProUIInputpanelActivateActionSet(dialog_name,"InputText",InputText_Action,NULL);//设置输入框的动作函数
ProUIPushbuttonActivateActionSet(dialog_name,"OK",OK_Action,NULL);//设置OK按钮的动作函数
ProUIPushbuttonActivateActionSet(dialog_name,"Cancel",CANCEL_Action,NULL);//设置Cancel按钮的动作函数
//显示和激活对话框
status=ProUIDialogActivate(dialog_name,&ActiveDialog_status);
if(status!=PRO_TK_NO_ERROR)
{
AfxMessageBox(L"UIDialogActivate error!");
return status;
}
//从内存清楚对话框资源
status=ProUIDialogDestroy(dialog_name);
if(status!=PRO_TK_NO_ERROR)
{
AfxMessageBox(L"UIDialogDestroy error!");
return status;
}
return status;
}
//UI对话框单选按钮组动作函数定义
void SelectType_Action(char *dialog,char *component,ProAppData data)
{
ProLine PromptMessage;
char** names;
ProCharLine strtmp;
int Index;
ProArrayAlloc(0,sizeof(char*),1,(ProArray*)&names);
ProUIRadiogroupSelectednamesGet(dialog,component,&Index,&names);
sprintf(strtmp,"选择基准面:%s",names[0]);
ProStringToWstring(PromptMessage,strtmp);
ProUILabelTextSet(dialog,"ShowMessage",PromptMessage);
ProArrayFree((ProArray*)&names);
}
//UI对话框复选按钮的动作函数定义
void Check_Action(char *dialog,char *component,ProAppData data)
{
ProLine PromptMessage;
ProBoolean set;
ProUICheckbuttonGetState(dialog,component,&set);
if(set)
{
if(strcmp(component,"CheckButtton1")==0)
ProStringToWstring(PromptMessage,"复选按钮1选中");
else
ProStringToWstring(PromptMessage,"复选按钮2选中");
}
else
{
if(strcmp(component,"CheckButtton1")==0)
ProStringToWstring(PromptMessage,"复选按钮1未选中");
else
ProStringToWstring(PromptMessage,"复选按钮2未选中");
}
ProUILabelTextSet(dialog,"ShowMessage",PromptMessage);
}
//UI对话框输入框的动作函数定义
void InputText_Action(char *dialog,char *component,ProAppData data)
{
wchar_t* PromptMessage;
ProUIInputpanelValueGet(dialog,component,&PromptMessage);
ProUILabelTextSet(dialog,"ShowMessage",PromptMessage);
}
//UI对话框“OK”按钮的动作函数定义
void OK_Action(char *dialog,char *component,ProAppData data)
{
ProUIDialogExit(dialog,OK);
}
//UI对话框“CANCEL”按钮的动作函数定义
void CANCEL_Action(char *dialog,char *component,ProAppData data)
{
ProUIDialogExit(dialog,CANCEL);
}
//显示UI对话框所有元素动作函数
int MenuActFn1()
{
ProError status;
char *dialog_name="UI_Allcomponents";
int ActiveDialog_status;
//装入对话框资源
status=ProUIDialogCreate(dialog_name,dialog_name);
if(status!=PRO_TK_NO_ERROR)
{
AfxMessageBox(L"UIDialog CreateCreate error!");
return status;
}
//设置动作函数
ProUIPushbuttonActivateActionSet(dialog_name,"PushButton1",OK_Action1,NULL);//设置OK按钮的动作函数
ProUIPushbuttonActivateActionSet(dialog_name,"PushButton2",CANCEL_Action1,NULL);//设置Cancel按钮的动作函数
//显示和激活对话框
status=ProUIDialogActivate(dialog_name,&ActiveDialog_status);
if(status!=PRO_TK_NO_ERROR)
{
AfxMessageBox(L"UIDialogActivate error!");
return status;
}
//从内存清楚对话框资源
status=ProUIDialogDestroy(dialog_name);
if(status!=PRO_TK_NO_ERROR)
{
AfxMessageBox(L"UIDialogDestroy error!");
return status;
}
return status;
}
void OK_Action1(char *dialog,char *component,ProAppData data)
{
ProUIDialogExit(dialog,OK);
}
void CANCEL_Action1(char *dialog,char *component,ProAppData data)
{
ProUIDialogExit(dialog,CANCEL);
}
其中Message.txt里面的内容是:
UserMenu
UserMenu
菜单条
#
PushButton1
PushButton1
菜单按钮1
#
Adding a push button to the ProE menu bar
Adding a push button to the ProE menu bar
在ProE菜单栏中加一个菜单按钮
#
CheckButton1
CheckButton1
菜单复选按钮1
#
Adding a check button to the ProE menu bar
Adding a check button to the ProE menu bar
在ProE菜单栏中加一个菜单复选按钮
#
RadioButton1
RadioButton1
单选按钮1
#
Select radio button 1
Select radio button 1
选择单选按钮1
#
RadioButton2
RadioButton2
单选按钮2
#
Select radio button 2
Select radio button 2
选择单选按钮2
#
RadioButton3
RadioButton3
单选按钮3
#
Select radio button 3
Select radio button 3
选择单选按钮3
#
SubMenu
SubMenu
菜单控制项
#
RemovePushButton1
RemovePushButton1
移动菜单按钮1
#
Switch Push Button Test
Switch Push Button Test
菜单按钮开关
#
CheckButton1Disenabled
CheckButton1Disenabled
复选按钮1不可选
#
Check Button 1 Disenabled Test
Check Button 1 Disenabled Test
复选按钮1开关
#
Push button pressed
Push button pressed
按下菜单按钮
#
Check button selected
Check button selected
选中复选按钮
#
Check button cancel
Check button cancel
取消复选按钮
#
Radio button 1 selected
Radio button 1 selected
选中单选按钮1
#
Radio button 2 selected
Radio button 2 selected
选中单选按钮2
#
Radio button 3 selected
Radio button 3 selected
选中单选按钮3
#
Push button disappear
Push button disappear
菜单按钮1消失
#
Push button appear
Push button appear
菜单按钮1出现
#
Check button can't be selected
Check button can't be selected
复选按钮1不能被选择
#
Check button can be selected
Check button can be selected
复选按钮1可以被选择
#
ModeMenu
ModeMenu
模式菜单
#
Starting a mode-specific menu
Starting a mode-specific menu
启动模式菜单
#
UIDialogBox
UIDialogBox
UI对话框示例
#
Open a UI Dialog Box
Open a UI Dialog Box
打开一个UI对话框示例
#
All Components
All Components
#
#
View all of the components in the UI dialog box
View all of the components in the UI dialog box
显示UI对话框里所有的元件
# |
|