Abl-menu On .net-controls

Hi everybody,

as i'm really new to using .Net-controls in OE (11.6) forgive my stupid question, but:

is it possible to define a popup-menu in ABL and connect it to a .Net-TreeView-control ?
 

Osborne

Active Member
Yes, it should be possible to convert the ABL popup-menu to a .NET System.Windows.Forms.ContextMenu and attach this to the TreeView.

I do not have any examples, but the following example may help get you started. It reads a standard ABL menu bar and creates .NET menus from the ABL menus. When you select the .NET menu it will select the relevant ABL menu:
Code:
CREATE WIDGET-POOL.

DEFINE VARIABLE hMenu AS HANDLE NO-UNDO.
DEFINE VARIABLE oForm AS Progress.Windows.Form NO-UNDO.
DEFINE VARIABLE oWindowContainer AS Progress.Windows.WindowContainer NO-UNDO.
DEFINE VARIABLE oToolStripMenuItem1 AS System.Windows.Forms.ToolStripMenuItem NO-UNDO.

DEFINE VAR C-Win AS WIDGET-HANDLE NO-UNDO.

DEFINE SUB-MENU m_File
       MENU-ITEM m_Menu_Item_1  LABEL "Menu Item 1"  
       MENU-ITEM m_Menu_Item_2  LABEL "Menu Item 2"  
       RULE
       MENU-ITEM m_Menu_Item_3  LABEL "Menu Item 3".

DEFINE SUB-MENU m_Edit
       MENU-ITEM m_Menu_Item_4  LABEL "Menu Item 4".

DEFINE MENU MENU-BAR-C-Win MENUBAR
       SUB-MENU  m_File         LABEL "&File"        
       SUB-MENU  m_Edit         LABEL "&Edit".

DEFINE VARIABLE FILL-IN-1 AS CHARACTER FORMAT "X(256)":U
     LABEL "Fill 1"
     VIEW-AS FILL-IN
     SIZE 14 BY 1 NO-UNDO.

DEFINE FRAME DEFAULT-FRAME
     FILL-IN-1 AT ROW 1.71 COL 7 COLON-ALIGNED
    WITH 1 DOWN NO-BOX KEEP-TAB-ORDER OVERLAY
         SIDE-LABELS NO-UNDERLINE THREE-D
         AT COL 1 ROW 1
         SIZE 100 BY 16.

CREATE WINDOW C-Win ASSIGN
       HIDDEN             = YES
       TITLE              = "ABL Window Embedded Into .NET Form"
       HEIGHT             = 16
       WIDTH              = 100
       MAX-HEIGHT         = 16
       MAX-WIDTH          = 100
       VIRTUAL-HEIGHT     = 16
       VIRTUAL-WIDTH      = 100
       RESIZE             = yes
       SCROLL-BARS        = no
       STATUS-AREA        = no
       BGCOLOR            = ?
       FGCOLOR            = ?
       KEEP-FRAME-Z-ORDER = yes
       THREE-D            = yes
       MESSAGE-AREA       = no
       SENSITIVE          = yes.

ASSIGN C-Win:MENUBAR = MENU MENU-BAR-C-Win:HANDLE.

IF SESSION:DISPLAY-TYPE = "GUI":U AND VALID-HANDLE(C-Win)
THEN C-Win:HIDDEN = yes.

ON CHOOSE OF MENU-ITEM m_Menu_Item_1
OR CHOOSE OF MENU-ITEM m_Menu_Item_2
OR CHOOSE OF MENU-ITEM m_Menu_Item_3
OR CHOOSE OF MENU-ITEM m_Menu_Item_4
DO:
   MESSAGE SELF:NAME SKIP SELF:LABEL VIEW-AS ALERT-BOX.
END.

MAIN-BLOCK:
DO ON ERROR   UNDO MAIN-BLOCK, LEAVE MAIN-BLOCK
   ON END-KEY UNDO MAIN-BLOCK, LEAVE MAIN-BLOCK:
   RUN CreateForm.
   RUN enable_UI.
   IF NOT THIS-PROCEDURE:PERSISTENT THEN
      WAIT-FOR System.Windows.Forms.Application:Run(oForm).
END.

