![]() |
||
| Home | SwiftForth Archive | SwiftX Archive | |

Virgil,
Thanks; its not what I asked for but is what I will surely find=20
useful, to view a text file ( from a menu).=20
I select and open a file no problem; I was puzzled by having to=20
save the addr at pad and not being able to pass it on the stack.
Cheers - Anil
-----Original Message-----
From: Virgil Stamps [mailto:vstamps_at_houston.rr.com]
Sent: Monday, June 13, 2005 9:55 PM
To: sftalk_at_forth.com
Subject: [sftalk] Re: FILENAME for open file
Anil,
Here is some working code to select and read a file. I hope what you =
need is
embedded here for you.
Virgil
{
-------------------------------------------------------------------------=
--
DISPLAY EVENT LOG
-------------------------------------------------------------------------=
--
}
1440 35 * CONSTANT EventSize \ 1440 minutes * 35 bytes/record
\ hh:mm:ss LOC Standby Set<crlf>
CREATE EventView EventSize ALLOT EventView EventSize ERASE
CREATE Event-FILES ,Z" Event files (*.EVN; *.EVN; *.EVN)" ,Z" *.EVN;
*.EVN; *.EVN" 0 ,
OFN-DIALOGS +ORDER
OFN-DIALOG SUBCLASS Event-FILE-DIALOG
: CUSTOM ( -- title filter flags ) Z" Select file" Event-FILES
DEFAULT-OPEN-FLAGS OFN_OVERWRITEPROMPT OR ;
END-CLASS
OFN-DIALOGS -ORDER
: GET-Event ( fid -- ) >R \ read Event file from disk
EventView EventSize R@ READ-FILE IF
R> 2DROP EXIT THEN DROP
R> FREE THROW ;
0 VALUE SizeOfEvent
: SELECT-EVENT-TO-RECEIVE ( addr len -- ) \ get .TXT event file from
disk
R/O OPEN-FILE IF
DROP EXIT THEN
DUP >R DUP FILE-SIZE 2DROP TO SizeOfEvent
['] GET-Event CATCH
IF DROP THEN
R> CLOSE-FILE DROP ;
CREATE eventnameholder 256 ALLOT eventnameholder 256 ERASE
: CHOOSE-EVENT-FILE \ load a event file from disk
EventView EventSize ERASE
[OBJECTS Event-FILE-DIALOG MAKES IFD OBJECTS]
IFD CHOOSE IF IFD FileName
DUP ZCOUNT -PATH eventnameholder swap cmove
ZCOUNT SELECT-EVENT-TO-RECEIVE THEN ;
\ =3D=3D=3D=3D=3D Read file to memory
\ =3D=3D=3D=3D=3D Setup file viewer
0 WS_CHILD OR WS_VISIBLE OR WS_VSCROLL OR
WS_BORDER OR ES_LEFT OR ES_MULTILINE OR
ES_AUTOVSCROLL OR ES_READONLY OR
CONSTANT ELSTYLE
: EL-HEDIT ( -- hwnd zstr ) HWND Z" Daily Event Viewer" ;
: /EL-VIEWER ( - ior )
0 Z" edit" 0 ELSTYLE 0 0 0 0 HWND 1 HINST 0 CreateWindowEx
EL-HEDIT ROT SetProp 0=3D ;
: /EL-CONTENTS ( -- )
EL-HEDIT GetProp LPARAM @ SetWindowText DROP
LPARAM @ FREE DROP ;
[SWITCH EL-MESSAGES DEFWINPROC ( msg -- res )
WM_CREATE RUN:
/EL-VIEWER ?DUP ?EXIT /EL-CONTENTS 0 ;
WM_SETFOCUS RUN:
EL-HEDIT GetProp SetFocus DROP 0 ;
WM_SIZE RUN:
EL-HEDIT GetProp 0 0 LPARAM LOHI 1 MoveWindow DROP 0 ;
WM_DESTROY RUN:
EL-HEDIT RemoveProp DROP 0 ;
SWITCH]
:NONAME ( -- res ) MSG LOWORD EL-MESSAGES ; 4 CB: EL-CALLBACK
\ =3D=3D=3D=3D=3D Show eventfile in separate window
: (show-event) ( adr -) \ show eventfile
( buffer_address -- ) >R ( Z" Event Viewer" ZCOUNT PAD ZPlace)
eventnameholder
EL-CALLBACK DefaultClass DROP
0 ( Z" Event Viewer" ZCOUNT PAD ZPlace) eventnameholder
DUP WS_OVERLAPPEDWINDOW 100 100 280 200 \ CW_USEDEFAULT DUP 2DUP
0 0 HINST R> CreateWindowEx ?DUP IF
DUP SW_SHOW ShowWindow DROP UpdateWindow DROP
ELSE
0 Z" Failed to start event log viewer." Z" Event Log Viewer"
MB_OK MessageBox DROP
THEN ;
: VIEW-EVENT ( -- res) CHOOSE-EVENT-FILE EventView (show-event) 0 =
;
-----Original Message-----
From: sftalk-bounce_at_forth.com [mailto:sftalk-bounce_at_forth.com] On Behalf =
Of
Anil Rodrigues
Sent: Monday, June 13, 2005 2:41 PM
To: sftalk_at_forth.com
Subject: [sftalk] FILENAME for open file
Can someone explain what I am missing as described=3D20
below ? ( Mike ?)
Following is a stripped down section to get a filename=3D20
for opening the file. It works fine, using=3D20
try pad zcount r/o open-file
However if I remove the "pad zcount zplace" from "try"
and let FILENAME leave the addr on the stack , it does=3D20
not work.=3D20
Alternately; as is, " try pad zcount type " types the=3D20
name correctly, but with "pad...." removed,=3D20
" try zcount type" prints junk.
The code follows:
Thanks, Anil
----------------------------------------------------------------------
sftalk_at_forth.com The SwiftForth programming discussion email list
To unsubscribe, send subject "unsubscribe" to sftalk-request_at_forth.com
For list command help, send subject "help" to sftalk-request_at_forth.com
Message archives are located at http://www.forth.com/archive/sftalk
----------------------------------------------------------------------
This list is a forum for SwiftForth users. For product support and bug=20
reports, please send email to support_at_forth.com
----------------------------------------------------------------------
----------------------------------------------------------------------
sftalk_at_forth.com The SwiftForth programming discussion email list
To unsubscribe, send subject "unsubscribe" to sftalk-request_at_forth.com
For list command help, send subject "help" to sftalk-request_at_forth.com
Message archives are located at http://www.forth.com/archive/sftalk
----------------------------------------------------------------------
This list is a forum for SwiftForth users. For product support and bug
reports, please send email to support_at_forth.com
----------------------------------------------------------------------
Received on Tue Jun 14 2005 - 08:28:04 PDT
This archive was generated by hypermail 2.2.0 : Wed Nov 19 2008 - 03:04:25 PST