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

I've been building dialog boxes lately with a tremendous number of
controls. I got very tired of having to manage a list of numbered
identifiers, and frustrated with having to deal with keeping too
many little bits in sync with each other.
So, I wrote a tool to let me automagically create control identifier
constants in the dialog box where they are used. Source code follows.
I hope this can be useful.
Rick
\ ----------------------------------------------------------------------
\ Automagic dialog control identifier creation
\ Copyright (c) 2005 Rick VanNorman "rick <at> neverslow <dot> com"
\ Free to use, modify, extend, or enjoy for any use whatsoever.
\ Please give credit, please give back any updates or fixes.
\ ----------------------------------------------------------------------
\ Automagically create resource identifier strings for dialogs.
\
\ The following package allows the programmer to automagically
\ create the constant identifiers for dialog box controls. With
\ it, there is no longer a need to manage a large set of resource
\ identifier constants apart from the dialog definition, nor
\ to program dialog boxes without named identifiers, relying
\ on your wits to keep track of the integer values for each
\ control.
\
\ The identifiers are created starting at an arbitrary value (I
\ chose 1000) and incrementing from there. The named identifiers
\ are defined as constants; the string "ID_" is prepended to
\ each name. Thus, using "ID: RUN" produces a constant whose name
\ is "ID_RUN". The constants cannot be generated during the
\ dialog definition because that would interfere with the dialog
\ template creation. The constants are created after the dialog
\ is defined by simply executing the word "CREATE-IDS". Then,
\ each identifier will be available as a named entity.
0 VALUE IDSTRINGS
0 VALUE IDN
: USE-IDSTRINGS ( -- )
IDSTRINGS 0= IF
65536 ALLOCATE THROW TO IDSTRINGS
THEN 0 IDSTRINGS ! 1000 TO IDN ;
: IDSTRINGS/ ( -- )
IDSTRINGS IF IDSTRINGS FREE THROW 0 TO IDSTRINGS THEN ;
: CREATE-IDS ( -- )
IDSTRINGS 0= THROW IDSTRINGS @+ EVALUATE
IDSTRINGS FREE THROW 0 TO IDSTRINGS ;
: >IDSTRINGS ( addr len -- ) IDSTRINGS XAPPEND ;
: ID: ( -- )
IDSTRINGS 0= IF USE-IDSTRINGS THEN
IDSTRINGS @ 65000 > THROW
IDN (.) >IDSTRINGS S" CONSTANT ID_" >IDSTRINGS
BL WORD COUNT >IDSTRINGS s" " >IDSTRINGS
IDN 1 +TO IDN ;
\ ----------------------------------------------------------------------
\ Simple dialog to illustrate the use of IDSTRINGS
DIALOG (SIMPLE)
[MODAL " Simple Example" 10 10 50 83 (CLASS SFDLG) ]
[PUSHBUTTON " &Run" ID: RUN 5 5 40 12 ]
[PUSHBUTTON " &Start" ID: START 5 20 40 12 ]
[PUSHBUTTON " &Test" ID: TEST 5 35 40 12 ]
[CTEXT " " ID: STAT 5 50 40 12 ]
[DEFPUSHBUTTON " E&xit" IDOK 5 65 40 12 ]
END-DIALOG CREATE-IDS
GENERICDIALOG SUBCLASS SIMPLE-DIALOG
: TEMPLATE ( -- a ) (SIMPLE) ;
IDOK COMMAND: ( -- ) 0 CLOSE-DIALOG ;
IDCANCEL COMMAND: ( -- ) 0 CLOSE-DIALOG ;
: SAY ( z -- )
mHWND ID_STAT ROT :: SetDlgItemText DROP ;
ID_RUN COMMAND: ( -- ) Z" Run" SAY ;
ID_START COMMAND: ( -- ) Z" Start" SAY ;
ID_TEST COMMAND: ( -- ) Z" Test" SAY ;
WM_INITDIALOG MESSAGE: ( -- ) Z" Status" SAY 0 ;
END-CLASS
: GO ( -- )
[OBJECTS SIMPLE-DIALOG MAKES SD OBJECTS]
0 SD MODAL DROP ;
----------------------------------------------------------------------
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 Apr 04 2005 - 16:44:00 PDT
This archive was generated by hypermail 2.2.0 : Thu Dec 04 2008 - 03:04:19 PST