|
UG二次开发时,频繁启动UG非常耗时,特别是在UG1.0以后(UG1.0启动较快)。UG本身提供了这种功能:DIALOG CREATION FROM A USER EXIT,即从用户退出创建对话框。具体做法如下:
1、我们创建对话框资源时,.c文件中有如下内容:
/*-------DIALOG CREATION FROM A USER EXIT HELP Example --------
To create this dialog from a user exit, you must invoke a
call to the UG/Open API, UF_STYLER_create_dialog. An example
is shown below.
All dialog files must be located in
$UGII_USER_DIR/application or
$UGII_SITE_DIR/application or
$UGII_VENDOR_DIR/application directory
1) Remove the conditional definitions:
#ifdef DISPLAY_FROM_USER_EXIT
#endif DISPLAY_FROM_USER_EXIT
2) Add a user exit to the function name below, for example, ufusr.
3) Consider how your shared library will be unloaded. Take a look
at the generated function ufusr_ask_unload.
--------------------------------------------------------------*/
#ifdef DISPLAY_FROM_USER_EXIT
extern void <enter a valid user exit here> (char *param, int *retcode, int rlen)
{
int response = 0;
int error_code = 0;
if ( ( UF_initialize() ) != 0 )
return;
if ( ( error_code = UF_STYLER_create_dialog ( "test.dlg",
TEST_cbs, /* Callbacks from dialog */
TEST_COUNT, /* number of callbacks*/
NULL, /* This is your client data */
&response ) ) != 0 )
{
char fail_message[133];
/* Get the user function fail message based on the fail code.*/
UF_get_fail_message(error_code, fail_message);
UF_UI_set_status (fail_message);
printf ( "%s\n", fail_message );
}
UF_terminate();
return;
}
/*--------------------------------------------------------------------------
This function specifies how a shared image is unloaded from memory
within Unigraphics. This function gives you the capability to unload an
internal UG/Open application or user exit from Unigraphics. You can
specify any one of the three constants as a return value to determine
the type of unload to perform: immediately after user function
execution, via an unload selection dialog, or when Unigraphics terminates
terminates. If you choose UF_UNLOAD_SEL_DIALOG, then you have the
option to unload your image by selecting File->Utilities->Unload Shared
Image.
NOTE: A program which associates UG/Open applications with the menubar
MUST NOT use this option since it will UNLOAD your UG/Open application image
--------
from the menubar.
--------------------------------------------------------------------------*/
extern int ufusr_ask_unload (void)
{
/* unload immediately after application exits*/
return ( UF_UNLOAD_IMMEDIATELY );
/*via the unload selection dialog... */
/*return ( UF_UNLOAD_SEL_DIALOG ); */
/*when UG terminates... */
/*return ( UF_UNLOAD_UG_TERMINATE ); */
}
/*--------------------------------------------------------------------------
You have the option of coding the cleanup routine to perform any housekeeping
chores that may need to be performed. If you code the cleanup routine, it is
automatically called by Unigraphics.
--------------------------------------------------------------------------*/
extern void ufusr_cleanup (void)
{
return;
}
#endif /* DISPLAY_FROM_USER_EXIT */
我们删除
#ifdef DISPLAY_FROM_USER_EXIT
#endif DISPLAY_FROM_USER_EXIT
或者定义 DISPLAY_FROM_USER_EXIT ,如
#define DISPLAY_FROM_USER_EXIT
函数
extern void <enter a valid user exit here> (char *param, int *retcode, int rlen)改为
extern void ufusr (char *param, int *retcode, int rlen)
然后就变成:
extern void ufusr(char *param, int *retcode, int rlen)
{
int response = 0;
int error_code = 0;
if ( ( UF_initialize() ) != 0 )
return;
if ( ( error_code = UF_STYLER_create_dialog ( "test.dlg",
TEST_cbs,
TEST_COUNT,
NULL,
&response ) ) != 0 )
{
char fail_message[133];
UF_get_fail_message(error_code, fail_message);
UF_UI_set_status (fail_message);
printf ( "%s\n", fail_message );
}
UF_terminate();
return;
}
extern int ufusr_ask_unload (void)
{
/* unload immediately after application exits*/
return ( UF_UNLOAD_IMMEDIATELY );//用户应用程序退出时立即卸载
//通过File->Utilities->Unload手动卸载用户dll
/*return ( UF_UNLOAD_SEL_DIALOG );*/
//UG退出时,卸载用户dll
/*return ( UF_UNLOAD_UG_TERMINATE ); */
}
extern void ufusr_cleanup (void)
{
return;
}
注意:不要用ufsta,用menuscipt functions也不行(它也要通过ufsta调用)
2、在菜单文件中ACTIONS 用dll动态链接库,不用dlg对话框。如下
! ----------------------------------------------------------------
VERSION 120
EDIT UG_GATEWAY_MAIN_MENUBAR
BEFORE UG_HELP
CASCADE_BUTTON UISTYLER_DLG_TAB_BTN
LABEL TAB
END_OF_BEFORE
MENU UISTYLER_DLG_TAB_BTN
BUTTON TEST_BTN
LABEL TEST
ACTIONS TEST.dll
!或者ACTIONS TEST 可省略.dll后缀
END_OF_MENU
3、动态链接库dll放在application里,菜单文件men放在startup中,所用到的对话框资源,比如位图文件,也可以放在application,系统可以识别出。
以上做好,就可以做到动态加载卸载用户dll了
注意:用户对话框退出时,才卸载用户dll,这时UG不要关闭,就可以修改文件,重新编译链接你的dll(不要执行),然后在UG中通过菜单或工具栏等再次
调用你的程序就可以了。
4、定义编译的动态链接库的路径时,因为输入长路径比较麻烦,可用环境变量如果定义了环境变量UGII_USER_DIR或者其它环境变量UGII_SITE_DIR,可用$(UGII_USER_DIR)/application/test.dll,可以省些事,如下图 |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?注册
x
|