| How can I bring up the VAR-LINK dialog and get the name of the selected file?

Previous | Input: Keyboard and Link | Next

Q: | How do I bring up the VAR-LINK dialog from C code and then get the name of the file that was selected?
A: | This is an advanced question. As the VAR-LINK dialog is an event-driven applet, you must use event-driven functions defined in the events.h header file. Bringing up the VAR-LINK dialog is quite easy:
    EVENT ev;
    ev.Type = CM_KEYPRESS;
    ev.extra.Key.Code = KEY_VARLNK;
    EV_defaultHandler (&ev);
but getting the name of the file that was selected is a bit harder. After executing the VAR-LINK dialog, the VAR-LINK applet will send the name of the selected file to the current application via the CM_HSTRING message. This message may be captured by a user event handler. Here is the demonstration program (called "Get File Name"):
    // Open VAR-LINK dialog and let user select something

    #define USE_TI89              // Compile for TI-89
    #define USE_TI92PLUS          // Compile for TI-92 Plus
    #define USE_V200              // Compile for V200

    #define MIN_AMS 100           // Compile for AMS 1.00 or higher
    #define SAVE_SCREEN           // Save/Restore LCD Contents

    #include <tigcclib.h>         // Include All Header Files

    char VarBuffer[20] = "";

    CALLBACK void VarLinkHandler (EVENT *ev)
    {
      if (ev->Type == CM_HSTRING)
        {
          strncpy (VarBuffer, HeapDeref (ev->extra.hPasteText), 19);
          VarBuffer [19] = 0;
        }
      EV_defaultHandler (ev);
    }

    void VarLinkDialog (void)
    {
      EVENT ev;
      EVENT_HANDLER OldHandler = EV_captureEvents (VarLinkHandler);
      memset (&ev, sizeof (ev), 0);
      ev.Type = CM_KEYPRESS;
      ev.extra.Key.Code = KEY_VARLNK;
      EV_defaultHandler (&ev);
      EV_captureEvents (OldHandler);
    }

    void _main(void)
    {
      VarLinkDialog ();
      printf_xy (0, 50, "You picked: %s", VarBuffer);
      ngetchx ();
    }
Read more about the events.h header file: incredible miracles may be produced using event-passing techniques!