|
马上注册,结交更多同行朋友,交流,分享,学习。
您需要 登录 才可以下载或查看,没有帐号?注册
x
这次以UG提供的UG\help中的uf_sample_app.c为例进行说明,为了便于理解,仅对程序中的第二项回调函数SAMPLE_APP__action2进行分析,程序段如下:
static void SAMPLE_APP__enter( void );
static void SAMPLE_APP__init( void );
static void SAMPLE_APP__exit( void );
static UF_MB_cb_status_t SAMPLE_APP__action2(
UF_MB_widget_t widget,
UF_MB_data_t client_data,
UF_MB_activated_button_p_t call_button );
static int app_id = 0;
static UF_MB_action_t actionTable[] =
{
{ "SAMPLE_APP__action2", SAMPLE_APP__action2, NULL },
{ NULL, NULL, NULL }
};
static void print_error(char*fun, int status);
extern void ufsta( char *param, int *returnCode, int rlen )
{
UF_MB_application_t appData;
char name[] = "SAMPLE_APP";
int status;
int ifail=0;
/* Initialize the API environment */
ifail= UF_initialize();
if ( !ifail )
{
status = UF_MB_add_actions( actionTable );
/* TODO: Add your application code here */
/* Initialize application data */
appData.name = name;
appData.id = 0;
appData.init_proc = SAMPLE_APP__init;
appData.exit_proc = SAMPLE_APP__exit;
appData.enter_proc = SAMPLE_APP__enter;
/* Initialize application support flags */
appData.drawings_supported = TRUE;
appData.design_in_context_supported = TRUE;
/* Register the application with UG */
status = UF_MB_register_application( &appData );
app_id=appData.id;
/* Terminate the API environment */
//errorCode = UF_terminate();
}
else
{
char message[133];
UF_get_fail_message( ifail, message );
/* Print out the message */
UF_UI_set_status( message );
fprintf( stderr, "%s\n", message );
}
ifail = UF_terminate();
}
/*****************************************************************************
** Utilities
*****************************************************************************/
/* Unload Handler
** This function specifies when to unload your application from Unigraphics.
** If your application registers a callback (from a MenuScript item or a
** User Defined Object for example), this function MUST return
** "UF_UNLOAD_UG_TERMINATE". */
//extern int ufusr_ask_unload( void )
//{
// return( UF_UNLOAD_IMMEDIATELY );
//}
static void print_error( char *fun, int status )
{
if ( status != 0 )
{
char msg[133];
UF_get_fail_message( status, msg );
printf( "%s failed with error = %d\n %s\n", fun, status, msg );
}
}
static void SAMPLE_APP__enter( void)
{
printf( "Entering application\n" );
/* Place code to enter application here */
}
static void SAMPLE_APP__init( void )
{
printf( "Initializing application\n" );
/* Place code to initialize application here */
}
static void SAMPLE_APP__exit( void )
{
printf( "Exiting application\n" );
/* Place code to cleanup for application and exit here */
}
/*----------------------------------------------------------------------------*
* SAMPLE_APP__action2
*
* Allow the user to specify this function's return value
*----------------------------------------------------------------------------*/
static UF_MB_cb_status_t SAMPLE_APP__action2(
UF_MB_widget_t widget,
UF_MB_data_t client_data,
UF_MB_activated_button_p_t call_button )
{
char options[5][38] = { "UF_MB_CB_CONTINUE",
"UF_MB_CB_CANCEL",
"UF_MB_CB_OVERRIDE_STANDARD",
"UF_MB_CB_WARNING",
"UF_MB_CB_ERROR"
};
char msg[133];
int option_number=5;
int response=0;
UF_MB_cb_status_t cb_value = UF_MB_CB_CANCEL;
if(UF_initialize()!=0)
return (UF_UI_CB_CONTINUE_DIALOG);
response = uc1603( "Choose value to return", 0, options, option_number );
switch ( response )
{
case 1:
case 2:
cb_value = UF_MB_CB_CANCEL;
printf( " Response = \"%s\" (%d)\n",
( response == 1 ? "Back" : "Cancel" ), response );
break;
case 5:
cb_value = UF_MB_CB_CONTINUE;
break;
case 6:
cb_value = UF_MB_CB_CANCEL;
break;
case 7:
cb_value = UF_MB_CB_OVERRIDE_STANDARD;
break;
case 8:
cb_value = UF_MB_CB_WARNING;
break;
case 9:
cb_value = UF_MB_CB_ERROR;
break;
default:
cb_value = UF_MB_CB_ERROR;
printf( " Response = \"%s\" (%d)\n", "Unexpected", response );
sprintf(msg, "Response number is %d",response);
UF_UI_lock_ug_access( UF_UI_FROM_CUSTOM );
uc1601( msg, 1 );
UF_UI_unlock_ug_access( UF_UI_FROM_CUSTOM );
break;
}
printf( "Return = %s\n", options[response - 5][0] );
return( cb_value );
}
其启动菜单按如下设置:
出了点出问题,后面再接着发,请大家稍微等等了.....
[ 本帖最后由 j_tian 于 2008-11-16 17:35 编辑 ] |
|