Frequently Asked Questions about Win32Lib

 

1. What is Win32Lib?

2. What do I need to know to program for Windows?

3. How do I make a program for Windows?

4. How do I make a "control"?

5. What is an "event link"?

6. How do I create an "event link"?

7. Where are the "event links" PLACED in the program?

x. How do I write into a window?

x. How do I draw in a window?

x. How can I write data to a file, and then retreive it to write into a window?

x. How can I use special keys like up/down arrows in windows?

x. How do I create and use a TIMER?

 

 

1. What is Win32Lib?

Answer: Win32Lib is a library of functions created by David Cuny and later expanded by Matthew Lewis and others which makes a large number of Windows programming elements available to the programmer.

Using Win32Lib, you can create one or more windows, and a variety of other "controls" (like push-buttons, menus, text fields, etc.), as well as provide for the occurance of various common "events" (like clicking on a button, pressing a key, etc.).

(top)

 

2. What do I need to know to program for Windows?

Answer: Programming for Windows is somewhat different than regular Dos programming in that Windows Programming is based on the use of "controls", which have "attributes", and, it is "event" oriented. There is also a defined main processing loop.

A "control" is basically any standard visual element available to be included in the program from a pre-existing library of controls, or a non-visual element such as a timer. They include the main & other windows, push buttons, list boxes, timers, etc. You can create them, query and change their Attributes, and respond to Events which happen to them.

An "attribute" is any property a control might have, such as the size or placement of the control, its font size, or font color, etc. Various routines are provided by Win32Lib to let you inspect and alter the attributes of controls.

An "event" is any action that is available to be monitored by Windows (such as clicking on a button, or a timer reaching a preset count, etc.), which is then linked by the programmer to some routine created by the programmer to respond appropriatly to that event .

The call to the main processing loop, "WinMain", is placed at the very end of the program, after all the controls have been declared , after all the routines you have written to handle all of the events you want to respond to in your program, and after all the event links.

(top)

 

3.How do I make a program for Windows?

Answer: To make a program for Windows, you first define what you want it to do; then you:

  1. Write "include win32lib.ew" (without the quotes) at the beginning of your program ;
  2. Establish the look of the program by creating various "controls" (windows, push-buttons, text fields, list boxes, menus, etc) that would be employed by the program user to do various things;
  3. then you create routines (procedures & functions) to respond appropriately to the users use of the controls;
  4. then you create "event links" to make the users use of a control in fact activate the proper procedure or function;
  5. then on the last line in your Windows program you write a statement which creates the main program loop ("WinMain( your_window_name, desired_window_style" ) .

Example:

-- example4.exw
--
-- This opens a window with a single button.
-- Clicking the button closes the window.

include win32lib.ew

-- create a window, and a control (a button) in the window:
constant
TheWindow = create( Window, "Close Window", 0, Default, Default, 200, 100, 0 ),
CloseButton = create( DefPushButton, "Close Window", TheWindow, 40, 10, 120, 30, 0 )

-- routine that accomplishes the desired action:
global procedure onClick_CloseButton()
closeWindow( TheWindow )
end procedure

-- tell Windows when to do the action:
onClick[CloseButton] = routine_id( "onClick_CloseButton" )

-- hand control over to Windows:
WinMain( TheWindow, Normal )

(top)

 

4. How do I make a "control"?

Answer: You make a "control" by using the "create" function. It has the form:

constant your_control_name = create( class, title, parent, x, y, cx, cy, flags)

class is the kind of control you wish to create (Window, PushButton, Menu, etc).
title is the text that will appear in the object's caption.
parent is the name of the control this control belongs to. The parent of the main window is 0.
x and y specify the position of the object, and cx and cy specify the width and height.
flags are optional additional attributes; place a 0 here if you don't know anything else to put.

Example:
The following will create a Window called MyWindow:

      -- create a window 
      constant MyWindow = create( Window,         -- the class 
                              "My Window",        -- the caption      
                              0,                  -- the parent 
                              Default, Default,   -- x and y position 
                              60, 40,             -- width and height 
                              0 )                 -- no special flags 

The following will create a PushButton in MyWindow:

      -- create a pushbutton 
      constant MyButton = create( PushButton,     -- the class 
                                  "Push Me!",     -- the caption      
                                  MyWindow,      -- the parent 
                                  10, 10,         -- x and y position 
                                  60, 40,         -- width and height 
                                  0 )             -- no special flags 

 

5. What is an "event link"?

Answer: An "event link" is a two part statement which establishes a connection between some pre-defined event and the routine which is intended to respond to the event:

  1. the first part references to some particular kind of event which is innately recognized by the Win32Lib library (such as "onClick" the mouse on some control, "onKeyPress", etc);
  2. the second part references to some routine previously created in the program intended to do what you would want to have happen when that event occured.

Example: An event link might look like this:

onClick[CloseButton] = routine_id( "onClick_CloseButton" )

(top)

 

6. How do I create an "event link"?

Answer: To create an "event link",

  1. Determine what kind of event you want to make your program respond to (a click on a button, selection of an item in a list, timer reaching a preset, etc);
  2. then look in the list of events in the Win32Lib manual for the one you want to use (onClick,onKeyPress,onChange, onOpen, etc);
  3. write the event name,
  4. followed by the name of the control which might be acted upon placed in brackets [controlName];
  5. write an equals sign (=);
  6. write "routine_id";
  7. write the name of the routine intended to handle the occurance of the event, placed inside parenthesis and *quotes*: ("routine_name")

It should look like this in general:

EventName[ControlName] = routine_id("event_handler_routine_name")

NOTE: it helps to make the "event_handler_routine_name" reference in some way to the event and the control, like this:

onClick[CloseButton] = routine_id( "onClick_CloseButton" )

top

 

7. Where are the "event links" PLACED in the program?

Answer: The "event links" must go AFTER the routine they point to.

  1. They can be immediately after, so that every event handling routine has its own event trap/link right after it, (which is usually the easiest way to remember to create both of them), or,
  2. they can all be written near the end of the program, just before the WinMain main processing loop. This can be helpful in a large program: after you have written a number of them in your program but before you are finished with the program, if you have consolidated them near the end, you can go down to them quickly, find the one you may be interested in, and then find its related routine by highlighting the routine name & doing a "search" with your editor.

Example 1, routine and event link together:

-- a routine to handle clicking on the "CloseButton":
global procedure onClick_CloseButton()
closeWindow( TheWindow )
end procedure

-- an event link which tells Windows when to do what action:
onClick[CloseButton] = routine_id( "onClick_CloseButton" )

Example 2, all event links grouped together (after the routines they point to):

<begin>
<includes and control creation here>

procedure onOpen_Window1()
-- do something
end procedure

procedure onClick_StartDisplay()
-- do something
end procedure

<all other procedures here>

--EVENTS TO RESPOND TO IN THIS PROGRAM:
----------------------------------------------------------
onOpen[Window1] = routine_id("onOpen_Window1")
onClick[StartDisplay] = routine_id("onClick_StartDisplay")
onClick[StopDisplay] = routine_id("StopDisplay_onClick")
onTimer[Window1] = routine_id("Window1_onTimer")
onClick[btnTestaSound] = routine_id("onClick_btnTestaSound")

-----------------------------------------------------------
-- MAIN PROCESSING LOOP: hand control over to Windows:
WinMain( Window1, Normal )

(top)