Creating a window

Preface

In Windows 96, all windows inherit the StandardWindow class, which is found in w96.StandardWindow.

It is not recommended to instantiate this class directly, as you're meant to be using this.createWindow inside a WApplication instance, for resource management reasons.

How windows are created

As mentioned before, windows are created with the function below

createWindow(params: WindowParams, isAppWindow: Boolean): StandardWindow

The params parameter is an object that contains the initialization parameters to use to create the window. These parameters include fields like title, resizable, etc.

The isAppWindow parameter specifies if the window is an app window (main window). An app window will destroy all child dialogs that have been created inside the WApplication instance when closed, and will trigger an application termination event.

Creating a basic window

Here is an application that creates a very basic window with some text as the HTML body. You can run it with basic-window-test through the run box or the terminal.

const { register } = w96.app;
const { Theme } = w96.ui;

class BasicWindowTest extends WApplication {
    constructor() { super(); }
    
    async main(argv) {
        super.main(argv);
        
        // 1. Create the window and assign it to a variable
        const mainwnd = this.createWindow({
            title: "Basic Window",
            body: "this is a very basic window."
        }, true);
        
        // 2. Show it
        mainwnd.show();
    }
}

register({
    command: "basic-window-test",
    type: "gui",
    cls: BasicWindowTest,
    meta: {
        icon: Theme.getIconUrl("exec"),
        friendlyName: "Basic Window Test"
    }
});

The result should be something like this:

Last updated