Deprecated: Function get_magic_quotes_gpc() is deprecated in /home/usingeup/public_html/textpattern/lib/constants.php on line 149
General error Warning: Cannot modify header information - headers already sent by (output started at /home/usingeup/public_html/textpattern/lib/constants.php:149) on line 5144
General error Warning: Cannot modify header information - headers already sent by (output started at /home/usingeup/public_html/textpattern/lib/constants.php:149) on line 575


Photo by Serge Kutuzov on Unsplash


Getting started

Now that we have Win32Lib installed, let’s use it to write a complete application from start to finish. We’ll be cloning everyone’s favorite text editor, Notepad! You may be surprised how much work goes into such a simple application.

The code I’m showing here will require that you’ve followed Clean up your code by fixing up Win32Lib.

Fire up Notepad++ and open click File > New. Then click File > Save As… and name it notepad.exw.

You can download the complete code from this article here: notepad1.exw (1kB)

Basic layout

The arrangement of a Win32Lib application typically goes like this:

  • include files
  • define controls
  • assign events
  • run main loop

Include files

These are the basic files we’ll need to include:

  • Win32Lib.ew is, of course, the main library with all of the GUI routines
  • std/filesys.e provides routines to easily parse file name parts
  • std/io.e provides routines to easily load and save text files
  • std/win32/msgbox.e provides a standard Windows interface

include Win32Lib.ew
include std/filesys.e
include std/io.e
include std/win32/msgbox.e

Define controls

We’ll need a few controls to get started:

  • Main is a Window – our main window
  • Editor is an MleText – a Multi-Line Edit text control
  • Status is our StatusBar – this sits at the bottom of the window

The create routine accepts eight parameters:

  • integer ctype – the control type to be created
  • sequence text – the text to be assigned to the control
  • integer parent – the parent control ID
  • object left – the left position of the control
  • object top – the top position of the control
  • object width – the width of the control
  • object height – the height of the control
  • object style – additional or default styles for the control

We’re going to need a couple extra window styles:

  • ES_NOWORDWRAP uses WS_HSCROLL and ES_AUTOHSCROLL to disable word wrapping
  • SBARS_SIZEGRIP adds a grip to the StatusBar, but is not included in Win32Lib by default

Win32Lib adds a few styles to controls by default that looked good on previous versions of Windows but they don’t look so great on Windows 10. We’ll turn those off with the removeStyle routine.

constant SBARS_SIZEGRIP = 256

	Main        = create( Window, "Notepad", 0, Center, Center, 960, 600 ),
	Editor      = create( MleText, "", Main, ,,,, ES_NOWORDWRAP ),
	Status      = create( StatusBar, "", Main, ,,,, SBARS_SIZEGRIP ),

removeStyle( Editor, {WS_BORDER,WS_EX_CLIENTEDGE} )

Assign events

We didn’t give our Editor control any position or size values, so if you ran this application right now, the control would be nowhere to be found. We can fix that by handling the OnResize event and giving the control some boundaries.

Every Win32Lib event handler is a procedure that requires three parameters:

  • integer self – the control ID of the control generating the event; generated by the create routine
  • integer event – the event ID of the event type being generated; constants declared as w32H-event name
  • sequence params – a list of optional parameters unique to each event

Events are assigned using the setHandler routine, which accepts three parameters:

  • object id – one control ID or a sequence of control IDs to be assigned to this handler; same as above
  • object event – one event ID or a sequence of control IDs to be assigned to this handler; same as above
  • object rtn_id – one routine ID or a sequence of routine IDs to handle the event(s); use routine_id

In most cases you’ll assign one control and one event to a handler routine. You could also assign many controls to the same handler for the same event, and then branch the handler with if or switch blocks, which we’ll see later. I typically name my event handler something obvious like ControlName_EventType but that’s entirely up to you.

Resize event

Now, back to our resize problem. We’ll catch the OnResize event and then use setRect to put the control into place.

The setRect routine accepts six parameters:

  • integer id – the ID of the control to be resized
  • object left – the new left position of the control
  • object top – the new top position of the control
  • object width – the new width of the control
  • object height – the new height of the control
  • integer repaint – a flag indicating to repaint the control after it’s resized

The setRect routine also has a few tricks up its sleeve for each of the size parameters:

  • Specify an interger value as an absolute position
  • Specify an atom value between 0.0 and 1.0 as a percentage
  • Specify the constant w32Edge to align the control’s parent edge
  • Specify the constant w32AltEdge to align the control’s parent opposite edge
  • Specify a sequence { constant, value } where:
    • constant is w32Edge or w32AltEdge
    • value is an integer or atom to offset from that edge

