查看: 4861|回复: 4

[解决] 用UF_UI_create_filebox()时UG崩溃了

  [复制链接]

4

主题

4

回帖

83

积分

培训VIP会员

积分
83
发表于 2015-5-1 11:53:07 | 显示全部楼层 |阅读模式

请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!

您需要 登录 才可以下载或查看,没有账号?注册

×
: F/ i  u- O' Q) s. ]) m$ {
/*****************************************************************************
! J! h/ W# @5 E- k; u* g5 I# R* J**0 I9 S2 t* Q2 I! U
** createfilebox.cpp/ m$ u9 W$ G! [; [% c& q  S
**7 v. g& V& f$ k+ q
** Description:
9 Z) x9 \8 i3 x: @; g; u& M/ u**     Contains Unigraphics entry points for the application.
! _' E7 M3 e" I2 K5 c, {**
5 `- o. b, s" f4 z) A*****************************************************************************/
0 _7 s/ d( d. L3 P- @3 e3 R$ s; y1 G& r/* Include files */) b5 I: G( A& H/ G' m
#if ! defined ( __hp9000s800 ) && ! defined ( __sgi ) && ! defined ( __sun )0 O) B9 U4 Y( L0 C
#   include <strstream>
& s# y5 K$ m! u0 z#   include <iostream>
0 O3 T1 r0 j( o7 K% i% v3 l$ N- w    using std:strstream;: l* ?/ Q% x) X. B, c
    using std::endl;   
; j, u! G0 s' X    using std::ends;4 Q  i0 G. k: I# ~
    using std::cerr;
1 [  q+ \: ]. E4 x( d#else# W; U5 g% S$ X, G% i9 f# a
#   include <strstream.h>
, I' q$ @, \+ t6 |) X#   include <iostream.h>
5 l, F4 ]; T: C8 h; x#endif
- }" c; L9 m, K! v0 V#include <uf.h>
) A4 f) ^' x; C#include <uf_ui.h>- |9 w# `4 o+ S: t
#include <uf_exit.h>- h5 v. l7 N6 ~5 Z+ _
#define UF_CALL(X) (report_error( __FILE__, __LINE__, #X, (X)))$ q% @8 D9 V% {3 ]1 f4 @
static int report_error( char *file, int line, char *call, int irc)) \: L8 r6 m+ d; g7 g+ ~; s
{# C2 ^, r, R3 S7 r+ e/ X0 h
    if (irc)
; d! p  `0 y8 J5 c+ o    {
6 t2 {2 h. l! g. l+ g        char err[133],
& c! U1 y- e8 b" o$ d             msg[133];
% k; @2 \4 f5 q9 \        sprintf(msg, "*** ERROR code %d at line %d in %s:\n+++ ",
/ E, [/ ?, ?+ V+ T3 O2 w, E. b7 X            irc, line, file);
( m7 R7 Y- C/ m4 W* n        UF_get_fail_message(irc, err);
) I" \( o4 ?0 u0 H/ f) W        UF_print_syslog(msg, FALSE);; ]$ ^/ N7 V7 L& n" E% |
        UF_print_syslog(err, FALSE);& ?3 G" B* N' v. ]' w
        UF_print_syslog("\n", FALSE);7 ?- G3 {& l: ~# g
        UF_print_syslog(call, FALSE);
; Z, o4 Y, Z- `7 O        UF_print_syslog(";\n", FALSE);
9 X5 [$ b# K, [5 _/ \8 v; c        if (!UF_UI_open_listing_window())% l2 s' Z0 [/ o; m6 m% |  U5 f( d
        {5 }  C9 f4 X8 E; c( _- |
            UF_UI_write_listing_window(msg);! G  T# e- C8 W# \0 O1 I
            UF_UI_write_listing_window(err);! e- |7 t" q  ^! w
            UF_UI_write_listing_window("\n");
+ ~4 v8 r( W: H            UF_UI_write_listing_window(call);, X' Z+ C8 X3 u! O% p6 H' v& z
            UF_UI_write_listing_window(";\n");& a1 I; o% O: U1 f/ }
        }
, }, z1 H& \2 S' ]    }
9 o( w& N+ i% W  @: q    return(irc);
7 k( h3 ?( E5 e+ G* b& L}
/ _& ?. a# R1 p( p
* e- d' ?$ b: G/*****************************************************************************1 X8 I' Y9 z% |
**  Activation Methods
1 H: v0 a( n0 {, s*****************************************************************************/
& f) Q# ^8 g$ c$ {1 ?2 {# {( M8 P/*  Explicit Activation
; w0 {* D! P0 p$ Z5 L5 A**      This entry point is used to activate the application explicitly, as in
3 g& L( l3 ~/ i' e: C. n4 _( |2 m**      "File->Execute UG/Open->User Function..." */9 q+ Y# A( b0 }8 s8 q
extern DllExport void ufusr( char *parm, int *returnCode, int rlen )
$ v- D8 S* k2 K+ ]' Q/ T{
' w# i; x/ i% h    /* Initialize the API environment */; b6 ]5 z+ E, W3 N% F
char prompt_string[]="open file";+ {$ ?4 k4 l4 T( P  I1 Y
char title_string[] = "select file";
" y2 w; E, }( s# ] char filter_string[] = "*.prt";
( K4 _. `, R3 f char default_name[] = "my file";
" t7 q  g$ d4 I& b7 z$ i char filename[256];
" G2 I$ ^% n0 \% f; Y int response;2 H( \+ j% L5 z1 ]' K
    if( UF_CALL(UF_initialize()) )
, Q4 X  j# F# ], k, @& j    {- d( V7 E" x, d$ S
        /* Failed to initialize */
* t8 w; z# y! R0 c        return;
* H# G2 p/ Z0 O6 y* p4 @+ e8 Z- \; b    }1 u9 A! Q$ C$ V) `: Y. x: e
    ( G2 I$ w9 x6 U( X4 v. y
    /* TODO: Add your application code here */& c7 K6 a# ]# {: F
UF_UI_create_filebox(prompt_string,title_string,filter_string,default_name,filename,&response);//UF_UI_create_filebox7 |4 M$ M0 z3 L. T% y
    /* Terminate the API environment */8 P2 [$ Y4 d. u
    UF_CALL(UF_terminate());
7 o+ y5 W5 M& d}
- d/ D4 ]) ^) G% H# R! u/*****************************************************************************
4 }. b: i' B( ]9 v  t**  Utilities
5 c+ u$ {# a' _$ T  E8 a*****************************************************************************/
( X) u4 O; ?" O! u# F3 f* u$ {/* Unload Handler- j7 K2 G! D, @0 @2 p
**     This function specifies when to unload your application from Unigraphics.: T+ ~' H! z% t  U
**     If your application registers a callback (from a MenuScript item or a7 p3 x2 f, e* V5 f( c
**     User Defined Object for example), this function MUST return
: v) E& r# p" `. i. F**     "UF_UNLOAD_UG_TERMINATE". */
& U2 a1 D+ B6 E1 d1 _1 Oextern int ufusr_ask_unload( void ). B- M  K) U* P5 F3 L7 ~* u
{. a* o$ }4 V  A. Y* G% l2 X  i
    return( UF_UNLOAD_IMMEDIATELY );
4 Y! T+ o, d8 z' m}' U0 B- V$ U$ e5 I( J$ n

$ d+ U1 ?# p8 G1 Y3 v2 e! z
CreateFilebox.png
上海点团信息科技有限公司,承接UG NX,CATIA,CREO,Solidworks 等CAx软件,Teamcenter,3D Experience等PLM软件,工业4.0数字化软件的实施\二次开发\培训相关业务,详情QQ 939801026 Tel 18301858168 网址 www.doteam.tech
回复

使用道具 举报

320

主题

226

回帖

9784

积分

管理员

PLM之家NX|TC专家

积分
9784
发表于 2015-5-2 20:07:06 | 显示全部楼层
UF_UI_create_filebox 我没有试你这个 $ }. D, f$ }# n# L) @# y

6 _. e, N! F. `- X6 ~1 _不过你加个uf_call或者看下syslog 啥问题 6 J, N8 F: r4 A, N

8 I! {) u. l% C6 N2 I' z- J$ Y
该会员没有填写今日想说内容.
回复 支持 反对

使用道具 举报

4

主题

4

回帖

83

积分

培训VIP会员

积分
83
 楼主| 发表于 2015-5-2 20:18:39 | 显示全部楼层
mildcat 发表于 2015-5-2 20:075 l7 \/ u$ X3 q2 }5 {
UF_UI_create_filebox 我没有试你这个
: u% x: i( u+ E* r1 E; Q) h4 p' D& F6 k7 r1 g. M
不过你加个uf_call或者看下syslog 啥问题
; o- k- ?- |( n
UF_CALL没有报错。打开文件的对话框也生成了。就是在点击ok之后,UG崩掉了。
  k2 C6 D+ S) Q& ]- {  \9 G我想用UF_UI_create_filebox()创建一个打开文件的对话框。UG有别的函数可以创建打开文件的对话框?
上海点团信息科技有限公司,承接UG NX,CATIA,CREO,Solidworks 等CAx软件,Teamcenter,3D Experience等PLM软件,工业4.0数字化软件的实施\二次开发\培训相关业务,详情QQ 939801026 Tel 18301858168 网址 www.doteam.tech
回复 支持 反对

使用道具 举报

8

主题

58

回帖

896

积分

培训VIP会员

积分
896
发表于 2015-5-5 08:31:59 | 显示全部楼层
文星和合 发表于 2015-5-2 20:184 B: |7 g3 D: E9 K" V
UF_CALL没有报错。打开文件的对话框也生成了。就是在点击ok之后,UG崩掉了。$ }: Y  a% ?2 K* s
我想用UF_UI_create_filebox ...

# ]5 q- V, {# t8 T
# X5 _* w; f' k+ d. w9 Y$ N#include <uf.h>
! L9 P. c' E4 n5 g" j#include <uf_ui.h>
3 [" K1 F( V3 t  w& `& e' d#include <uf_exit.h>
* |6 [8 Q4 X2 C3 vextern DllExport void ufusr( char *parm, int *returnCode, int rlen )6 n* s  f' R8 J- F: z1 I: f3 }+ D
{
+ u+ R9 k% b: o& T$ m3 E        /* Initialize the API environment */! N2 O# s4 D) ^, a) T$ ~) Y' H
        char *prompt_string="输入文件名";
: Z/ n# e, c3 }. Y7 w        char *title_string = "另存为";1 V+ x1 D  y2 D, k9 Z7 }
        char *filter_string = "E:\\+*.prt";% u) D$ k' p7 W2 D- o
        char *default_name = "OK-PRT";
/ o4 _3 L1 g# m) H6 ^        char filename[256];
, Y; J/ W4 e% P9 ?. f2 N        int response;& X" [& B0 ]! R  u3 p
        UF_initialize();
4 b- X8 b3 k0 D) t3 h+ x        UF_UI_create_filebox(prompt_string,title_string,filter_string,default_name,filename,&response);# a1 m/ g8 N* w, {1 v1 F
        if (response ==UF_UI_OK)$ X  U+ @: T( G3 q- f6 m
                uc1601(filename,1);
9 R8 y# e5 A/ [! C" C        else if(response ==UF_UI_CANCEL)- R/ \+ L9 u. s2 D" `. ^
                uc1601("取消",1);$ ]8 {/ X4 ^9 o9 i9 q
        UF_terminate();) |$ F  L6 k' m3 S/ b3 }. N; F
}
* M% `! g5 n# F3 S. K. B6 ?$ Uextern int ufusr_ask_unload( void )! H& ]7 |0 ?9 O* i; @1 Q* x
{
: c- l3 ?4 w" q" \8 W1 s' s: {- B4 B# Y        return( UF_UNLOAD_IMMEDIATELY );% B+ {. R- d( `6 X$ a4 h8 c
}

评分

参与人数 1PLM币 +3 收起 理由
admin + 3 很给力!

查看全部评分

上海点团信息科技有限公司,承接UG NX,CATIA,CREO,Solidworks 等CAx软件,Teamcenter,3D Experience等PLM软件,工业4.0数字化软件的实施\二次开发\培训相关业务,详情QQ 939801026 Tel 18301858168 网址 www.doteam.tech
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

在本版发帖
关注公众号
QQ客服返回顶部