这是UFUN帮助的官方例子
1 /****************************************************************************** 2 Copyright (c) 1999 Unigraphics Solutions, Inc. 3 Unpublished - All Rights Reserved 4 5 *******************************************************************************/ 6 /* The following example demonstrates how to invoke 7 UF_UI_open_part. */ 8 /* ***** Include Files ***** */ 9 #include <stdio.h> 10 #include <string.h> 11 #include <uf.h> 12 #include <uf_part.h> 13 #include <uf_ui.h> 14 /* ***** Local Prototype ***** */ 15 static logical my_error_handler 16 ( 17 UF_UI_err_data_p_t error_fn_data, 18 char *file_name, 19 int error, 20 UF_PART_load_status_t *error_status, 21 logical *skip_error_disp 22 ); 23 /* ***** Entry Point ***** */ 24 /*ARGSUSED*/ 25 extern void ufusr(char *param, int *ret_code, int len) 26 { 27 /* 28 ********************* 29 variable declarations 30 ********************* 31 */ 32 int response; 33 tag_t part_tag = NULL_TAG; 34 char file_name[MAX_FSPEC_SIZE + 1] = "flange.prt"; 35 const char *message = "part open error"; 36 logical use_display_file = FALSE; 37 UF_PART_load_status_t part_status; 38 UF_UI_err_t error_handler; 39 40 /* 41 ************************************************ 42 initialize the 'struct' as an open part 'struct' 43 and assign the local function prototyped above 44 as the callback 45 ************************************************ 46 */ 47 error_handler.type = UF_UI_open_part_fun; 48 error_handler.fun.open = my_error_handler; 49 /* 50 ************************************************ 51 assign the client data and its size 52 Note: this is an arbitrary usage of the client 53 data. A better use might be to pass the name of 54 a UIStyler dialog which would then be invoked in 55 the callback 56 ************************************************ 57 */ 58 error_handler.fun_data.size = strlen(message) + 1; 59 error_handler.fun_data.data = message; 60 /* 61 ************************************************* 62 call the function, free any allocated memory 63 ************************************************* 64 */ 65 UF_initialize(); 66 UF_UI_open_part(&error_handler, file_name, 67 &use_display_file, 68 &part_tag, &response, &part_status); 69 if (part_status.statuses != NULL) 70 { 71 UF_free(part_status.statuses); 72 } 73 if (part_status.file_names != NULL) 74 { 75 UF_free_string_array(part_status.n_parts, 76 part_status.file_names); 77 } 78 UF_terminate(); 79 } 80 /* ***** local function to be invoked as a callback ***** */ 81 static logical my_error_handler 82 ( 83 UF_UI_err_data_p_t error_fn_data, 84 char *file_name, 85 int error, 86 UF_PART_load_status_t *error_status, 87 logical *skip_error_disp 88 ) 89 { 90 /* 91 *************************************************** 92 this function trivially just prints the client data 93 that it receives as well as the file name and the 94 error 95 As mentioned above, a better usage of the client 96 data would be to pass through the name of a 97 UIStyler dialog to display. Such a use might 98 resemble the following: 99 UF_STYLER_create_dialog ( 100 ( char * ) error_fn_data->data , 101 callbacks , 102 n_callbacks , 103 NULL , 104 &response ); 105 *************************************************** 106 */ 107 fprintf(stderr, "my_error_handler called with: " 108 " error_fn_data->size = %d " 109 " error_fn_data->data = %s " 110 " file_name = %s " 111 " error = %d ", 112 error_fn_data->size, 113 (const char *)error_fn_data->data, 114 file_name, 115 error 116 ); 117 /* ************************************************** 118 instruct NX to display its error dialog and to 119 continue looping within the dialog until a part 120 is opened 121 ************************************************** 122 */ 123 *skip_error_disp = TRUE; 124 return TRUE; 125 }