As it turns out, setRect is pretty powerful. I recommend experimenting with these options to get the hang of it.

We’re just going to use setRect to dock the Editor control to the outer bounds of the window with w32Edge.

procedure Main_OnResize( integer self, integer event, sequence params )

	-- dock the Editor to the outer bounds and force it to repaint
	setRect( Editor, w32Edge, w32Edge, w32Edge, w32Edge, w32True )

end procedure
setHandler( Main, w32HResize, routine_id("Main_OnResize") )

The main loop

Now that we have some controls defined and an event handler for OnResize, we can run our application with WinMain.

The WinMain routine accepts two parameters:

  • integer id – the control ID of the Window to be the main window
  • integer style – the initial state of the window: Normal, Minimized, or Maximized

Add this line to the end of our file, save it, and press your Run in Euphoria key (mine is F6).

WinMain( Main, Normal )

Hello, Notepad! In the next part, we’ll add some menus and fill out the basic file loading routines.

Categories Beginner, Win32Lib


Photo by Hal Gatewood on Unsplash


Getting started

Starting with version 4.0, Euphoria supports default parameters. We can use this feature to our advantage by adding some defaults to commonly-used Win32Lib routines. A couple small tweaks will make your code cleaner and easier to maintain.

Typically, when you have to create a lot of controls, your code ends up looking like this:

	FileMenu        = create( Menu, "&File", Main, 0, 0, 0, 0, 0 ),
	FileNew         = create( MenuItem, "&New\tCtrl+N", FileMenu, 0, 0, 0, 0, 0 ),
	FileOpen        = create( MenuItem, "&Open\tCtrl+O", FileMenu, 0, 0, 0, 0, 0 ),
	FileSave        = create( MenuItem, "&Save\tCtrl+S", FileMenu, 0, 0, 0, 0, 0 ),
	FileSaveAs      = create( MenuItem, "Save &As...", FileMenu, 0, 0, 0, 0, 0 ),
	FileSep1        = create( MenuItem, "-", FileMenu ),
	FilePageSetup   = create( MenuItem, "Page Set&up...", FileMenu, 0, 0, 0, 0, 0 ),
	FilePrint       = create( MenuItem, "&Print...\tCtrl+P", FileMenu, 0, 0, 0, 0, 0 ),
	FileSep2        = create( MenuItem, "-", FileMenu, 0, 0, 0, 0, 0 ),
	FileExit        = create( MenuItem, "E&xit", FileMenu, 0, 0, 0, 0, 0 ),

Yuck. All those zeros create a lot of visual noise. Ugly code is hard to maintain.

After making these tweaks, your code can look like this:

	FileMenu        = create( Menu, "&File", Main ),
	FileNew         = create( MenuItem, "&New\tCtrl+N", FileMenu ),
	FileOpen        = create( MenuItem, "&Open\tCtrl+O", FileMenu ),
	FileSave        = create( MenuItem, "&Save\tCtrl+S", FileMenu ),
	FileSaveAs      = create( MenuItem, "Save &As...", FileMenu ),
	FileSep1        = create( MenuItem, "-", FileMenu ),
	FilePageSetup   = create( MenuItem, "Page Set&up...", FileMenu ),
	FilePrint       = create( MenuItem, "&Print...\tCtrl+P", FileMenu ),
	FileSep2        = create( MenuItem, "-", FileMenu ),
	FileExit        = create( MenuItem, "E&xit", FileMenu ),

Now that looks a lot cleaner, doesn’t it? You can also skip parameters, like this:

integer Text = create( MleText, "", Main, ,,,, ES_WORDWRAP )

Modify the code

Open up your local copy of Win32Lib.ew in Notepad++. (It’s probably under C:\Euphoria\Win32Lib\Include\win32lib.ew)

Remember, I’m using Jean-Marc DURO’s “win32lib_r2” release: Setup Win32Lib 0.70 on Windows 10

You can press Ctrl+G and to jump to a specific line. Add the following default parameters:

Line 19797

global function createEx( object pControl, sequence pCaption = "", atom pOwner = 0,
            object pLeft = 0, object pTop = 0, object pWidth = 0, object pHeight = 0,
            object styleFlags = 0, object exFlags = 0 )

Line 21111

global function create( integer pControl, sequence caption = "", atom pOwner = 0,
            object x = 0, object y = 0, object cx = 0, object cy = 0,
            object styleFlags = 0 )

That’s it! Now go forth and write cleaner code!

Categories Beginner, Win32Lib


Photo by Sebas Ribas on Unsplash


