programming tools for Windows applications development
  Home  |   SwiftForth Archive  |   SwiftX Archive  |

Re: FILENAME for open file

From: Virgil Stamps <vstamps_at_houston.rr.com>
Date: Mon, 13 Jun 2005 20:55:01 -0500

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 ;
\ ===== Read file to memory

\ ===== 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= ;

: /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

\ ===== 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=20
below ? ( Mike ?)

Following is a stripped down section to get a filename=20
for opening the file. It works fine, using=20
   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=20
not work.=20

Alternately; as is, " try pad zcount type " types the=20
name correctly, but with "pad...." removed,=20
" 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
reports, please send email to support_at_forth.com
----------------------------------------------------------------------
Received on Mon Jun 13 2005 - 18:52:55 PDT

This archive was generated by hypermail 2.2.0 : Thu Dec 04 2008 - 03:04:20 PST