PROCEDURE CreateForm:
   DEFINE VARIABLE oMenuStrip AS System.Windows.Forms.MenuStrip NO-UNDO.

   /* Create the .NET form. */
   oForm = NEW Progress.Windows.Form().
   oForm:ClientSize = NEW System.Drawing.Size(C-Win:WIDTH-PIXELS,C-Win:HEIGHT-PIXELS).
   oForm:Text = C-Win:TITLE.
   oForm:FormClosed:Subscribe("FormClosed").

   /* Create form menus from ABL window menus */
   IF VALID-HANDLE(C-Win:MENUBAR) THEN DO:
      oMenuStrip = NEW System.Windows.Forms.MenuStrip().
      hMenu = C-Win:MENUBAR.
      hMenu = hMenu:FIRST-CHILD.
      DO WHILE hMenu <> ?:
         oToolStripMenuItem1 = NEW System.Windows.Forms.ToolStripMenuItem().
         oToolStripMenuItem1:Text = hMenu:LABEL.
         oMenuStrip:Items:Add(oToolStripMenuItem1).
         RUN FormMenus (INPUT hMenu,
                        INPUT oToolStripMenuItem1).
         hMenu = hMenu:NEXT-SIBLING.
      END.
      oForm:Controls:Add(oMenuStrip).
      oForm:MainMenuStrip = oMenuStrip.
      oForm:Height = oForm:Height + oMenuStrip:Height + 1.
   END.

   /* Create the WindowContainer, embedding the ABL window into it. */
   oWindowContainer = NEW Progress.Windows.WindowContainer().
   oWindowContainer:Size = NEW System.Drawing.Size(C-Win:WIDTH-PIXELS, C-Win:HEIGHT-PIXELS).
   oWindowContainer:EmbeddedWindow = C-Win.
   oWindowContainer:Parent = oForm.
   IF VALID-OBJECT(oMenuStrip) THEN
      oWindowContainer:Top = oMenuStrip:Height + 1.

   oWindowContainer:Show().
   oForm:Show().
END PROCEDURE.

PROCEDURE disable_UI:
  IF SESSION:DISPLAY-TYPE = "GUI":U AND VALID-HANDLE(C-Win)
  THEN DELETE WIDGET C-Win.
  IF THIS-PROCEDURE:PERSISTENT THEN DELETE PROCEDURE THIS-PROCEDURE.
END PROCEDURE.

PROCEDURE enable_UI:
  DISPLAY FILL-IN-1
      WITH FRAME DEFAULT-FRAME IN WINDOW C-Win.
  ENABLE FILL-IN-1
      WITH FRAME DEFAULT-FRAME IN WINDOW C-Win.
  {&OPEN-BROWSERS-IN-QUERY-DEFAULT-FRAME}
  VIEW C-Win.
END PROCEDURE.

PROCEDURE FormClosed:
   DEFINE INPUT PARAMETER sender AS System.Object NO-UNDO.
   DEFINE INPUT PARAMETER e AS System.EventArgs NO-UNDO.

   APPLY "CLOSE" TO THIS-PROCEDURE.
END PROCEDURE.

PROCEDURE FormMenus:
   DEFINE INPUT PARAMETER phMenu AS HANDLE NO-UNDO.
   DEFINE INPUT PARAMETER poToolStripMenuItem AS System.Windows.Forms.ToolStripMenuItem NO-UNDO.

   DEFINE VARIABLE oToolStripMenuItem2 AS System.Windows.Forms.ToolStripMenuItem NO-UNDO.

   phMenu = phMenu:FIRST-CHILD.
   DO WHILE phMenu <> ?:
      IF phMenu:TYPE = "MENU-ITEM" AND phMenu:SUBTYPE = "RULE" THEN
         poToolStripMenuItem:DropDownItems:Add(NEW System.Windows.Forms.ToolStripSeparator()).
      ELSE DO:
         oToolStripMenuItem2 = NEW System.Windows.Forms.ToolStripMenuItem().
         oToolStripMenuItem2:Text = phMenu:LABEL.
         poToolStripMenuItem:DropDownItems:Add(oToolStripMenuItem2).
         IF phMenu:TYPE = "MENU-ITEM" THEN DO:
            oToolStripMenuItem2:Tag = STRING(phMenu).
            oToolStripMenuItem2:Click:Subscribe("FormMenuSelection").
         END.
         ELSE IF phMenu:TYPE = "SUB-MENU" THEN
            RUN FormMenus (INPUT phMenu,
                           INPUT oToolStripMenuItem2).
      END.
      phMenu = phMenu:NEXT-SIBLING.
   END.
END PROCEDURE.

PROCEDURE FormMenuSelection:
   DEFINE INPUT PARAMETER sender AS System.Object NO-UNDO.
   DEFINE INPUT PARAMETER e AS System.EventArgs NO-UNDO.

   oToolStripMenuItem1 = CAST(sender,System.Windows.Forms.ToolStripMenuItem).
   hMenu = HANDLE(oToolStripMenuItem1:Tag:ToString()).
   APPLY "CHOOSE" TO hMenu.
END PROCEDURE.
 
Wow, this is great, thanks a lot ! This seems to be a very easy way to convert existing ABL-Windows to .Net-Windows !

But this immediatelly leads me to the follow-up question: If one has ABL-Widgets and .NET-components together, how does this effect r-code-size and loading-times (e.g. over a network) ? Any experiance ?

thanks, Wolf
 

Osborne

Active Member
Although .NET controls are not native ABL controls and have to be accessed from Progress using a bridge, I have not experienced any real slowness in loading times. For r-code sizes there is maybe a slight increase, but not noticed anything massive. As for loading times over a network, again have not experienced any problems.

Any effect in loading times is likely to be between the ABL and the .NET runtime. Chapter 2 - GUI for .NET Environment in the "GUI for .NET Primer" manual (gsgnp.pdf) outlines the workings.
 
Top