Getting started

Let’s walk through installing Win32Lib 0.70 on Windows 10.


Win32Lib currently works only with 32-bit Euphoria, even on 64-bit systems.

So if you’re planning to develop with Win32Lib on 64-bit Windows 10, you have a couple options:

This guide assumes you’re simply running 32-bit Euphoria on either system.


Win32Lib 0.70

Head over to The Archive and download win32lib_r2.

This is a more recent version of Win32Lib by Jean-Marc DURO that is simpler and more compatible with Euphoria 4.x.

7-Zip 16.04

You’ll also need something to extract the files. While Windows 10 includes built-in support for zip files, I prefer using 7-Zip for this purpose. Head over to the 7-Zip Download page and download the appropriate release for your system.

Go ahead and install 7-Zip. I don’t think we need to go into detail here about that.


Navigate to your Downloads folder, right-click, and then select 7-Zip > Extract files…

Enter your Euphoria directory in the Extract to field and uncheck the sub-directory box.

Then click OK to extract the files. Your new win32lib directory should like like this:


Navigate to the bin directory in your Euphoria directory. Right-click on eu.cfg and click Edit with Notepad++.

Add the following line into the [all] section and save the file.

-i C:\Euphoria\win32lib\Include


Open any of the demos under C:\Euphoria\win32lib\Demo (like window.exw) and press F5 to run it.

Categories Beginner, Win32Lib


Photo by Mr Cup / Fabien Barral on Unsplash


Getting started

Sometimes you need to toggle between multiple versions of Euphoria on one system.

It’s a bit tricky, and I don’t recommend it, but I’ll try to make this as easy as possible on Windows 10.


A word of warning, this is our first Intermediate article. I expect that you’re already familiar with installing Euphoria. You should also be relatively familiar with the command line, how environment variables work, how to write a batch file, and your own system in general. You’ll probably need to adapt these steps to your own needs as necessary.


This method should work for switching between any number of Euphoria versions. I use this it to switch between 32-bit and 64-bit Euphoria 4.1 on my 64-bit Windows 10 system. I recommend using color-coded terminals to avoid any confusion in which environment is live. Best of all, you can run each of these environments simultaneously!

Version Architecture Path Shortcut Code Preview
Euphoria 2.5 N/A C:\Euphoria25 N/A 06  Aqua 
Euphoria 3.1 N/A C:\Euphoria31 F8 2F  Green 
Euphoria 4.0 N/A C:\Euphoria40 F7 5F  Purple 
Euphoria 4.1 32-bit C:\Euphoria41-32bit F6 4F  Red 
Euphoria 4.1 64-bit C:\Euphoria41-64bit F5 1F  Blue 


So how do we get multiple versions of Euphoria installed side-by-side? We copy them!

Here are the steps to get any number of versions installed. Repeat as necessary for each version you need.

  1. Install a version of Euphoria to C:\Euphoria.
  2. Copy this folder to its new home. You can do this in Windows Explorer, but I prefer to use Robocopy, e.g.
    robocopy /E C:\Euphoria C:\Euphoria41-32bit
  3. Update the %EUDIR%\bin\eu.cfg files for all Euphoria 4.x versions to use the new path for that version.
  4. Uninstall the “original” version from C:\Euphoria.

At this point, you don’t need to maintain any version as being “installed” on your system under Programs and Features.


We’ll need to prepare your environment to accept dynamic changes to put any version of Euphoria into the path.

Head back to our previous article (Installing Euphoria 4.1 on Windows 10) if you need, and do the following:

  1. Add a new environment variable EUDIR with your default environment, e.g. C:\Euphoria41-64bit.
  2. Edit your PATH environment variable and change C:\Euphoria\bin to %EUDIR%\bin.

Done correctly, this won’t change anything about your original Euphoria installation.

Command scripts

This, as they say, is where the magic happens. We’ll create a series of command scripts (or “batch files”) to switch our environment on-the-fly. Repeat the following steps for each version of Euphoria you want to use. I create these files on my Desktop for easy access.

  1. Create a new text file named Euphoria {VERSION}.cmd, e.g. Euphoria 4.1 (32-bit).cmd.
  2. Open the new script in Notepad++ and enter the following:
    @echo off
    COLOR 5F
    SET EUDIR=C:\Euphoria40
    TITLE Euphoria 4.0.5 (32-bit)
    %COMSPEC% /k "eui.exe -v"
  3. Replace the COLOR, EUDIR, and TITLE values to match your environment. See the table above.

If you’re using Euphoria 2.5 or 3.1, you’ll need to change this line:

