[futurebasic] Re: [FB] Launching applications

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : January 2002 : Group Archive : Group : All Groups

From: Robert Covington <artlythere@...>
Date: Thu, 3 Jan 2002 23:43:46 -0500
>> David,
>>
>> This is completely out of my realm, but it sounds analogous to
>> double-clicking a document to launch an application. Can you "launch" a
>> known (or newly created) document to bring up the app?
>>
>
>This can be done with appleevents. I think the key here is how the
>finder does this - it uses the creator code and the application
>signature. I figure there must be a way to use these pieces of
>information to do what I want - I'm just not sure how.
>
>I might experiment with aliases...
>
>Cheers
>
>David

This is a way using FB II and the app's creator code.

I don't know how to convert this to FB 3, it would probably be much simpler.

AG wrote this originally I think.

Robert Covington

' Beware The Line Wrap

'---------------Launch FN Globals
DIM RECORD DTPBRec                    'Dimension the desk top data base record
  DIM DTPB.104
DIM END RECORD .DTPBRec

DIM RECORD procSerNumRec              'process serial num used in launch
param rec
  DIM psnHigh&
  DIM psnLow&
DIM END RECORD .procSerNumRec

DIM RECORD LaunchParamBlockRec
  DIM LPBreserved1&                   'LONGINT
  DIM LPBreserved2%                   'INTEGER
  DIM LPBlaunchBlockID%               'INTEGER
  DIM LPBlaunchEPBLength&             'LONGINT
  DIM LPBlaunchFileFlags%             'INTEGER
  DIM LPBlaunchControlFlags%          'LaunchFlags
  DIM LPBlaunchAppSpec&               'FSSpecPtr
  DIM LPBlaunchProcessSN.procSerNumRec'ProcessSerialNumber from above
  DIM LPBlaunchPreferredSize&         'LONGINT
  DIM LPBlaunchMinimumSize&           'LONGINT
  DIM LPBlaunchAvailableSize&         'LONGINT
  DIM LPBlaunchAppParameters&         'AppParametersPtr
DIM END RECORD .LaunchParamBlockRec

DIM RECORD FSSpec                     'Dim the file spec record
  DIM fsVRefNum%
  DIM fsParID&
  DIM 63 fsName$
DIM END RECORD .FSSpec


END GLOBALS

'--------------------------LaunchPoserFN
CLEAR LOCAL MODE
DIM osErr%
'___________________________________________________
LOCAL FN LaunchApplication (launchPtr&)'launch the application
  '___________________________________________________
  `  SUBQ.L    #2,sp                    ;clear space for osErr
  `  MOVE.L    ^launchPtr&,-(sp)        ;push fileSpec ptr on stack
  `  DC.W      $205F,$A9F2,$3E80        ;trap number
  `  MOVE.W    (sp)+,^osErr%            ;D0 = osErr
END FN = osErr%


LOCAL MODE
'___________________________________________________
LOCAL FN PBDTGetPath(DBRecPtr&)       'get the location of the dt data base
  '___________________________________________________
  `     subq.l  #2,sp                           ;Space for result
  `     move.l  ^DBRecPtr&,-(sp)                ;pBlock for call
  `     dc.w    $205F,$7020,$A260,$3E80         ;INLINE
  `     move.w  (sp)+,D0                        ;Put result in D0
  `     ext.l   D0                              ;Extend for looks
END FN


LOCAL MODE
'___________________________________________________
LOCAL FN PBDTGetAPPLSync(DBPBPtr&)    'find the appl location
  '___________________________________________________
  `     subq.l  #2,sp
  `     move.l  ^DBPBPtr&,-(sp)
  `     dc.w    $205F,$7027,$A260,$3E80         ;INLINE
  `     move.w  (sp)+,D0
  `     ext.l   D0
END FN


CLEAR LOCAL MODE
DIM result%,OSErr,NoteExists,MyVol%
DIM theDB.DTPBRec
DIM theLPB.LaunchParamBlockRec
DIM theFSSpec.FSSpec
DIM resFileID%
DIM CurFileID%
DIM OSErr%
'___________________________________________________
LOCAL FN SearchDTDB(Creator&)
  '___________________________________________________
  OSErr% = _noErr
  CurFileID% = FN CURRESFILE          'record the current res file
  theDB.ioCompletion& = _nil          'no completion
  theDB.ioNamePtr&    = _nil          'Don't care yet
  theDB.ioVRefNum%    = -1            'Boot volume only
  OSErr% = FN PBDTGetPath(@theDB)     'Is anyone out there?
  LONG IF OSErr = _noErr              'Have a DT DB?
    _ioFileCreator = 52               'Offset for pBlock
    _ioAPPLParID   = 100              'Offset for pBlock
    theDB.ioWDIndex%     = 0          'Most recent creation date = 0
    theDB.ioFileCreator& = Creator&   'The target's signature passed to FN
    theDB.ioNamePtr&     = @theFSSpec.fsName$'Call puts name here
    OSErr = FN PBDTGetAPPLSync(@theDB)'Find application itself
    LONG IF OSErr = _noErr            'Ok?
      theFSSpec.fsVRefNum%        = theDB.ioVRefNum%'We need volume ref number
      theFSSpec.fsParID&          = theDB.ioAPPLParID&'and param ID


      theLPB.launchBlockID%       = _extendedBlock'Use extended block
      theLPB.launchEPBLength%     = _extendedBlockLen'Length of extended block
      theLPB.launchFileFlags% = 0
      theLPB.launchControlFlags%  =
_launchContinue_launchNoFileFlags_launchUseMinimum
      theLPB.launchAppSpec&       = @theFSSpec'The filespec to the application
      theLPB.launchAppParameters& = &00000000


      OSErr = FN LaunchApplication(@theLPB)

    END IF


  END IF
END FN = OSErr%                       'of  FN SearchDTDB


'Launch SimpleText for a test.

result% = FN SearchDTDB(_"ttxt")