home *** CD-ROM | disk | FTP | other *** search
Text File | 1997-06-06 | 2.4 KB | 106 lines | [TEXT/CWIE] |
- {•This sourcecode is an example for creating a FKey coderesource with•}
- {•Metrowerks Pascal. It is copyrighted by Peter Hoerster and released•}
- {•for free use in any Shareware or Freeware product as a way to thank all•}
- {•programmers who share code snippets. You may put this sources on any•}
- {•CD ROM or any Archive Server but you may not sell it. •}
-
- {• For comments please write to <hoerster@muenster.de>•}
-
- unit OpenFile;
-
- interface
-
- uses
- Types, OSUtils, GestaltEqu, Script, notification, Resources, Events,
- PascalA4, QuickDraw, ToolUtils, Memory, LowMem, Scrap,StandardFile;
-
-
-
- {$MAIN}
-
- procedure main;
-
- implementation
-
-
- procedure main;
- var
- oldA4: LongInt;
- myerr: oserr;
- myclipsize: longint;
- myclipHandle: handle;
-
- function GetFile (var gsavereply: SFReply): OSErr;
- var
-
- where: Point;
- typelist: sftypelist;
- begin
- typelist[1] := 'TEXT';
- typelist[2] := 'PICT';
- SetPt(where, 104, 100);
- SFGetFile(where, '', nil, 4, @typeList, nil, gsavereply);
- if not gsavereply.good then
- GetFile := 1
- else
- GetFile := NoErr;
- end;
-
-
- procedure getsaved;
- const
- HeaderSize = 512; { PICT file header - we ignore this }
- var
- fndrinfo: finfo;
- gsaveref: integer;
- gsavereply: sfreply;
-
-
-
- procedure fillclipboard (thetype: OSType);
- begin
- mycliphandle := Tempnewhandle(myclipsize,myerr);
- if myerr=noerr then
- begin
- Temphlock(mycliphandle,myerr); { Read picture portion of file }
- if fsread(gsaveref, myclipsize, mycliphandle^) = noerr then
- begin
- myerr := ZeroScrap;
- myerr := putscrap(myclipsize, thetype, myclipHandle^);
- end;
- Temphunlock(myCliphandle,myerr);
- end;
- TempDisposeHandle(myCliphandle,myerr);
- end;
-
- begin
- if getfile(gsavereply) = noerr then
- if FSOpen(gsaveReply.fname, gsaveReply.vRefNum, gsaveref) = noerr then
- if geteof(gsaveref, myclipsize) = noerr then
- if getfinfo(gsaveReply.fname, gsaveReply.vRefNum, fndrinfo) = noerr then
- if fndrinfo.fdtype = 'PICT' then
- begin
- myerr := SetFPos(gsaveref, FSFromStart, HeaderSize); { Skip over header }
- myclipsize := myclipsize - HeaderSize;
- fillclipboard('PICT')
- end
- else if fndrinfo.fdtype = 'TEXT' then
- begin
- fillclipboard('TEXT')
- end;
- if gsaveref <> 0 then
- begin
- myerr := FSclose(gsaveref);
- gsaveref := 0;
- end;
- end;
-
-
-
-
- begin
- oldA4 := SetCurrentA4;
- getsaved;
- oldA4 := SetA4(oldA4);
- end;
- end.