The following example illustrates the sequence and the use of UF_UI_lock_ug_access, plus various other UF_UI functions.
 
#include <Xm/XmAll.h>
#include <uf.h>
#include <uf_ui.h>
#include <uf_ui_xt.h>

/*  Local Function Declaration */
static void ok_cb( Widget w, XtPointer client_data,
                   XtPointer call_data);
static void back_cb( Widget w, XtPointer client_data,
                     XtPointer call_data);
static void cancel_cb( Widget w, XtPointer client_data,
                       XtPointer call_data);
static void launch_lock_cb( Widget w, XtPointer button_state,
                            XtPointer client_data);
static UF_UI_change_state_fn_t lock_change_state(int new_state);
static int initialize_uf( void );
static void call_end_dialog_xt ( XtPointer call_data,
                                 XtIntervalId *id );
static void call_end_dialog ( void );
static void clean_up( void );

static void create_custom_dialog(Position x, Position y,
                                 Widget parent);
/*  Local variables used within this file */
static Widget custom_dialog;
static Widget pushb1_w;

/*  Defines */
#define UFUN_INITIALIZED (0)
#define UFUN_NOT_INITIALIZED (1)

extern void
ufusr(char *param, int *retcod, int param_len)
{
  int        rcode;
  Widget     nx_parent;
  Position   x, y;

  /*  Check to see if Ufun is initialized and if it isn't then */
  /*  initialize it                                            */

  if (initialize_uf() == UFUN_NOT_INITIALIZED)
      return;

  /* Use NX parent and standard area 1 for primary menu. */
  nx_parent = (Widget)UF_UI_get_default_parent();
  UF_UI_get_DA2_coords(&x, &y);

  create_custom_dialog(x,y,nx_parent);

  /*  Instantiate the change state function. This is called  */
  /*  whenever NX goes from a lock to an unlock state. This  */
  /*  does not mean that this is called whenever a new DA2 is */
  /*  brought up.                                            */

  rcode = UF_UI_register_change_state_fn(
         (UF_UI_change_state_fn_t)lock_change_state,
         "locktest_change_state");

  if (rcode == UF_UI_FAILURE)
    UF_UI_set_status("Could not set a change state function");

  XtManageChild (custom_dialog);

  UF_terminate();
}

/*  The function to create the custom dialog */

static void create_custom_dialog(Position x, Position y,
                                 Widget parent)
{

  int        i;
  Arg        args[20];
  Widget     form_w;
  XmString   canstr, helpstr, okstr;

  canstr  = XmStringCreate(" Back ", XmSTRING_DEFAULT_CHARSET);
  helpstr = XmStringCreate("Cancel", XmSTRING_DEFAULT_CHARSET);
  okstr   = XmStringCreate("  OK  ", XmSTRING_DEFAULT_CHARSET);

  /* Create the specified dialog. */
  i = 0;
  XtSetArg(args[i], XmNcancelLabelString, canstr);   i++;
  XtSetArg(args[i], XmNhelpLabelString, helpstr);   i++;
  XtSetArg(args[i], XmNokLabelString, okstr);   i++;
  XtSetArg(args[i], XmNx, x+200);   i++;
  XtSetArg(args[i], XmNy, y);   i++;
  XtSetArg(args[i], XmNdefaultPosition, False);   i++;
  XtSetArg(args[i], XmNautoUnmanage, False);  i++;
  XtSetArg(args[i], XmNdeleteResponse, XmDO_NOTHING);  i++;
  XtSetArg(args[i], XmNmarginHeight, 10);  i++;
  XtSetArg(args[i], XmNmarginWidth, 0);  i++;
  XtSetArg(args[i], XmNdialogType, XmDIALOG_WORKING);  i++;

  custom_dialog = XmCreateMessageDialog (parent,
                                         "Lock Example",
                                         args, i);

  XtUnmanageChild( XmMessageBoxGetChild(custom_dialog,
                                        XmDIALOG_MESSAGE_LABEL) );

  XtAddCallback (custom_dialog, XmNcancelCallback, back_cb, NULL);
  XtAddCallback (custom_dialog, XmNokCallback, ok_cb, NULL);
  XtAddCallback (custom_dialog, XmNhelpCallback, cancel_cb, NULL);

  /* Turn the default button off. */
  XtVaSetValues(custom_dialog, XmNdefaultButton, NULL, NULL);

  form_w = XtVaCreateManagedWidget("grp",
                                   xmFormWidgetClass,
                                   custom_dialog,
                                   NULL);

  pushb1_w =  XtVaCreateManagedWidget( "Launch Lock Test",
                  xmPushButtonWidgetClass, form_w,
                  XmNleftAttachment, XmATTACH_FORM,
                  XmNrightAttachment, XmATTACH_FORM,
                  XmNtopAttachment, XmATTACH_FORM,
                  NULL );

  XtAddCallback(pushb1_w,
                XmNactivateCallback,
                (XtCallbackProc) launch_lock_cb,
                NULL);
}

/*********************************************************
    Function:    lock_change_state
    Description: Called whenever NX locks and unlocks its menubar.
                 This is not quite as evident as it used to be
                 since NX's menubar doesn't grey out as much as it
                 used to, but the state changes are still the same.
    Input:       new_state - this is the new lock state of NX.
    Output:      N/A
    Return:      N/A
***********************************************************/

