#include <WinTen.h>
#include <Windows.h>
#include <ClipApi.h>

static char cHelpFile[ 50 ];
static char cHelpTopic[ 100 ];
static LONG lHelpTopic;

//----------------------------------------------------------------------------//

CLIPPER WINHELP()
{
   _retl( WinHelp( GetActiveWindow(),
          _parc( 1 ),
          ( PCOUNT() > 1 ) ? _parni( 2 ): HELP_CONTENTS,
          ( LONG ) ( ( PCOUNT() > 2 ) ?
          ( ISCHAR( 3 ) ? ( LONG ) _parc( 3 ):_parnl( 3 ) ): 0 ) ) );
}

//----------------------------------------------------------------------------//

CLIPPER HelpIndex()
{
   if( cHelpFile[ 0 ] )
      WinHelp( GetActiveWindow(), cHelpFile, HELP_CONTENTS, 0 );
}

//----------------------------------------------------------------------------//

CLIPPER HelpSearch()
{
   if( cHelpFile[ 0 ] )
      WinHelp( GetActiveWindow(), cHelpFile, HELP_PARTIALKEY,
               ( LONG ) ( PCOUNT() ? _parc( 1 ): "" ) );
}

//----------------------------------------------------------------------------//

CLIPPER HelpSetTop()     // ic
{
   if( PCOUNT() )
   {
      if( ISCHAR( 1 ) )
      {
         _bcopy( cHelpTopic, _parc( 1 ),
                 ( _parclen( 1 ) > 99 ) ? 99: _parclen( 1 ) );
         cHelpTopic[ ( _parclen( 1 ) > 99 ) ? 99: _parclen( 1 ) ] = 0;
      }
      else
      {
         lHelpTopic = _parnl( 1 );
         cHelpTopic[ 0 ] = 0;
      }
   }
   else
   {
      cHelpTopic[ 0 ] = 0;
      lHelpTopic = 0;
   }
}

//----------------------------------------------------------------------------//

CLIPPER HelpTopic()
{
   if( ! cHelpFile[ 0 ] )
   {
      MessageBox( GetActiveWindow(),
                  "No Help file available", "Atention",
                  MB_ICONINFORMATION );
      return;
   }

   if( PCOUNT() )
   {
      if( cHelpFile[ 0 ] )
      {
         WinHelp( GetActiveWindow(), cHelpFile,
                  ISCHAR( 1 ) ? HELP_KEY: HELP_CONTEXT,
                  // ISCHAR( 1 ) ? HELP_KEY: HELP_CONTEXTPOPUP,
                  ISCHAR( 1 ) ? ( LONG ) _parc( 1 ):_parnl( 1 ) );
      }
   }
   else
   {
      if( cHelpTopic[ 0 ] )
      {
         WinHelp( GetActiveWindow(), cHelpFile, HELP_KEY,
                  ( LONG ) cHelpTopic );
      }
      else
         WinHelp( GetActiveWindow(), cHelpFile, HELP_CONTEXT, lHelpTopic );
         // WinHelp( GetActiveWindow(), cHelpFile, HELP_CONTEXTPOPUP, lHelpTopic );
   }
}

//----------------------------------------------------------------------------//

CLIPPER HelpSetPos()
{
   HELPWININFO WinInfo;

   WinInfo.x    = _parni( 1 );
   WinInfo.y    = _parni( 2 );
   WinInfo.dx   = _parni( 3 );
   WinInfo.dy   = _parni( 4 );
   WinInfo.wMax = _parl( 5 );
   WinInfo.wStructSize = sizeof( HELPWININFO );
   WinInfo.rgchMember[ 0 ] = 0;
   WinInfo.rgchMember[ 1 ] = 0;

   if( cHelpFile[ 0 ] )
      WinHelp( GetActiveWindow(), cHelpFile, HELP_SETWINPOS,
               ( LONG ) &WinInfo );
}

//----------------------------------------------------------------------------//

CLIPPER SETHELPFIL()     // E
{
   if( PCOUNT() )
      strcpy( cHelpFile, _parc( 1 ) );
}

//----------------------------------------------------------------------------//

CLIPPER GetHelpFil() { _retc( cHelpFile[ 0 ] ? cHelpFile: "" ); }

//----------------------------------------------------------------------------//

CLIPPER GetHelpTop() // ic()
{
   if( cHelpFile )
      _retc( cHelpTopic );
   else
      _retnl( lHelpTopic );
}

//----------------------------------------------------------------------------//
