Floating Windows Inside Main Window

I am using floating windows.
The problem of floating windows is that if i move the main window to a new position and try to open a new window that opens outside the main window.
So i created a routine to force floating window to open inside the main window margins.
I also created routines for minimize and maximize the main window.
Please someone to examine the routines and improve them.

Here is the code for opening floating window in the main window:

Dim n As Integer

n = App.WindowCount

Var Window As New NewProduct
Window.Top = me.top + (35 * n)
Window.Left = me.left + (30 * n)
Return true

here is the code for minimize event in the main window:

Dim n, i As Integer
n = App.WindowCount
For i = n-1 DownTo 0
If App.Window(i) IsA NewProduct Then App.Window(i).Minimize

and here is the code for moving event of the main window:

Dim n, i, j, k As Integer
j = me.Top
k = me.Left

n = App.WindowCount

For i = n-1 DownTo 0
  If App.Window(i) IsA NewProduct and n > 0 Then 
    App.Window(i).Top = j + (30 / n) 
    App.Window(i).Left = k + (30 / n)
  end if

It sounds like you are trying to create an MDI application. A for of Windows app that has been deprecated since about Window 3.1. I think it still works on Windows. Go to the Windows tab and turn on MDI. You will get a container window in side which all your other windows will live. Except for dialog boxes.

It’s not a setting that works on other platforms.

well the above solution (MDI application) works:
a) when i open new windows (they open inside the main window) and b) when i minimize the main window and restore it they do open in their original position.

But the real problem occurs when i try to move the main window to work on the screen my program side by side with excel (so i can see some data from excel and enter them to my program). The floating windows remain outside the main window…
So perhaps i stick to my above code and try to improve it.

Another approach could be:
Opening event of the “NewProduct” window sets a property in App to true.
Moving event of MainWindow checks if the property is true and repositions the “NewProduct” window…

It is not working… i removed from main window minimize and maximize button so nothing bad happens with floating windows and left my routine for moving main window which work partialy and keeps floating windows inside main window. But to speak honestly and having paid my Xojo IDE these issues with windows shouldnt exist and should be solved by xojo developers and everything should work as it should so we the programmers could focus to write the programs and applications and get our work done fast and easier. I am very dissapointed at this early stage of my first application in xojo. I wonder what other serious problems i will meet till i finish my application (if i ever manage to finish it…). After so many years of developing Xojo still has issues…

What you are trying to do is called a childWindow in Apple’s AppKit: the main window has a number of child windows attached that follow the parent window’s position. Xojo does not provide that kind of functionality, but it could be achieved with some careful use of an array and references.

First, forget about MDI. Then, create your own child window management system. Basically, the code you posted a few days ago is correct. In the main window, you would create an array childWindows() as MyChildWindow that stores the references to the floating windows you open. Then you add code in every relevant event of the main window, like Moved, Activated, etc. to update the position and status of the child windows, something like this:

for each w as MyChildWindow in childWindows

It is important to keep the array updated when you close a child window, so I would also add a reference to the parentWindow in MyChildWindow. When a child window is closed, it tells main Window to remove the reference to self and then removes its reference to the parent window:

Sub Closed()
if (parentWindow <> nil) then
parentWindow = nil

Hi my friend.
You described exactly what i need and what i have to do.
I come again into programming from the long time ago MSDos and i was creating applications in GwBasic, Cobol, Fortran and Pascal.
My code above is correct but not perfect as it partially works in the first open floating window and mess things when many floating windows are open. The reason is that i am not familiar with object oriented programming and classes so i couldn’t find a solution by myself without your valuable support.!!
Perhaps Xojo Developers give more attention to databases and other Xojo functionalities that are same to all OS Platforms (windows, Mac, Linux etc) and leave the hot stuff as the windows functionality to programmers ability.
I thought Xojo would give the bricks to build the house it seems now that i will create the bricks by myself and then build the house.

Thanks again for your valuable help.!!!
I will adapt your code to my program and let you know the next days.
Be well.!!!

i entered your instructions and got following message:

BlockquoteWindowMain.Moved, line 3
Type “MyChildWindow” has no member named “updateRelativeTo”


Please help me what is missing from code?

What I typed is actually pseudo-code, it was meant to give you an idea of the structure.

Here is the base to get started:

  1. Create a window subclass “MyWindow” (choose your own class name) with the following properties:
  • childWindows() as MyWindow (private)
  • mParent as MyWindow (private)
  1. In MyWindow, add a method “addChildWindow (wnd as MyWindow)” with the following code:
// Adds a given window as a child window of the window

if (wnd <> nil AND childWindows.IndexOf(wnd) < 0) then
  // do not add a nil reference or a window already listed

  // store a ref to the parent window
  wnd.mParent = self
end if
  1. Add another method “removeChildWindow (wnd As MyWindow)”:
// Detaches a given child window from the window.

if (wnd <> nil) then
  // make sure the window is actually listed
  var index As Integer = childWindows.IndexOf(wnd)
  if (index >= 0) then
    // remove from array
    // remove ref to parent
    wnd.mParent = nil
  end if
end if

  1. To handle the changes in position and size of the parent window and update the children accordingly, you could a third method called “updateChildren()”. This is where you will put the code that handles the position of the child windows. Call updateChildren from the Moved and Resizing events of the parent window.

Hope that helps!

Andrea thank you for the effort anf the help but Unfortunately I am not familiar with classes subclasses and oop.
I hereby attach my Xojo application to whoever has the time and ability to add your code to my application.

The link expires in 1 week.


You are going to have to remedy that first. Whatever code is offered to you is going to require you to have an understanding of these things just to use them in your app.


Hi Friend.
With your precious help and the precious help of Thomas Roemert
i finally managed to use floating windows as planned.
i upload the file as a help to community.
Perhaps the code needs more calibration but i am happy as it is now.

Thank you both for your precious help.!!!

1 Like