跪拜 Guibai
← Back to the summary

Fun's Declarative UI Runs on Windows 95 via a 1996 IE3 Control

Author: 一了 [email protected] Date: 2026-11-20

One-sentence summary: On a 1995 Windows 95 machine, Fun uses an IE3 control to render declarative UIs: fun:data binds data, fun:click and fun:key capture events, and JScript's Fun.call can even change the window title in reverse.

Writing Frontend on Windows 95

The previous article got Fun's core, FFI, and machine code running on Windows 95. That was a bottom-up test, probing from the interpreter down to executable memory. This article goes the other direction, top-down: can a 1995 system run a declarative UI like today's?

The answer lies in a control that came with the system. Windows 95 OSR2 (4.00.1111) ships with IE3, and lib-ui.fun's Form uses a native Win32 window as the shell, embedding an IE WebBrowser control inside. The UI is written in HTML and CSS, events are passed back from the browser to Fun, and Fun calls user32.dll to modify the window. Sounds like Electron, except both the shell and the kernel are thirty years older.

Talk is cheap; let's build something usable. A random password generator, saved as test-password.fun on the desktop:

var p = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789~!@#$%^&*-_+=<>?';
fun get_password()
  result = '';
  for i = 0 * 0.random() to 8 + 8.random() do
    result &= p.substr(p.length().random(), 1);
  end do;
end fun;

use 'lib-ui.fun';
use 'lib-bind.fun';

class PwdForm = Form()
  autoEvent    = true;
  var databind = Bind(this, []);

  var password = get_password();
  fun Get(e)
    password = get_password();
  end fun;

  fun Body()
    return `
<table><tr><td>
 <input fun:data="password,r" onmousemove="this.select();Fun.call('SetCaption', this.value);">
</td><td>
 <button fun:click="Get" fun:key="Ctrl-R, &R, R, Ctrl-5, F5">Next(<u>R</u>)</button>
</td></tr></table>
`;
  end fun;

  fun Style()
    return 'table{width:100%;height:100%}';
  end fun;
end class;

PwdForm('Password', 360, 80).Show();
Run();

Type fun test-password.fun in the command line, and a window pops up. The title bar doesn't say "Password"; it shows the currently generated password. The input box contains the same password, already fully selected. On the right is a button labeled Next(R).

Fun on a Windows 95 desktop: console runs fun test-password.fun, the popped-up window's title bar is the generated password, the input is fully selected, button is Next(R) Figure: test-password.fun running on Win95 4.00.1111. Title, input, and button are all rendered by the IE3 control, data comes from Fun objects.

1. The Shell Is Win32, the Content Is HTML

PwdForm inherits from Form, Body() returns an HTML string, Style() returns CSS. Show() does something straightforward: it calls the underlying layer to create a Win32 window, gets the WebBrowser control's Document, concatenates Head() and Body() into a full page, and writes it via Doc.write().

So the table, input, and button are all parsed by IE3 according to 1996 standards. The MSThemeCompatible meta is also in Head(), and Win95 controls decide whether to use the system gray theme based on it. The gray background, sunken edges, and square corners in the screenshot are the authentic look of that era.

