Frequently Asked Questions about Win32Lib
2. What do I need to know to program for Windows?
3. How do I make a program for Windows?
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?
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.).
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.
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:
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 )
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
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:
Example: An event link might look like this:
onClick[CloseButton] = routine_id( "onClick_CloseButton" )
6. How do I create an "event link"?
Answer: To create an "event link",
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" )
7. Where are the "event links" PLACED in the program?
Answer: The "event links" must go AFTER the routine they point to.
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 )