September 25, 2022, 11:39:54 PM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


Programming 2 - A Quick Window Example

Started by GWS, April 27, 2010, 02:18:11 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

GWS

April 27, 2010, 02:18:11 PM Last Edit: April 29, 2010, 10:58:29 AM by GWS
Programming 2.

So let's now take a leap of faith, so you see how easy it is to program Windows.

In Programming 1 we set up a Console window.  That will serve quite well to examine many programming ideas.

However, the main aim is to program Graphical User Interfaces (GUI) - Windows in other words.

Now we will set up a fully functional window using only 8 instructions.

__________________________

def win:window
window win, 0,0,300,300,@MINBOX|@MAXBOX|@SIZE, 0, "A Creative Window", winproc
setwindowcolor win,rgb(0,50,80)

waituntil win = 0
end

sub winproc
       if @CLASS = @IDCLOSEWINDOW then closewindow win
return


___________________________

Just close any currently open code in the Creative Editor window, and use 'File - New - Source File' to obtain an empty window.
Then copy and paste the above, and click the green 'Run' arrow.

There you are, a lovely coloured, resizeable window.  Pretty, but not very useful.  You can drag it around by clicking on the top caption - or minimise it, maximise it - or close it.

Pretty amazing compared to some languages, which would require far more instructions.

We'll leave explaining what the instructions do for a little while, but just reading them, it's fairly clear what's happening.

For completeness of our joint CBasic/ EBasic awareness, here's how they look in EBasic, which being a true compiler, has marginally different syntax ..

_________________________

def win:window
openwindow win, 0,0,300,300,@MINBOX|@MAXBOX|@SIZE, 0, "An Emergence Window", &winproc
setwindowcolor win,rgb(0,50,80)

waituntil win = 0
end

sub winproc
  if @CLASS = @IDCLOSEWINDOW then closewindow win
return
endsub
_____________________________

Spot the difference? .. there isn't much .. we are using 'OpenWindow' instead of just 'Window'.
The messages subroutine 'winproc' (which we will discuss later) has an 'EndSub' statement, .. and you may have missed it, but
the 'OpenWindow' statement has an '&' before the name of the messages subroutine 'winproc'.

Why the differences ? .. apparently it's one of the snags of using a compiler.  For me, any additional symbolism is not a good thing.

With EBasic, you will need to save the file to some appropriate folder, and compile it using 'Build - Build Single - Executable Target set to 'Windows.Exe'

So having shown we can easily set up a working Window in both CBasic and EBasic, we'll leave them for the moment and get back to the elements of a program.

End of Programming 2

_______________________

So there we are - just a few instructions and you have a rather nice window, just waiting to be used ..  

The parts of the instructions might look strange at the moment, but they are very logical and you soon become familiar with them.
Tomorrow may be too late ..