static UF_UI_change_state_fn_t lock_change_state(int new_state)
{
   if (custom_dialog != NULL)
   {
      if (new_state == UF_UI_LOCK)
         XtSetSensitive(pushb1_w, FALSE);

      else if (new_state == UF_UI_UNLOCK)
         XtSetSensitive(pushb1_w, TRUE);

      else if (new_state == UF_UI_ERROR)
       /*  Do any necessary clean up. This is called when */
       /*  UF_UI_set_force_unlock is called.              */
           printf("ERROR clean up time \n");
   }

   return(NULL);

} /* end locktest_change_state */



/**************************************************************
    Function:    launch_lock_cb
    Description: Called whenever the user presses the push
                 button in the custom dialog. This
                 launches a standard Ufun dialog (Point
                 Subfunction). It is demonstrating the use of
                 the lock and unlock  mechanism.
    Input:       w            - the widget with the action
                 button_state - call data
                 client_data  - any data the user wants to
                                pass on.
    Output:      N/A
    Return:      N/A
***************************************************************/

static void
launch_lock_cb( Widget w,
                XtPointer button_state,
                XtPointer client_data)
{
    int    rcode;
    int    def[2];
    double point1[3];
    if (initialize_uf() == UFUN_NOT_INITIALIZED)
         return;

   /*  Call the lock protocol to provide for the correct */
   /*  handshaking.                                     */
    rcode = UF_UI_lock_ug_access (UF_UI_FROM_CUSTOM);
    if (rcode != UF_UI_LOCK_SET)
    {
        UF_UI_set_status("Could not lock NX");
        return;
    }

    def[0] = 0;
    rcode = uc1616("Create Point", def, 0, point1);

    rcode = UF_UI_unlock_ug_access (UF_UI_FROM_CUSTOM);
    if (rcode != UF_UI_UNLOCK_SET)
        UF_UI_set_status("Could not unlock NX");

    UF_terminate();
}

/********************************************************

    Function:    ok_cb
    Description: This is called whenever the OK button is
                 pressed on the custom dialog.
    Input:       w            - the widget with the action
                 client_data  - any data the user wants to
                                pass on.
    Output:      N/A
    Return:      N/A
*********************************************************/
static void
ok_cb( Widget w, XtPointer client_data, XtPointer call_data)
{

  /*  Do any processing at this point in time and then do */
  /*  the necessary clean up.                            */

  clean_up( );
}

/******************************************************
    Function:    back_cb
    Description: This is called whenever the Back button

                 is pressed on the custom dialog.
    Input:       w            - the widget with the action
                 client_data  - any data the user wants to
                                pass on.
    Output:      N/A
    Return:      N/A
*******************************************************/
static void
back_cb( Widget w, XtPointer client_data, XtPointer call_data)
{
  /*  Do any necessary clean up to go back to the previous */
  /*  state */
  clean_up( );
}

/*******************************************************
    Function:    cancel_cb
    Description: This is called whenever the Cancel button
                 is pressed on the custom dialog.
    Input:       w            - the widget with the action
                 client_data  - any data the user wants to
                                pass on.
    Output:      N/A

   Return:      N/A
*************************************************************/
static void
cancel_cb( Widget w, XtPointer client_data,
           XtPointer call_data)
{
  /*  Do any necessary clean up to go back to the previous */
  /*  state */
  clean_up( );
}


/**************************************************************
    Function:    clean_up
    Description: This function does the necessary clean up when
                 leaving your custom dialog.
    Input:       N/A
    Output:      N/A
    Return:      N/A
***************************************************************/
static void clean_up( void )
{
  int rcode;
  if (initialize_uf() == UFUN_NOT_INITIALIZED)
      return;

  if (UF_UI_ask_lock_status() == UF_UI_LOCK)
  {
      if (rcode == UF_UI_FAILURE)
          UF_UI_set_status("Could not call set the change state to
NULL");

      rcode = UF_UI_cancel_uf_dialog(UF_UI_FROM_CUSTOM);
      if (rcode == UF_UI_FAILURE)
      {
        /*  Even with a failure you want to destroy your custom */
        /*  dialog.                                            */
        UF_UI_set_status("Could not Cancel the dialog");
        call_end_dialog();
      }
      else

XtAppAddTimeOut(XtWidgetToApplicationContext(custom_dialog),
                 10,
                 (XtTimerCallbackProc) call_end_dialog_xt,
                 (XtPointer) NULL);
   }
   else
      call_end_dialog();
}


/*  This is called in the XtAppAddTimeOut function in the cancel */
/*  callback.                                                   */
static void call_end_dialog_xt ( XtPointer call_data,
                                 XtIntervalId *id )
{
    call_end_dialog();
}

static void call_end_dialog ( void )
{
  /*  Destroy your custom dialog */
      XtDestroyWidget(custom_dialog);

  /*  Be sure to unregister your change state function. By  */
  /*  passing in a NULL this unregisters the function.  */

      UF_UI_register_change_state_fn( NULL,
                                      "locktest_change_state");

      UF_terminate();
}

/*  This is used to initialize User Function */

static int initialize_uf( void )
{
  int        uf_is_initialized;
  int        initialize_rcode;

  /*  Check to see if Ufun is initialized and if it isn't then */
  /*  initialize it                                            */

  uf_is_initialized = UF_is_initialized();
  if( uf_is_initialized == 0 )
  {
      initialize_rcode = UF_initialize();
      if( initialize_rcode != 0 )
      {
          printf("Could not initialize User Function\n");
          return (UFUN_NOT_INITIALIZED);
      }
  }

  return(UFUN_INITIALIZED);
}

int ufusr_ask_unload(void)
{
   return ( UF_UNLOAD_SEL_DIALOG );
}




 
Figure This is the dialog created by this user function program
 




 
Figure The custom dialog is unmanaged after the Launch Lock Test button has been pressed and the Point Subfunction dialog appears.