Try OpenEdge Now
skip to main content
GUI for .NET Programming
Using .NET Forms with ABL Windows : Embedding ABL windows in .NET forms : Embedding a single window in an MDI child form
 

Embedding a single window in an MDI child form

The Progress.Windows.MDIChildForm class is designed to embed one ABL window so that its client area becomes the client area of a .NET MDI child form, as described in the following general steps.
To embed an ABL window in a .NET MDI child form:
1. Ensure that the window object you want to embed has not been visualized or otherwise realized.
2. Create an MDI form object from the Progress.Windows.Form class, which becomes the MDI parent for your application. You can create the MDI parent directly with this class or you can create an ABL-derived MDI form from this class. For an example of an ABL-derived MDI form, see SampleABL-derived .NET MDI form.
3. For each new instance of a Progress.Windows.MDIChildForm you want to create in the MDI parent (typically in response to a menu selection in the MDI parent, such as New > File), instantiate the class as in the following example, where MdiChild is an object reference to an MDIChildForm, MdiContainer is an object reference to the MDI parent form, and hWin is the handle to the current ABL window you want to embed. For example:
MdiChild = NEW Progress.Windows.MDIChildForm( MdiContainer, hWin ).
MdiChild:ClientSize = NEW System.Drawing.Size
                          ( hWin:WIDTH-PIXELS, hWin:HEIGHT-PIXELS ).
Note: If you are creating this MDIChildForm within an ABL-derived MDI form, MdiContainer would be replaced with THIS-OBJECT.
4. After all MDI initialization is complete, block on the form using a .NET WAIT-FOR statement, and in appropriate handlers on .NET events for the MDI, create MDI child forms as you have designed for Step 3. For example:
MdiContainer:Show( ).
MdiChild:Show( ).
hWin:VISIBLE = YES.
. . .
WAIT-FOR Application:Run( MdiContainer ).
Also, after you have first created an MDIChildForm instance, you can change the setting of its EmbeddedWindow property to the handle of a different ABL window. However, if it has already been realized, you must first delete the window to which the property was previously assigned before assigning the handle of another window to it.
The following procedure fragment creates a simple MDI containing one MDI child form containing a button from an embedded ABL window. The bold elements indicate the most critical and recommended code for making this work.

USING System.Windows.Forms.* FROM ASSEMBLY.
USING System.Drawing.* FROM ASSEMBLY.
USING Progress.Windows.* FROM ASSEMBLY.
USING Progress.Util.* FROM ASSEMBLY.

DEFINE VARIABLE hWin AS HANDLE NO-UNDO.
DEFINE VARIABLE MdiContainer AS Progress.Windows.Form NO-UNDO.
DEFINE VARIABLE MdiChild AS Progress.Windows.MDIChildForm NO-UNDO.

/* Create main menu for the MDI container (not shown for brevity). */
DEFINE VARIABLE MainMenu AS System.Windows.Forms.MainMenu NO-UNDO.
. . .

/* Define a frame with a button. */
DEFINE BUTTON b1 LABEL "Button 1" SIZE 18 BY 1.14.
DEFINE FRAME f1 b1 AT ROW 2 COL 22 WITH SIDE-LABELS THREE-D SIZE 60 BY 6.

/* Create the window. It will not be realized at this point. */
CREATE WINDOW hWin ASSIGN WIDTH = 60 HEIGHT = 6.
FRAME f1:PARENT = hWin.

/* A trigger to prove that clicking the button works. */
ON 'CHOOSE':U OF b1
DO:
MESSAGE "Click of Button 1".
RETURN.
END.

/* Create the MDI container form. */
MdiContainer = NEW Progress.Windows.Form( ).
MdiContainer:Text = "MDI Container Form".
MdiContainer:IsMdiContainer = TRUE.
MdiContainer:Menu = MainMenu.
MdiContainer:Show( ).

/* Create the MDI child form, embedding the window into it. */
MdiChild = NEW Progress.Windows.MDIChildForm( MdiContainer, hWin ).
MdiChild:Text = "MDI Child Form".
MdiChild:ClientSize = NEW Size( hWin:WIDTH-PIXELS, hWin:HEIGHT-PIXELS ).
MdiChild:FormClosed:Subscribe( "MdiChild_FormClosed" ).
MdiChild:Show( ).

/* Now make the window visible.
It will be realized inside the MDI child form. */
hWin:VISIBLE = YES.
ENABLE ALL WITH FRAME f1.

WAIT-FOR Application:Run(MdiContainer).

/* Delete the embedded window after MDIChildForm closes. */
PROCEDURE MdiChild_FormClosed:

  DEFINE INPUT PARAMETER sender AS System.Object.
  DEFINE INPUT PARAMETER e      AS System.EventArgs.

  DELETE WIDGET hWin.

END PROCEDURE.
Recommended code in this example includes:
*Sizing the client area of the MDIChildForm object (MdiChild) to the client area of the ABL embedded window (hWin)
*Handling the FormClosed event on the MDI child form in order to delete the embedded window when it closes