OpenW Command

Purpose

Creates a (MDI) window form.

Syntax

OpenW [options] [#]n [, x, y, w, h][, attr]

OpenW [options] Owner form, [#]n [, x, y, w, h][, attr]

OpenW [options] MdiParent [#]n [, x, y, w, h][, attr]

OpenW [options] MdiChild Owner | Parent form, [#]n [, x, y, w, h][, attr]

n, x, y, w, h, attr:iexp
options:
[Tool] [Center] [Full] [Hidden] [Client3D] [Help] [Top] [Palette] [NoCaption] [NoTitle] [Fixed] [Default]

Description

The GFA-BASIC 16 compatible command OpenW [#]n, x, y, w, h, attr opens the window with number n, where n can assume any value. When n specifies the values 0 to 31, GFA-BASIC 32 automatically provides a global Form variable named Win_n. When the number is greater than 31 the window gets the object name Form(n).

For Properties, Methods and Events for Window objects, see Form Object.

The upper left corner of the window is anchored at the coordinates specified with x and y. The window has the width w and the height h. By using attr the following window attributes can be specified:

Bit Value Meaning
0,1 1,2 vertical scrollbar
2,3 4,8 horizontal scrollbar
4 16 title line
5 32 close box
6 64 minimize box
7 128 maximize box
9 512 size box


attr =-1 draws all attributes.
attr = 0 draws a window with a single border and no attributes.

Without the attr parameter, the window gets all attributes except the scrollbars. (In GFA-BASIC 16 you would have used attr = ~15.)

OpenW creates a Form object named Win_n, where n is a number between 0 and 31. The GFA-BASIC 16 window management commands like MoveW, SizeW, etc. are still present, and can be used to manage the windows using pixel coordinates. When managing the Form using properties and methods the measurements are in twips.

Messages should be handled using event subs, like Win_1_Activate. For an overview of all properties, methods, and event subs see Form object.

When OpenW specifies a number > 31, then the properties and methods are accessed using Form(n).property and the event subs are like Sub Form_Activate(Index%). The window number is passed as the first argument in the sub parameter list. See also Name for more information on using window numbers beyond 31.

OpenW [option] Owner name creates a window that is to be owned by the form object name. The Owner option permits you to specify the parent form of the form being shown. When you use this option, you achieve two interesting effects: the owned form is always shown in front of its owner (parent), even if the parent has the focus, and when the parent form is closed or minimized, all forms it owns are also automatically closed or minimized. You can take advantage of this feature to create floating forms that host a toolbar, a palette of tools, a group of icons, and so on. This technique is most effective if combine it with the window state options Fixed and/or Tool/Palette.

The options argument specifies additional window state settings.

Center - centers the form.

Full - creates a maximized window, excludes Hidden (full windows are always visible).

Hidden - opens invisible

Client3D - sets WS_EX_CLIENTEDGE

Tool - creates a WS_EX_TOOLWINDOW

Help - includes a Help button in the window caption, excludes minimize an maximize buttons

Top - creates a topmost window

Palette - creates a WS_EX_PALETTEWINDOW

Fixed - a non-sizable window

NoCaption - no title bar

NoTitle - no title bar, alias

Default - uses Windows default values

You can create MDI parent and child windows with OpenW as well. To create a parent window use:

OpenW [options] MdiParent n (identical to ParentW n).

To create a MDI child window of MDI parent form parentform, use (Owner and Parent are identical):

OpenW [options] MdiChild Parent parentform, n

OpenW [options] MdiChild Owner parentform, n

These OpenW commands are identical to ChildW n, np)

OpenW MdiParent 1 , , , 300, 300

OpenW MdiChild Parent Me, 2, 0, 0

Example

OpenW # 1, 10, 10, 200, 100, -1//opens the window #1

Win_1.Moveable = 0

OpenW Tool Client3D Center Owner Win_1, 40

Form(40).Sizeable = 0

Do

Sleep

Until Me Is Nothing

 

Sub Win_1_Activate

EndSub

 

Sub Form_Activate(Index%)

If Index% = 40

// code ..

EndIf

EndSub

Remarks

The rules for windows numbered larger than 31 apply for ChildW as well. The number of simultaneous open windows is limited by the OS.

In contrast with LoadForm, the OpenW, ChildW, ParentW, and Form commands don't generate a Load event.

Known Issues

  1. [Solved in OCX version 2.38] Creating windows with IDs greater than 31 can cause Memory Access errors; these disappear if the IDE is closed and then restarted but usually resurface very quickly afterwards. The reason for this is unknown at present and there is no known workaround.
    [Reported by James Gaite, 25/05/2020]
  2. [Solved in OCX version 2.38] In a similar vein to (1) above, using Ocx Forms in windows created using OpenW can cause Memory Access issues. Once again, closing the IDE and reloading solves this for a short while but the problem usually reappears. The reason for this is unknown but may be linked to (1) above; the workaround is to open the window using the Form Command instead.
    [Reported by James Gaite, 25/05/2020]

See Also

Form Object, Form, LoadForm, ParentW, ChildW, Dialog, SaveFormPos, LoadFormPos, ModifyStyle, ModifyExStyle, WinDpi, ScaleToDpi, ScaleXYWHToDpi, WM_DPICHANGED.

{Created by Sjouke Hamstra; Last updated: 15/02/2023 by James Gaite}