4.6. Making a Window

DataHub scripting offers many of the Windows classes wrapped as Gamma classes. Thus you can create windows, buttons, entry forms, tabs, dialogs, and so on. The DataHub Windows Scripting manual contains more information. This is how you create a basic window.

  1. Open the Properties window, select the Scripting option, and click the New button to create a new script.
  2. In the New Script File dialog, name the main class 'MyWindows' and select the Windows option. More details.
  3. Add the file to your list of files, and load it now. Here's how. A new window will open:
  4. Click the close icon in the top right corner. The window will close, and you will see this dialog box:

This is an example of a basic window. Here are the main parts of your MyWindows.g script:

class MyWindows Application
{
    window;
}

The window itself is an instance variable of the MyWindows class.

method MyWindows.constructor ()
{
    local    rect = CreateRect (0, 0, 300, 300), txt;
    .window = new GWindow();
    
    .window.Create (0, rect, "Hello", WS_OVERLAPPEDWINDOW, 0);
    .window.CenterWindow();
    txt = .window.CreateControl (GStatic, 0, 0, 280, 22, "Hello world", SS_CENTER);
    txt.CenterWindow();
    .window.MessageHandler (WM_DESTROY, `destroy(@self));
    .window.ShowWindow (SW_SHOW);
}

method MyWindows.destructor ()
{
    // The WM_DESTROY message could come before or after this destructor depending
    // on whether the application instance is destroyed or the window is closed
    // first.  We protect against the case where the window is closed first.
    if (instance_p(.window) && .window.GetHwnd() != 0)
        .window.PostMessage (WM_CLOSE, 0, 0);
    MessageBox(0, string ("Application: ", class_name(self), " completed."), "Done", 0);
}

More information about Windows scripting and the Windows classes and methods can be found in the DataHub Windows Scripting manual.