Sunday, September 22, 2019 | Toby Opferman
 

GUI Tutorial

Toby Opferman
http://www.opferman.net
programming@opferman.net



		From TUI to GUI: Event Driven Programming Tutor
	
	This is a no code tutor, but a concept tutorial.  This should explain to someone
who has been in a DOS, Linux type enviroment (Teletype/TUI) to a GUI like Windows!  The
concepts of event driven programming as opposed to the concepts of a straight top down
executing program.


	First, we will go over how a typical DOS program works.  Typically, the program
executes at a certain starting point.  The program will then execute until it's done.  It 
may do a straight through process or it may have a polling loop and wait for the user to
input things and when exit is detected it exits.  It may exit in more than one spot.
It's general form though, is, it starts here and it continues until it ends more than
likely, it was programmed with the idea in mind that the program will be uninterupted and
as if it's the only program running.

	Even programming on a mainframe or in linux in a TUI enviroment, the programmer
usually programs his programs in the same fashion. Even though these are multi tasking
systems, they still have programs programmed as if they are the only program executing.
The program runs and that's it.  It takes no consideration for memory, other programs,
processing time, or devices.  It owns all memory, it has all processing time, and it
owns all devices.

	Event driven programming and GUI is a bit differnt.  In text OSes, the user
for the most part has crude tools and styles.  Mostly everything is done by the user
(Unless you use linux, it has an API. DOS, has no real API).  

	Basically, what you do is set up what your window shall look like.  Then you
assign a function to it and tell the Operating System to create it.  The OS will send
the Function messages and your window procedure will process the messages as they come in.
The function is called, you check the message to see what message it is, and you perform
the task you want performed.  This is kind of like POLLING in dos programming, execpt 
you don't have a loop, the OS just calls you when something happens.


A simple Diagram:

+[ User Performs Operation on Window (Ex: Hit Keyboard) ] ----------------------------+
|                                                                                     |
+[ Computer Event (Ex: RePaint Window after being hidden from another app) ] -------- +
|                                                                                     |
|                                                                                     |
|                                   +-------------------------------------------------+
|                  [Windows Sends Message To Your Program]
|                                   |
|                [ Your Program Checks What Message is sent ]
|                                   |
|            [ Your Program either discards it or performs an operation]
|                                   |
|                       +-----------+----------+
|              [ Back To Windows ]      [ Exit Detected, Program destorys itself ]
|                      |                                   |
|            +---------+---------+                 [  Back To Windows ]
|  [ Message For Your Program ]  |          +--------------+
|            |           [ Message For Another Program]
+------------+                        |
                                   .......

	That is the basics of how GUI's and event driven programming work.  With this,
you should have a better understanding of how GUI's work, if you want to get more into GUI
programming I suggest you pick a platform GUI OS to program for and development tools for it.
X-Windows, Windows 3.1/NT/95/98, BeOS, etc.  Some are set up a little differnt than others,
but main applications can run like the above.  The above diagram is based on the Win32
model.
 
About Toby Opferman

Professional software engineer with over 15 years...

Learn more »
Codeproject Articles

Programming related articles...

Articles »
Resume

Resume »
Contact

Email: codeproject(at)opferman(dot)com