1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Abl-menu On .net-controls

Discussion in 'Development' started by Wolfgang Schölmberger, Mar 16, 2017.

  1. 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 ?
     
  2.  
  3. Osborne

    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 (progress):
    1. CREATE WIDGET-POOL.
    2.  
    3. DEFINE VARIABLE hMenu AS HANDLE NO-UNDO.
    4. DEFINE VARIABLE oForm AS Progress.Windows.Form NO-UNDO.
    5. DEFINE VARIABLE oWindowContainer AS Progress.Windows.WindowContainer NO-UNDO.
    6. DEFINE VARIABLE oToolStripMenuItem1 AS System.Windows.Forms.ToolStripMenuItem NO-UNDO.
    7.  
    8. DEFINE VAR C-Win AS WIDGET-HANDLE NO-UNDO.
    9.  
    10. DEFINE SUB-MENU m_File
    11.        MENU-ITEM m_Menu_Item_1  LABEL "Menu Item 1"  
    12.        MENU-ITEM m_Menu_Item_2  LABEL "Menu Item 2"  
    13.        RULE
    14.        MENU-ITEM m_Menu_Item_3  LABEL "Menu Item 3".
    15.  
    16. DEFINE SUB-MENU m_Edit
    17.        MENU-ITEM m_Menu_Item_4  LABEL "Menu Item 4".
    18.  
    19. DEFINE MENU MENU-BAR-C-Win MENUBAR
    20.        SUB-MENU  m_File         LABEL "&File"        
    21.        SUB-MENU  m_Edit         LABEL "&Edit".
    22.  
    23. DEFINE VARIABLE FILL-IN-1 AS CHARACTER FORMAT "X(256)":U
    24.      LABEL "Fill 1"
    25.      VIEW-AS FILL-IN
    26.      SIZE 14 BY 1 NO-UNDO.
    27.  
    28. DEFINE FRAME DEFAULT-FRAME
    29.      FILL-IN-1 AT ROW 1.71 COL 7 COLON-ALIGNED
    30.     WITH 1 DOWN NO-BOX KEEP-TAB-ORDER OVERLAY
    31.          SIDE-LABELS NO-UNDERLINE THREE-D
    32.          AT COL 1 ROW 1
    33.          SIZE 100 BY 16.
    34.  
    35. CREATE WINDOW C-Win ASSIGN
    36.        HIDDEN             = YES
    37.        TITLE              = "ABL Window Embedded Into .NET Form"
    38.        HEIGHT             = 16
    39.        WIDTH              = 100
    40.        MAX-HEIGHT         = 16
    41.        MAX-WIDTH          = 100
    42.        VIRTUAL-HEIGHT     = 16
    43.        VIRTUAL-WIDTH      = 100
    44.        RESIZE             = yes
    45.        SCROLL-BARS        = no
    46.        STATUS-AREA        = no
    47.        BGCOLOR            = ?
    48.        FGCOLOR            = ?
    49.        KEEP-FRAME-Z-ORDER = yes
    50.        THREE-D            = yes
    51.        MESSAGE-AREA       = no
    52.        SENSITIVE          = yes.
    53.  
    54. ASSIGN C-Win:MENUBAR = MENU MENU-BAR-C-Win:HANDLE.
    55.  
    56. IF SESSION:DISPLAY-TYPE = "GUI":U AND VALID-HANDLE(C-Win)
    57. THEN C-Win:HIDDEN = yes.
    58.  
    59. ON CHOOSE OF MENU-ITEM m_Menu_Item_1
    60. OR CHOOSE OF MENU-ITEM m_Menu_Item_2
    61. OR CHOOSE OF MENU-ITEM m_Menu_Item_3
    62. OR CHOOSE OF MENU-ITEM m_Menu_Item_4
    63. DO:
    64.    MESSAGE SELF:NAME SKIP SELF:LABEL VIEW-AS ALERT-BOX.
    65. END.
    66.  
    67. MAIN-BLOCK:
    68. DO ON ERROR   UNDO MAIN-BLOCK, LEAVE MAIN-BLOCK
    69.    ON END-KEY UNDO MAIN-BLOCK, LEAVE MAIN-BLOCK:
    70.    RUN CreateForm.
    71.    RUN enable_UI.
    72.    IF NOT THIS-PROCEDURE:PERSISTENT THEN
    73.       WAIT-FOR System.Windows.Forms.Application:Run(oForm).
    74. END.
    75.  
    76. PROCEDURE CreateForm:
    77.    DEFINE VARIABLE oMenuStrip AS System.Windows.Forms.MenuStrip NO-UNDO.
    78.  
    79.    /* Create the .NET form. */
    80.    oForm = NEW Progress.Windows.Form().
    81.    oForm:ClientSize = NEW System.Drawing.Size(C-Win:WIDTH-PIXELS,C-Win:HEIGHT-PIXELS).
    82.    oForm:Text = C-Win:TITLE.
    83.    oForm:FormClosed:Subscribe("FormClosed").
    84.  
    85.    /* Create form menus from ABL window menus */
    86.    IF VALID-HANDLE(C-Win:MENUBAR) THEN DO:
    87.       oMenuStrip = NEW System.Windows.Forms.MenuStrip().
    88.       hMenu = C-Win:MENUBAR.
    89.       hMenu = hMenu:FIRST-CHILD.
    90.       DO WHILE hMenu <> ?:
    91.          oToolStripMenuItem1 = NEW System.Windows.Forms.ToolStripMenuItem().
    92.          oToolStripMenuItem1:Text = hMenu:LABEL.
    93.          oMenuStrip:Items:Add(oToolStripMenuItem1).
    94.          RUN FormMenus (INPUT hMenu,
    95.                         INPUT oToolStripMenuItem1).
    96.          hMenu = hMenu:NEXT-SIBLING.
    97.       END.
    98.       oForm:Controls:Add(oMenuStrip).
    99.       oForm:MainMenuStrip = oMenuStrip.
    100.       oForm:Height = oForm:Height + oMenuStrip:Height + 1.
    101.    END.
    102.  
    103.    /* Create the WindowContainer, embedding the ABL window into it. */
    104.    oWindowContainer = NEW Progress.Windows.WindowContainer().
    105.    oWindowContainer:Size = NEW System.Drawing.Size(C-Win:WIDTH-PIXELS, C-Win:HEIGHT-PIXELS).
    106.    oWindowContainer:EmbeddedWindow = C-Win.
    107.    oWindowContainer:Parent = oForm.
    108.    IF VALID-OBJECT(oMenuStrip) THEN
    109.       oWindowContainer:Top = oMenuStrip:Height + 1.
    110.  
    111.    oWindowContainer:Show().
    112.    oForm:Show().
    113. END PROCEDURE.
    114.  
    115. PROCEDURE disable_UI:
    116.   IF SESSION:DISPLAY-TYPE = "GUI":U AND VALID-HANDLE(C-Win)
    117.   THEN DELETE WIDGET C-Win.
    118.   IF THIS-PROCEDURE:PERSISTENT THEN DELETE PROCEDURE THIS-PROCEDURE.
    119. END PROCEDURE.
    120.  
    121. PROCEDURE enable_UI:
    122.   DISPLAY FILL-IN-1
    123.       WITH FRAME DEFAULT-FRAME IN WINDOW C-Win.
    124.   ENABLE FILL-IN-1
    125.       WITH FRAME DEFAULT-FRAME IN WINDOW C-Win.
    126.   {&OPEN-BROWSERS-IN-QUERY-DEFAULT-FRAME}
    127.   VIEW C-Win.
    128. END PROCEDURE.
    129.  
    130. PROCEDURE FormClosed:
    131.    DEFINE INPUT PARAMETER sender AS System.Object NO-UNDO.
    132.    DEFINE INPUT PARAMETER e AS System.EventArgs NO-UNDO.
    133.  
    134.    APPLY "CLOSE" TO THIS-PROCEDURE.
    135. END PROCEDURE.
    136.  
    137. PROCEDURE FormMenus:
    138.    DEFINE INPUT PARAMETER phMenu AS HANDLE NO-UNDO.
    139.    DEFINE INPUT PARAMETER poToolStripMenuItem AS System.Windows.Forms.ToolStripMenuItem NO-UNDO.
    140.  
    141.    DEFINE VARIABLE oToolStripMenuItem2 AS System.Windows.Forms.ToolStripMenuItem NO-UNDO.
    142.  
    143.    phMenu = phMenu:FIRST-CHILD.
    144.    DO WHILE phMenu <> ?:
    145.       IF phMenu:TYPE = "MENU-ITEM" AND phMenu:SUBTYPE = "RULE" THEN
    146.          poToolStripMenuItem:DropDownItems:Add(NEW System.Windows.Forms.ToolStripSeparator()).
    147.       ELSE DO:
    148.          oToolStripMenuItem2 = NEW System.Windows.Forms.ToolStripMenuItem().
    149.          oToolStripMenuItem2:Text = phMenu:LABEL.
    150.          poToolStripMenuItem:DropDownItems:Add(oToolStripMenuItem2).
    151.          IF phMenu:TYPE = "MENU-ITEM" THEN DO:
    152.             oToolStripMenuItem2:Tag = STRING(phMenu).
    153.             oToolStripMenuItem2:Click:Subscribe("FormMenuSelection").
    154.          END.
    155.          ELSE IF phMenu:TYPE = "SUB-MENU" THEN
    156.             RUN FormMenus (INPUT phMenu,
    157.                            INPUT oToolStripMenuItem2).
    158.       END.
    159.       phMenu = phMenu:NEXT-SIBLING.
    160.    END.
    161. END PROCEDURE.
    162.  
    163. PROCEDURE FormMenuSelection:
    164.    DEFINE INPUT PARAMETER sender AS System.Object NO-UNDO.
    165.    DEFINE INPUT PARAMETER e AS System.EventArgs NO-UNDO.
    166.  
    167.    oToolStripMenuItem1 = CAST(sender,System.Windows.Forms.ToolStripMenuItem).
    168.    hMenu = HANDLE(oToolStripMenuItem1:Tag:ToString()).
    169.    APPLY "CHOOSE" TO hMenu.
    170. END PROCEDURE.
     
  4. 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
     
  5. Osborne

    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.
     

Share This Page