[[Category:OOBasicCode]]
*'''Site''': http://www.oooforum.org/forum/viewtopic.phtml?t=59986
*'''Nota''': Ver [[#Corrección del Thread|Corrección del Thread]] 
<small><pre>
Sub Main
On Error GoTo Handler
Dim oNewFrame As Object, oNewToolkit
Dim oNewWindow As Object
Dim oNewMenuBar As Object, oNewPopMenu As Object
  oNewToolkit = GetToolkit
  oNewWindow = CreateWindow( oNewToolkit, MakeRect(50,50,150,150) )
 
  oNewMenuBar = CreateMenuBar()
  oNewMenuBar.removeItem(0,oNewMenuBar.getItemCount())
  oNewMenuBar.insertItem(0,"~Menu",0,0)
  oNewPopMenu = CreatePopMenu()
  oNewPopMenu.insertItem(1,"~Pop", 0,0)
  oMenuListener = CreateUnoListener("MenuListener_", _
    "com.sun.star.awt.XMenuListener")
  oNewPopMenu.addMenuListener(oMenuListener)
  oNewMenuBar.setPopupMenu(0,oNewPopMenu)
  oNewWindow.setMenuBar(oNewMenuBar)
 
  oNewEdit = CreateCtrWithProp( _
    "Edit",oNewToolkit,oNewWindow,MakeRect(0,0,150,oNewWindow.OutputSize.Height), _
    array("MultiLine","VScroll"), array(true,true))
  oNewEdit.setText("string...")
  oFrames = StarDesktop.getFrames()
  oNewFrame = CreateNewFrame( oNewWindow, "New Frame" )
  oNewFrame.setPropertyValue("Title","title")
  AddTopFrame( oNewFrame )
  Exit Sub
Handler:
  msgBox "error"
End Sub


Sub MenuListener_highlight()
End Sub

Sub MenuListener_select( ev )
  Select Case ev.MenuId
  Case 1
    msgBox "Pop"
  End Select
End Sub

Sub MenuListener_activate( ev )
End Sub

Sub MenuListener_deactivate()
End Sub

Sub MenuListener_disposing()
End Sub


Function CreateMenuBar() As Object
  CreateMenuBar = GetProcessServiceManager. _
    createInstanceWithContext( _
    "stardiv.Toolkit.VCLXMenuBar",GetDefaultContext)
End Function


Function CreatePopMenu() As Object
  CreatePopMenu = GetProcessServiceManager. _
    createInstanceWithContext( _
    "stardiv.Toolkit.VCLXPopupMenu",GetDefaultContext)
End Function


Function GetToolkit()
  GetToolkit = GetProcessServiceManager. _
    createInstanceWithContext( _
    "com.sun.star.awt.Toolkit",GetDefaultContext)
End Function


Sub AddTopFrame( oLocFrame As Object )
  StarDesktop.getFrames().append( oLocFrame )
End Sub


Function CreateNewFrame( oLocWindow As Object, sLocFrameName As String ) As Object
Dim oLocNewFrame As Object
  oLocNewFrame = GetProcessServiceManager.createInstance("com.sun.star.frame.Frame")
  With oLocNewFrame
    .initialize(oLocWindow)
    .setCreator(StarDesktop)
    .setName(sLocFrameName)
  End With
  CreateNewFrame = oLocNewFrame
End Function


Function CreateWindow( oLocToolkit As Object, _
  aLocRect As com.sun.star.awt.Rectangle ) As com.sun.star.awt.WindowDescriptor
Dim oLocWinDesc
  oLocWinDesc = createUnoStruct("com.sun.star.awt.WindowDescriptor")
  With oLocWinDesc
    .Type = com.sun.star.awt.WindowClass.TOP
    '.WindowServiceName = "window"
    '.ParentIndex = -1
    .Bounds = aLocRect
  End With
  With com.sun.star.awt.WindowAttribute
    oLocWinDesc.WindowAttributes = _
      .MOVEABLE + .CLOSEABLE + .BORDER + .SHOW + .SIZEABLE
  End With
  CreateWindow = oLocToolkit.createWindow(oLocWinDesc)
End Function


Function CreateCtrWithProp( CtrType, oToolkit, oWindow, aPosSize, aPropNames, aPropValues )
Dim oCtr As Object, oCtrModel As Object
  oCtr = createUnoService("com.sun.star.awt.UnoControl" & CtrType )
  oCtrModel = createUnoService("com.sun.star.awt.UnoControl" & CtrType & "Model" )
  oCtrModel.setPropertyValues( aPropNames, aPropValues )
  With oCtr
    .setModel(oCtrModel)
    .createPeer( oToolkit, oWindow )
    .setPosSize( aPosSize.X, aPosSize.Y, aPosSize.Width, aPosSize.Height, _
        com.sun.star.awt.PosSize.POSSIZE )
  End With
  CreateCtrWithProp() = oCtr 'model can be got from returned value
End Function


Function MakeRect( nX As Long, nY As Long, _
  nWidth As Long, nHeight As Long ) As com.sun.star.awt.Rectangle
Dim oLocRect
  oLocRect = createUnoStruct("com.sun.star.awt.Rectangle")
  With oLocRect
    .X = nX
    .Y = nY
    .Width = nWidth
    .Height = nHeight
  End With
  MakeRect() = oLocRect
End Function
</pre></small>
===== Corrección del Thread =====
<small><pre>
Global oNewFrame
Sub Main
On Error GoTo Handler
Dim oNewToolkit
Dim oNewWindow As Object
Dim oNewMenuBar As Object, oNewPopMenu As Object
  oNewToolkit = GetToolkit
  oNewWindow = CreateWindow( oNewToolkit, MakeRect(50,50,150,150) )
oTWL = createUnoListener("TopWindowListener_", "com.sun.star.awt.XTopWindowListener")
oNewWindow.addTopWindowListener(oTWL)
...
End Sub

...

Sub TopWindowListener_windowClosing(oEventObject)
  oNewFrame.close(True)
End Sub
Sub TopWindowListener_windowClosed(oEventObject)
End Sub
Sub TopWindowListener_windowMinimized(oEventObject)
End Sub
Sub TopWindowListener_windowNormalized(oEventObject)
End Sub
Sub TopWindowListener_windowActivated(oEventObject)
End Sub
Sub TopWindowListener_windowDeactivated(oEventObject)
End Sub
Sub TopWindowListener_disposing(oEventObject)
End Sub 
</pre></small>