%COMSPEC% /k "eui.exe -v"
to look like this instead:
%COMSPEC% /k "ECHO. | exwc.exe"

Unfortunately you cannot avoid seeing the “file name to execute?” prompt, but at least the echo trick ignores it.


So how does all this work?


First we echo a blank line. I just the aesthetics of padding the version output with blank lines.


Next we set the terminal color using the color codes listed above. See color /? for details.


Command scripts will drop you into the directory where the script lives. But by default, Command Prompt drops you into your home directory. So we’re just restoring that behavior with this command.

SET EUDIR=C:\Euphoria40

Here we’re overriding the environment variables that point to the relevant Euphoria environment.

TITLE Euphoria 4.0.5 (32-bit)

This sets the terminal title which, in conjunction with the colored back ground, helps prevent confusion when using multiple environments.

%COMSPEC% /k "eui.exe -v"

Finally, we drop the user into a new Command Prompt instance. The /k argument executes the provided command and then stays in the command prompt instead of exiting. See cmd /? for details.

Notepad++ macros

We can take this a step further and extend the macro from our previous article (Setup Notepad++ to edit Euphoria code).

Reassign shortcuts

First, we’ll need to reassign a couple existing menu item shortcuts so that we can use F5-F6-F7-F8 for these macros.

  1. Click Run > Modify Shortcut/Delete Command…
  2. Select the Main menu tab.
  3. Scroll down to 97 Search Results Window ( F7 ) and click Modify.
  4. Add Shift to the shortcut.
  5. Repeat steps 3-4 for 167 Focus on Another View ( F8 ) (add Shift as well).

Insert macros

We can drop in all four macros at once by modifying the shortcuts.xml for Notepad++.

  1. Click File > Open…
  2. Browse to %APPDATA%\Notepad++ and select shortcuts.xml.
  3. Remove the previous “Run in Euphoria” macro around line 22.
  4. Insert the following macros. You may need to modify these depending on your setup.
    <Command name="Run in Euphoria 4.1 (64-bit)" Ctrl="no" Alt="no" Shift="no" Key="116">%EUDIR%\bin\euiw.exe %EUDIR%\bin\startw.exw -d &quot;$(CURRENT_DIRECTORY)&quot; C:\Euphoria41-64bit\bin\euiw.exe &quot;$(FILE_NAME)&quot;</Command>
    <Command name="Run in Euphoria 4.1 (32-bit)" Ctrl="no" Alt="no" Shift="no" Key="117">%EUDIR%\bin\euiw.exe %EUDIR%\bin\startw.exw -d &quot;$(CURRENT_DIRECTORY)&quot; C:\Euphoria41-32bit\bin\euiw.exe &quot;$(FILE_NAME)&quot;</Command>
    <Command name="Run in Euphoria 4.0 (32-bit)" Ctrl="no" Alt="no" Shift="no" Key="118">%EUDIR%\bin\euiw.exe %EUDIR%\bin\startw.exw -d &quot;$(CURRENT_DIRECTORY)&quot; C:\Euphoria40\bin\euiw.exe &quot;$(FILE_NAME)&quot;</Command>
    <Command name="Run in Euphoria 3.1 (32-bit)" Ctrl="no" Alt="no" Shift="no" Key="119">%EUDIR%\bin\euiw.exe %EUDIR%\bin\startw.exw -d &quot;$(CURRENT_DIRECTORY)&quot; C:\Euphoria31\bin\exw.exe &quot;$(FILE_NAME)&quot;</Command>

Categories Intermediate, Windows


Photo by Taskin Ashiq on Unsplash


Getting started

Let’s walk through setting up Nano to highlight Euphoria files.


If you’re running Ubuntu, then you should already have Nano. Open a Terminal and type which nano to verify its installation. If it’s missing, type sudo apt install nano to install it. (Isn’t Linux easy?)


Download nanorc

I have created an updated nanorc file for Euphoria 4.1. This file will add syntax highlighting to Nano.

You can get it on the Downloads page. Here is a direct link: euphoria.nanorc (2kB)

Install nanorc

Open Terminal and enter the following commands:

  • sudo mv Downloads/euphoria.nanorc /usr/share/nano/
  • sudo chown root:root /usr/share/nano/euphoria.nanorc

The default Nano configuration for Ubuntu will use all *.nanorc files in the /usr/share/nano/ directory by default.

Test nanorc

Now open a Euphoria file, such /usr/local/euphoria-4.1.0-Linux-x64/demo/animal.ex, to see the syntax highlighting works correctly.

Thats it! I told you Linux was easy.

Categories Beginner, Linux