' Gambas module file

Private Sub FindMenuChild(hMenu As Menu, sMenu As String) As Menu
  
  For Each hMenu In hMenu.Children
    If hMenu.Name == sMenu Then Return hMenu
    hMenu = FindMenuChild(hMenu, sMenu)
    If hMenu Then Return hMenu
  Next
  
End

Private Sub FindMenuWindow(hWindow As Window, sMenu As String) As Menu
  
  Dim hMenu As Menu
  
  For Each hMenu In hWindow.Menus
    If hMenu.Name == sMenu Then Return hMenu
    hMenu = FindMenuChild(hMenu, sMenu)
    If hMenu Then Return hMenu
  Next
  
End

Public Sub FindMenu(hCtrl As Control, sMenu As String) As Menu
  
  Dim hWindow As Window
  Dim hMenu As Menu
  
  hWindow = hCtrl.Window
  Do
    hMenu = FindMenuWindow(hWindow, sMenu)
    If hMenu Then Break
    Try hWindow = hWindow.Parent.Window
    If Error Then Return
  Loop
  
  Return hMenu
  
End

Public Sub Main()

  ' Dim hImage As Image
  ' Dim hFile As File
  ' 
  ' hImage = Image.Load("default.png")
  ' hImage.Format = "ARGB"
  ' 
  ' File.Save(Application.Path &/ "default.bin", String@(hImage.Data, hImage.W * hImage.H * SizeOf(gb.Integer)))
  
  DBus.Debug = True
  DBus.Unique = True
  FTest.Show

End