(Rant: IE3's DOM has no addEventListener; it's all document.all, srcElement, and getAttribute. Fun's UI library is written against this old DOM, not a single modern API is used.)

2. fun:click: Click Once, Return to Fun

With autoEvent = true, Form installs a click handler on the document. When the user clicks anywhere, the event bubbles up to the document, DoClick reads the fun:click attribute from srcElement, gets the method name, finds the same-named method in the Fun object, and calls it. Attribute reading uses getAttribute(name, 2), where the second parameter 2 means case-insensitive, an old IE idiom.

The button carries fun:click="Get", so clicking it executes PwdForm.Get, regenerating password. The whole process doesn't bind to each element; it receives one event at the document level and dispatches by attribute. The term event delegation became popular later, but the practice already ran in the 1996 DOM.

3. fun:data: Binding Is Event-Level, Not Keystroke-Level

Bind installs three hooks on the form: in beforeShow, it scans document.all and registers elements with fun:data; in beforeClick, it executes Save; in afterClick, it executes Load.

fun:data="password,r" is parsed by ParseJsonLite. password is a variable name on the Form, defaulting to the element's value attribute; r means read-only. During Load, Bind reads form.password and writes it back to the element's value. During Save, seeing r, it skips the write-back.

Let's be precise: this is not today's two-way binding that syncs on every keystroke. IE3 has no reliable input event to hang onto, so Bind chooses to sync once before and after clicks and hotkeys. Remove r, and it will write the input box's value back to form.password before a click, reversing the direction. Keep r, and there's only a one-way path from Fun to the UI. The password generator in the screenshot uses the latter.

4. fun:key: Translating Win32 Key Codes into Commands

The button also carries fun:key="Ctrl-R, &R, R, Ctrl-5, F5". During Init, Bind splits this string by commas, registers them in a keys table, and points doc.onkeyup to DoHotKey.

DoHotKey receives a keyCode, a Win32 number. It translates: 0x70 to 0x7b are F1 to F12, with Ctrl pressed it forms Ctrl-F5; Alt plus a letter becomes &R; plain letters A to Z become characters; left/right arrow keys become <- and ->. The translated name is looked up in the keys table; if a method is found, it executes, and Save and Load run before and after as usual.

So this button can be clicked by mouse, or triggered by R, Alt+R, Ctrl+R, F5, or Ctrl+5. Six entry points, all landing on the same Get.

5. Fun.call: JScript Calls Back into the Native Window

The input box also has a trickier line:

onmousemove="this.select();Fun.call('SetCaption', this.value);"

When the mouse moves over the input, it first selects the content, then passes the value to SetCaption. This line is JScript, running inside IE3. Form.Show() did two things during initialization: it attached the Fun object to the control as a COM property, and wrote window.Fun = window.external into the page. Thus JScript's Fun.call goes through COM back to Fun's FunCall, which finds the method by name, allowing up to nine extra parameters beyond the method name.

SetCaption lives in BaseForm; underneath it's user32's SetWindowText. The string passes to the Win9x window API via the ANSI code page, not UTF-16.

A complete chain: IE3's JScript triggers, goes through COM into the Fun interpreter, then through FFI into user32.dll, and finally changes the Win32 window title. Four layers, three languages, all on a 1995 system.

6. The Boundaries of This Setup

Saying what it isn't is more useful than saying what it is.

Here's a correction to a common misconception: this code doesn't only live on Win95. Windows 11 still carries the MSHTML WebBrowser control, and the same Form, the same fun:data, all run there. What it depends on isn't a 1995 system; it's IE's WebBrowser control. As long as the control exists, the code exists; what changes is the rendering mode and system theme, not the Fun layer.

These limitations aren't flaws in Fun; they're the age of the host system. Swapped to today, the same approach can connect to WebView2, which is what fun-ui does. The Win95 version's value isn't practicality; it's that it got the minimal skeleton working: native windows, HTML rendering, property binding, event delegation, cross-language callbacks. Today's frameworks make these five things thicker, but none of them grew out of thin air.

7. The Precursor to z-data

The fun:data, fun:click, fun:key pattern wasn't written just for this demo. It's the precursor to z-data: attributes as directives, values as bindings, events directly on the DOM, no virtual DOM, minimal runtime. Later this idea was ported to JavaScript, becoming the roughly 8KB z-data, and even the atomic CSS added later follows the same minimalist line.

There's also a z-data demo in the fun-ui repository now. The page starts a data object with z-data="{msg:'not called yet'}", and the button has @click="Fun('greet','z-data')", calling back to Fun's fd_greet, then writes the return value into $el.$data.msg. The host changed from IE3 to a browser, the bridge from COM to WebSocket, but the interface is still HTML calling Fun, Fun returning data.

This Win95 window is one of its earliest hosts. The host changed, the interface changed, but the underlying things haven't: find an element, read an attribute, sync data, dispatch events. People writing z-data in a browser today probably don't realize this pattern first ran on IE3.

Conclusion

The runtime is still around 300KB, no Chromium, no Node, no npm. The UI relies on the system's built-in IE3, the logic on the Fun interpreter, the window on user32.dll. All three are things already on the machine in 1995.

The previous article ran Fun's language core and machine code on Win95; this one runs the UI. One article digs down, one digs up, and the middle layer hasn't broken. For the details of the lower half, you can go back to Running Fun on Windows 95.

The browser control built into the system thirty years ago can still be woken up by a language from 2026. That fact is more interesting than the password generator.

Comments

Top 1 from juejin.cn, machine-translated. The original thread is authoritative.

组合搭配函数

Running your own language on Win95's native IE is genuinely fun, and the tinkering energy is maxed out. A single fun.js can run it, and the approach is both wild and clean.