Re: Rich edit saples?

From: Bob Nash <BNash_at_smud.org>
Date: Thu, 26 Jul 2001 14:59:41 -0700

This is not exactly what you are looking for, but it might get you started.
This was written for me by Rick Van Norman some time ago and I use it
frequently to display static text in a Rich Edit control.

{
===========================================================================
                        VIEW.f - Simple Text Viewer 06Jul01
rjn

\ ***** Read a text file into a read-only edit control (by RVN)

The file viewer is implemented as a stand-alone window, which has no
menu. It contains an edit control for viewing the text.

The main window remembers the handle of the edit control by storing
it in a "window property". See the windows api for GetProp for
details.

On startup, only the failure to create the HEDIT property causes the
creation of the window to fail. On exit, the property is removed.

EDSTYLE has the required style settings for creating an edit control.

HEDIT returns the keys necessary to access the window property which
   has the handle of the edit control.

/VIEWER creates the edit control.

/CONTENTS puts the text pointed to by the creation parameter into
   the edit control.

VIEWER-MESSAGES handles the messages to the file viewer. On creation,
   an edit control is created and filled. All focus messages shift
   focus to the edit control. Size commands force the edit control to
   be resized. Destruction causes the edit control handle property to
   be removed.

Typical Usage:

         CREATE VIEW-FILENAME ," VIEW.txt"
        REQUIRES View

        : APP-VIEW ( -) VIEW-FILENAME COUNT >EXEPATH DISPLAY-FILE ;
============================================================================
= }

OPTIONAL View A simple 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 EDSTYLE

: HEDIT ( -- hwnd zstr ) HWND Z" Text View" ;

: /VIEWER ( -- ior )
   0 Z" edit" 0 EDSTYLE 0 0 0 0 HWND 1 HINST 0 CreateWindowEx
   HEDIT ROT SetProp 0= ;

: /CONTENTS ( -- )
   HEDIT GetProp LPARAM @ SetWindowText DROP
   LPARAM @ FREE DROP ;

[SWITCH VIEWER-MESSAGES DEFWINPROC ( msg -- res )
   WM_CREATE RUN:
      /VIEWER ?DUP ?EXIT /CONTENTS 0 ;
   WM_SETFOCUS RUN:
      HEDIT GetProp SetFocus DROP 0 ;
   WM_SIZE RUN:
      HEDIT GetProp 0 0 LPARAM LOHI 1 MoveWindow DROP 0 ;
   WM_DESTROY RUN:
      HEDIT RemoveProp DROP 0 ;
SWITCH]

:NONAME ( -- res ) MSG LOWORD VIEWER-MESSAGES ; 4 CB: VIEWER-CALLBACK

0 VALUE |FILE| \ holds last file size: valid only immed. after GET-FILE?

: GET-FILE? ( adr len -- adr flag) \ flag is true for a good read
   2DUP R/O OPEN-FILE IF
      DROP 100 ALLOCATE DROP >R
      S" File " R@ ZPLACE R@ ZAPPEND
      S" not found." R@ ZAPPEND R> FALSE EXIT
   THEN ( handle) 0 0 LOCALS| buf n fid | 2DROP
   fid FILE-SIZE 2DROP DUP TO n TO |FILE|
   n 4 + ALLOCATE DROP TO buf 0 buf n + C!
   buf n fid READ-FILE 2DROP
   fid CLOSE-FILE DROP buf TRUE ;

: GET-FILE ( addr len - addr) GET-FILE? DROP ; \ ADD USER ERROR HANDLING
HERE

: DISPLAY-FILE ( addr len -- ) GET-FILE ( a) >R
   Z" File Viewer" VIEWER-CALLBACK DefaultClass DROP
   0 Z" File Viewer" DUP WS_OVERLAPPEDWINDOW CW_USEDEFAULT DUP 2DUP
   0 0 HINST R> CreateWindowEx ?DUP IF
      DUP SW_SHOW ShowWindow DROP UpdateWindow DROP
   ELSE
      0 Z" Failed to start the file viewer." Z" Application"
      MB_OK MessageBox DROP
   THEN ;

: >EXEPATH ( adr n - addr' n')
        EXEPATH ZCOUNT HERE PLACE HERE APPEND HERE COUNT ;

-----Original Message-----
From: Richard Owlett [mailto:rowlett_at_atlascomm.net]
Sent: Thursday, July 26, 2001 1:51 PM
To: sftalk_at_forth.com
Subject: [sftalk] Rich edit saples?

This may be case of newbie not seeing forest for the trees :}

What I find refers to "rich edit controls".

What I want is a window in which has defined:
Background color
Foreground color
Specified font ( NO bold, underlined or italic etc.)

A replacement for type accepting
X Y coordinate of first character of specified string
point size of the entire following string
address count of string to be displayed

Any error checking/prevention would be responsibility of calling routine

My eventual application will produce display similar to Powerpoint by
M$, but throwing out the 90% I don't want and adding the situation
specific features that Powerpoint ignores. Eventually, in a year or two,
I would like to replace background color with selected graphic files.
The environment is displaying hymn lyrics for congregational singing.

----------------------------------------------------------------------
sftalk_at_forth.com The SwiftForth programming discussion email list
To unsubscribe, send subject "unsubscribe sftalk" to listar_at_forth.com
For help with listar commands, send subject "help" to listar_at_forth.com
Archives are located at http://www.forth.com/sftalk -- check them out!
Search the archives! Visit http://www.forth.com/search for details.
----------------------------------------------------------------------
sftalk_at_forth.com The SwiftForth programming discussion email list
To unsubscribe, send subject "unsubscribe sftalk" to listar_at_forth.com
For help with listar commands, send subject "help" to listar_at_forth.com
Archives are located at http://www.forth.com/sftalk -- check them out!
Search the archives! Visit http://www.forth.com/search for details.
Received on Thu Jul 26 2001 - 14:59:56 PDT


Subscribe to our e-mail list service. It's free for all SwiftForth and SwiftX users!

This archive was generated 06-Feb-2012. Archive updated nightly.