Re: drawLine( ) fails?
- Posted by DerekParnell (admin) Aug 26, 2010
- 1139 views
I can not get drawLine() or drawLines() to put anything into the window. I am using the latest version of win32Lib. What am I doing wrong?
Louis.
include win32lib.ew constant Main = create(Window, "No line?", 0, 0, 0, 200, 200, 0) setPenColor(Main, Black) drawLine(Main, 10, 10, 190, 190) WinMain(Main, Normal)
The problem is that Main window doesn't kinda exist until the WinMain() is called. Is does exist but it isn't usable until WinMain() starts. Here is some alternate code ...
include win32lib.ew constant Main = create(Window, "No line?", 0, 0, 0, 200, 200, 0) procedure onActivate_Main(integer self, integer event, sequence parms) -- This gets run whenever the Main window is activated. setPenColor(self, Black) drawLine(self, 10, 10, 190, 190) end procedure setHandler(Main, w32HActivate, routine_id("onActivate_Main")) WinMain(Main, Normal)
Programming for a GUI like Windowstm is a lot different from writing a console application. For GUI programs, you need to write a lot of small routines that handle specific events that might happen. The order that the events happen in is determined by what the user does.
In the code above, there is a small routine that is run everytime that the Main window s activated. The w32HActivate is one of the many possible types of events that can occur in a GUI system. The call to setHandler() sets up a connection between a GUI control, an event, and a routine to process (handle) the event for that control.
In the sample code above, the procedure onActivate_Main() is linked to the w32HActivate event for the Main control. One of the first things that WinMain() does, after making the main window visible, is to trigger an activate event for the main window and each of its child controls. Thus the line gets drawn.
Note however, this might not be what you actually want as the line will get wiped out again whenever that portion of the main window is covered by anything else. You might need to draw the line during the w32HPaint event, as that event happens everytime any portion of the window get uncovered (say during resizing or moving a foreground window off the main window).