## Defining an Addressbook program screen.

This is a simple example which re-defines our previous database examples, and finally creates a simple addressbook which can actually be used. The code below only shows how the program's screen is created, and provides an active FILE, EXIT in the menu. All the required routines will be added later, and this section will not be shown again.

-- address1.exw

    -- a simple addressbook example, by wolf/Jan./99

    include win32lib.ew

    -- lots of little 'windows'.
    global constant
      MyWin   = create(Window, "AddressBook", 0, 0, 0, 230, 370, 0),
      List1   = create(SortedList, "", MyWin, 10, 10, 200, 60, 0),
    -- ^^ note we are using a sorted list here for the first time. This is a
    --    simple way for us to keep our addressbook alphabetically sorted.
      Label1  = create(LText, "", MyWin, 10, 69, 210, 18, 0),
      Label2  = create(RText, "Last:", MyWin, 10, 92, 65, 20, 0),
      Sle1    = create(EditText, "", MyWin, 80, 89, 130, 22, 0),
      Label3  = create(RText, "First:", MyWin, 10, 117, 65, 20, 0),
      Sle2    = create(EditText, "", MyWin, 80, 114, 130, 22, 0),
      Label4  = create(RText, "Address:", MyWin, 10, 142, 65, 20, 0),
      Sle3    = create(EditText, "", MyWin, 80, 139, 130, 22, 0),
      Label5  = create(RText, "Street:", MyWin, 10, 167, 65, 20, 0),
      Sle4    = create(EditText, "", MyWin, 80, 164, 130, 22, 0),
      Label6  = create(RText, "City:", MyWin, 10, 192, 65, 20, 0),
      Sle5    = create(EditText, "", MyWin, 80, 189, 130, 22, 0),
      Label7  = create(RText, "State:", MyWin, 10, 217, 65, 20, 0),
      Sle6    = create(EditText, "", MyWin, 80, 214, 80, 22, 0),
      Label8  = create(RText, "Zip:", MyWin, 10, 242, 65, 20, 0),
      Sle7    = create(EditText, "", MyWin, 80, 239, 80, 22, 0),
      Label9  = create(RText, "Phone:", MyWin, 10, 267, 65, 20, 0),
      Sle8    = create(EditText, "", MyWin, 80, 264, 130, 22, 0),

    -- all our menu items so far.
      MenuTop   = create(Menu, "&File", MyWin, 0, 0, 0, 0, 0),
      MenuSave  = create(MenuItem, "&Save", MenuTop, 0, 0, 0, 0, 0),
      MenuExit  = create(MenuItem, "Eξt", MenuTop, 0, 0, 0, 0, 0),
      MenuDo    = create(Menu, "&Item", MyWin, 0, 0, 0, 0, 0),
      MenuNew   = create(MenuItem, "&New", MenuDo, 0, 0, 0, 0, 0),
      MenuAdd   = create(MenuItem, "&Add", MenuDo, 0, 0, 0, 0, 0),
      MenuDelete= create(MenuItem, "&Delete", MenuDo, 0, 0, 0, 0, 0),

    -- and all our buttons.
      btnNew  = create(PushButton, "New", MyWin, 10, 290, 40, 25, 0),
      btnAdd  = create(PushButton, "Add", MyWin, 55, 290, 40, 25, 0),
      btnSave = create(PushButton, "Save", MyWin, 100, 290, 50, 25, 0),
      btnDel  = create(PushButton, "Delete", MyWin, 155, 290, 60, 25, 0)

    -- set the background color to Green.
    setWindowBackColor( MyWin, rgb(0,255,127) )

    -- ** further code will mostly be inserted here!

    procedure onMenu_Exit( integer self, integer event, sequence params )  -- this is our 'EXIT' routine.
        closeWindow(MyWin)
    end procedure

    -- and these are our basic event handlers, with only 'exit' usable now.
    setHandler( btnNew, w32HClick, routine_id("onClick_btnNew") )
    setHandler( btnAdd, w32HClick, routine_id("onClick_btnAdd") )
    setHandler( btnSave, w32HClick, routine_id("onClick_btnSave") )
    setHandler( btnDel, w32HClick, routine_id("onClick_btnDel") )
    setHandler( MenuExit, w32HClick, routine_id("onMenu_Exit") )
    setHandler( MenuNew, w32HClick, routine_id("onClick_btnNew") )
    setHandler( MenuAdd, w32HClick, routine_id("onClick_btnAdd") )
    setHandler( MenuSave, w32HClick, routine_id("onClick_btnSave") )
    setHandler( MenuDelete, w32HClick, routine_id("onClick_btnDel") )

    WinMain(MyWin,Normal)

    -- end --

* addendum *

Recent versions of win32lib now have a default background color of CLR_BTNFACE, and have fancy borders around list boxes and edittext boxes.These new features make it very hard to see where these controls are located. I've purposely left the background green in the next few examples because it gives a much more accurate 'picture' of where, exactly, the various controls are located.

Just to give you an idea of how 'picky' one can get, notice that I've placed each 'Label' for it's associated EditText(), 3 pixels below the EditText() control.

..end of lesson.

CONTENTS